MessageHandler.c 834 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106
  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 int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4.
  117. unsigned char :3; //bit 5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // Save configuration
  357. //=========================================
  358. int runShellCmd(const char*cmd)
  359. {
  360. int result = FAIL;
  361. char buf[256];
  362. FILE *fp;
  363. fp = popen(cmd, "r");
  364. if(fp != NULL)
  365. {
  366. while(fgets(buf, sizeof(buf), fp) != NULL)
  367. {
  368. DEBUG_INFO("%s\n", buf);
  369. }
  370. result = PASS;
  371. }
  372. pclose(fp);
  373. return result;
  374. }
  375. int StoreUsrConfigData(struct SysConfigData *UsrData)
  376. {
  377. int result = PASS;
  378. int fd,wrd;
  379. unsigned int i,Chk;
  380. unsigned char *ptr, *BufTmp;
  381. int MtdBlockSize = 0x300000;
  382. Chk=0;
  383. ptr=(unsigned char *)UsrData;
  384. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  385. {
  386. memset(BufTmp,0,MtdBlockSize);
  387. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  388. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  389. Chk+=*(BufTmp+i);
  390. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  391. // Output configuration to file.
  392. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  393. if (fd < 0)
  394. {
  395. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  396. free(BufTmp);
  397. return 0;
  398. }
  399. wrd=write(fd, BufTmp, MtdBlockSize);
  400. close(fd);
  401. if(wrd<MtdBlockSize)
  402. {
  403. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  404. free(BufTmp);
  405. return 0;
  406. }
  407. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  408. DEBUG_INFO("Erase /dev/mtd10.\n");
  409. runShellCmd("flash_erase /dev/mtd10 0 0");
  410. DEBUG_INFO("Write /dev/mtd10.\n");
  411. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  412. DEBUG_INFO("Erase /dev/mtd11.\n");
  413. runShellCmd("flash_erase /dev/mtd11 0 0");
  414. DEBUG_INFO("Write /dev/mtd11.\n");
  415. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  416. system("rm -f /mnt/EvseConfig.bin");
  417. DEBUG_INFO("EvseConfig write to flash OK\n");
  418. }
  419. else
  420. {
  421. DEBUG_ERROR("alloc BlockSize NG\r\n");
  422. result = FAIL;
  423. }
  424. if(BufTmp!=NULL)
  425. free(BufTmp);
  426. return result;
  427. }
  428. //=========================================
  429. // Sqlite3 related function
  430. //=========================================
  431. static int selectSqlCount = 0;
  432. static int callback(void *data, int argc, char **argv, char **azColName){
  433. int i;
  434. //printf("%s: ", (const char*)data);
  435. selectSqlCount = argc;
  436. for(i = 0; i<argc; i++){
  437. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  438. }
  439. //printf("\n");
  440. return 0;
  441. }
  442. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  443. //int i;
  444. //printf("%s:\n", (const char*)data);
  445. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  446. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  447. return 0;
  448. }
  449. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  450. //printf("%s:\n", (const char*)data);
  451. //idTag
  452. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. //parentIdTag
  455. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  456. //expir_date
  457. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  458. //status
  459. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  460. //version
  461. if(columenCount > 5)
  462. idTagQuery.listVersionInt = atoi(columnValue[5]);
  463. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  464. return 0;
  465. }
  466. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  467. {
  468. // localversion = argv[5] ? atoi(argv[5]) : 0;
  469. // printf("localversion=%d\n", localversion);
  470. return 0;
  471. }
  472. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  473. {
  474. for (int i = 0; i < n_columns; i++)
  475. {
  476. DEBUG_INFO("%s\t", col_values[i]);
  477. }
  478. DEBUG_INFO("\n");
  479. return 0;
  480. }
  481. int OCPP_cleanLocalCache()
  482. {
  483. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  484. char *errMsg = 0;
  485. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  486. if (SQLITE_OK != rc)
  487. {
  488. DEBUG_INFO("SQL error: %s\n",errMsg);
  489. return FALSE;
  490. }
  491. return TRUE;
  492. }
  493. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  494. {
  495. int isSuccess = TRUE;
  496. int ret = 0;
  497. //const char* data = "Callback function called";
  498. char sql[300];
  499. char zErrMsg[200];
  500. memset(sql, 0, 300);
  501. memset(zErrMsg, 0, 200);
  502. 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);
  503. //* Execute SQL statement */
  504. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  505. if( ret != SQLITE_OK )
  506. {
  507. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  508. isSuccess = FALSE;
  509. }
  510. return isSuccess;
  511. }
  512. void OCPP_getIdTagFromLocalCache(char idTag[])
  513. {
  514. int rc = 0;
  515. char sql[100];
  516. char zErrMsg[100];
  517. memset(sql, 0, 100);
  518. memset(zErrMsg, 0, 100);
  519. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  520. memset(&idTagQuery, 0, sizeof(idTagQuery));
  521. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  522. /* Execute SQL statement */
  523. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  524. if( rc != SQLITE_OK )
  525. {
  526. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  527. }
  528. }
  529. void OCPP_getListVerion()
  530. {
  531. int rc = 0;
  532. // const char* data = "Callback function called";
  533. char sql[100];
  534. char zErrMsg[100];
  535. memset(sql, 0, 100);
  536. memset(zErrMsg, 0, 100);
  537. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. }
  545. void OCPP_get_TableAuthlocalAllData(void)
  546. {
  547. int rc = 0;
  548. char sql[100];
  549. char zErrMsg[100];
  550. memset(sql, 0, 100);
  551. memset(zErrMsg, 0, 100);
  552. sprintf(sql,"select * from ocpp_auth_local ");
  553. /* Execute SQL statement */
  554. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  555. if( rc != SQLITE_OK )
  556. {
  557. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  558. }
  559. //return ver;
  560. }
  561. int OCPP_cleanLocalList()
  562. {
  563. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  564. char *errMsg = 0;
  565. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  566. if (SQLITE_OK != rc)
  567. {
  568. DEBUG_INFO("%s\n",errMsg);
  569. return FALSE;
  570. }
  571. return TRUE;
  572. }
  573. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  574. {
  575. int isSuccess = FALSE;
  576. int ret = 0;
  577. //const char* data = "Callback function called";
  578. char sql[300];
  579. char zErrMsg[200];
  580. memset(sql, 0, 300);
  581. memset(zErrMsg, 0, 200);
  582. 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);
  583. //* Execute SQL statement */
  584. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  585. if( ret != SQLITE_OK )
  586. {
  587. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  588. return isSuccess;
  589. }
  590. memset(sql, 0, 300);
  591. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  592. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  593. if( ret != SQLITE_OK )
  594. {
  595. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  596. return isSuccess;
  597. }
  598. isSuccess = TRUE;
  599. return isSuccess;
  600. }
  601. void OCPP_getIdTagFromLocalList(char idTag[])
  602. {
  603. int rc = 0;
  604. // const char* data = "Callback function called";
  605. char sql[100];
  606. char zErrMsg[100];
  607. memset(sql, 0, 100);
  608. memset(zErrMsg, 0, 100);
  609. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  610. memset(&idTagQuery, 0, sizeof(idTagQuery));
  611. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  612. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  613. /* Execute SQL statement */
  614. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  615. if( rc != SQLITE_OK )
  616. {
  617. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  618. }
  619. //return ver;
  620. }
  621. void OCPP_deleteIdTagFromLocalList(char idTag[])
  622. {
  623. //int ver = 0;
  624. //int isSuccess = FALSE;
  625. int rc = 0;
  626. char sql[100];
  627. char zErrMsg[100];
  628. memset(sql, 0, 100);
  629. memset(zErrMsg, 0, 100);
  630. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  631. //* Execute SQL statement */
  632. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  633. if( rc != SQLITE_OK )
  634. {
  635. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  636. }
  637. }
  638. int getCurrentYear()
  639. {
  640. int result = 0;
  641. time_t CurrentTime;
  642. struct tm *tm;
  643. CurrentTime = time(NULL);
  644. tm=localtime(&CurrentTime);
  645. result = (tm->tm_year + 1900);
  646. return result;
  647. }
  648. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  649. {
  650. int result = PASS;
  651. char* errMsg = NULL;
  652. char sqlStr[8192];
  653. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  654. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  655. {
  656. result = FAIL;
  657. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  658. }
  659. 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));
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  664. }
  665. return result;
  666. }
  667. //==========================================
  668. // Check time passed since today
  669. //==========================================
  670. long long DiffTimebWithNow(struct timeb ST)
  671. {
  672. //return milli-second
  673. struct timeb ET;
  674. long long StartTime,StopTime;
  675. ftime(&ET);
  676. StartTime=(long long)ST.time;
  677. StopTime=(long long)ET.time;
  678. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  679. }
  680. int getTimePassSinceToday(uint8_t gun_index)
  681. {
  682. int result = -1;
  683. static time_t lastTime[4];
  684. time_t t;
  685. struct tm *tmStartToday;
  686. struct timeb tbStartToday;
  687. t=time(NULL);
  688. if(difftime(t, lastTime[gun_index])>0)
  689. {
  690. tmStartToday=localtime(&t);
  691. tmStartToday->tm_hour = 0;
  692. tmStartToday->tm_min = 0;
  693. tmStartToday->tm_sec = 0;
  694. tbStartToday.time = mktime(tmStartToday);
  695. tbStartToday.millitm = 0;
  696. result = DiffTimebWithNow(tbStartToday)/1000;
  697. lastTime[gun_index] = t;
  698. }
  699. return result;
  700. }
  701. void getNowDatetime(uint8_t *data)
  702. {
  703. time_t t = time(NULL);
  704. struct tm tm = *localtime(&t);
  705. 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);
  706. }
  707. int syncDateTimeRTC(uint8_t *data)
  708. {
  709. struct ParsingResult
  710. {
  711. int result;
  712. int scanedElement;
  713. int year;
  714. int month;
  715. int mday;
  716. int hour;
  717. int min;
  718. int sec;
  719. int tz_hour;
  720. int tz_min;
  721. float minSec;
  722. }result;
  723. struct tm tmOrg;
  724. struct tm *tmTarget;
  725. struct timeb tbTarget;
  726. char buf[128];
  727. memset(&result, 0x00, sizeof(struct ParsingResult));
  728. result.result = PASS;
  729. if(strstr((char*)data, ".") != NULL)
  730. {
  731. // Original data with mini second
  732. if(strstr((char*)data, "Z") != NULL)
  733. {
  734. // Original data with Z
  735. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  736. &result.year,
  737. &result.month,
  738. &result.mday,
  739. &result.hour,
  740. &result.min,
  741. &result.sec,
  742. &result.minSec);
  743. }
  744. else
  745. {
  746. // Original data without Z
  747. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  748. &result.year,
  749. &result.month,
  750. &result.mday,
  751. &result.hour,
  752. &result.min,
  753. &result.sec,
  754. &result.minSec,
  755. &result.tz_hour,
  756. &result.tz_min);
  757. }
  758. }
  759. else
  760. {
  761. // Original data without mini second
  762. if(strstr((char*)data, "Z") != NULL)
  763. {
  764. // Original data with Z
  765. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  766. &result.year,
  767. &result.month,
  768. &result.mday,
  769. &result.hour,
  770. &result.min,
  771. &result.sec);
  772. }
  773. else
  774. {
  775. // Original data without Z
  776. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  777. &result.year,
  778. &result.month,
  779. &result.mday,
  780. &result.hour,
  781. &result.min,
  782. &result.sec,
  783. &result.tz_hour,
  784. &result.tz_min);
  785. }
  786. }
  787. tmOrg.tm_year = result.year - 1900;
  788. tmOrg.tm_mon = result.month - 1;
  789. tmOrg.tm_mday = result.mday;
  790. tmOrg.tm_hour = result.hour;
  791. tmOrg.tm_min = result.min;
  792. tmOrg.tm_sec = result.sec;
  793. tmOrg.tm_gmtoff = 0;
  794. tbTarget.time = mktime(&tmOrg);
  795. tbTarget.timezone = 0;
  796. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  797. tmTarget = gmtime(&tbTarget.time);
  798. 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);
  799. //DEBUG_INFO(" org date time: %s\n", data);
  800. //DEBUG_INFO("parse date time: %s\n", buf);
  801. system(buf);
  802. system("/sbin/hwclock -w --systohc");
  803. if(result.scanedElement < 6)
  804. result.result = FAIL;
  805. return result.result;
  806. }
  807. //==========================================
  808. // GetCompositeSchedule logic related function
  809. //==========================================
  810. int DiffTimebSec(struct timeb ST, struct timeb ET)
  811. {
  812. //return milli-second
  813. unsigned int StartTime,StopTime;
  814. StartTime=(unsigned int)ST.time;
  815. StopTime=(unsigned int)ET.time;
  816. return (StopTime-StartTime);
  817. }
  818. int DiffTimebWithNowSec(struct timeb ST)
  819. {
  820. //return milli-second
  821. struct timeb ET;
  822. unsigned int StartTime,StopTime;
  823. ftime(&ET);
  824. StartTime=(unsigned int)ST.time;
  825. StopTime=(unsigned int)ET.time;
  826. return (StopTime-StartTime);
  827. }
  828. int getStartStop(uint8_t *start, uint8_t *stop)
  829. {
  830. int result = -1;
  831. struct tm tmStart;
  832. struct timeb tbStart;
  833. struct tm tmStop;
  834. struct timeb tbStop;
  835. 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) &&
  836. (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))
  837. {
  838. //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);
  839. //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);
  840. tmStart.tm_year -= 1900;
  841. tmStart.tm_mon -= 1;
  842. tbStart.time = mktime(&tmStart);
  843. tbStart.millitm = 0;
  844. tmStop.tm_year -= 1900;
  845. tmStop.tm_mon -= 1;
  846. tbStop.time = mktime(&tmStop);
  847. tbStop.millitm = 0;
  848. result = DiffTimebSec(tbStart, tbStop);
  849. //DEBUG_INFO("getStartStop(): %d\n", result);
  850. }
  851. else
  852. {
  853. DEBUG_WARN("Start or stop date parsing error.\r\n");
  854. }
  855. return result;
  856. }
  857. int isOvertNow(uint8_t *start)
  858. {
  859. int result = NO;
  860. struct ParsingResult
  861. {
  862. int result;
  863. int scanedElement;
  864. int year;
  865. int month;
  866. int mday;
  867. int hour;
  868. int min;
  869. int sec;
  870. int tz_hour;
  871. int tz_min;
  872. float minSec;
  873. }parsingResult;
  874. struct tm tmStart;
  875. struct timeb tbStart;
  876. if(strstr((char*)start, ".") != NULL)
  877. {
  878. // Original data with mini second
  879. if(strstr((char*)start, "Z") != NULL)
  880. {
  881. // Original data with Z
  882. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  883. &parsingResult.year,
  884. &parsingResult.month,
  885. &parsingResult.mday,
  886. &parsingResult.hour,
  887. &parsingResult.min,
  888. &parsingResult.sec,
  889. &parsingResult.minSec);
  890. }
  891. else
  892. {
  893. // Original data without Z
  894. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  895. &parsingResult.year,
  896. &parsingResult.month,
  897. &parsingResult.mday,
  898. &parsingResult.hour,
  899. &parsingResult.min,
  900. &parsingResult.sec,
  901. &parsingResult.minSec,
  902. &parsingResult.tz_hour,
  903. &parsingResult.tz_min);
  904. }
  905. }
  906. else
  907. {
  908. // Original data without mini second
  909. if(strstr((char*)start, "Z") != NULL)
  910. {
  911. // Original data with Z
  912. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  913. &parsingResult.year,
  914. &parsingResult.month,
  915. &parsingResult.mday,
  916. &parsingResult.hour,
  917. &parsingResult.min,
  918. &parsingResult.sec);
  919. }
  920. else
  921. {
  922. // Original data without Z
  923. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  924. &parsingResult.year,
  925. &parsingResult.month,
  926. &parsingResult.mday,
  927. &parsingResult.hour,
  928. &parsingResult.min,
  929. &parsingResult.sec,
  930. &parsingResult.tz_hour,
  931. &parsingResult.tz_min);
  932. }
  933. }
  934. if(parsingResult.scanedElement >= 6)
  935. {
  936. tmStart.tm_year = parsingResult.year - 1900;
  937. tmStart.tm_mon = parsingResult.month - 1;
  938. tmStart.tm_mday = parsingResult.mday;
  939. tmStart.tm_hour = parsingResult.hour;
  940. tmStart.tm_min = parsingResult.min;
  941. tmStart.tm_sec = parsingResult.sec;
  942. tmStart.tm_gmtoff = 0;
  943. tbStart.time = mktime(&tmStart);
  944. tbStart.timezone = 0;
  945. tbStart.millitm = 0;
  946. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  947. if(DiffTimebWithNowSec(tbStart) <= 0)
  948. result = NO;
  949. else
  950. result = YES;
  951. }
  952. else
  953. {
  954. DEBUG_WARN("Start date parsing error.\n");
  955. }
  956. return result;
  957. }
  958. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  959. {
  960. int result = -1;
  961. struct tm tmStart;
  962. struct timeb tbStart;
  963. struct tm tmStop;
  964. struct timeb tbStop;
  965. 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) &&
  966. (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))
  967. {
  968. tmStart.tm_year -= 1900;
  969. tmStart.tm_mon -= 1;
  970. tbStart.time = mktime(&tmStart);
  971. tbStart.millitm = 0;
  972. tmStop.tm_year -= 1900;
  973. tmStop.tm_mon -= 1;
  974. tbStop.time = mktime(&tmStop);
  975. tbStop.millitm = 0;
  976. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  977. }
  978. return result;
  979. }
  980. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  981. {
  982. FILE *fp;
  983. char profileFileName[128];
  984. char *line = NULL;
  985. size_t len = 0;
  986. time_t CurrentTime;
  987. struct tm *tmComposite;
  988. struct StructChargingProfile maxProfile;
  989. uint8_t limitMax=0;
  990. int compositePeriodIdx = 0;
  991. CurrentTime = time(NULL);
  992. tmComposite=localtime(&CurrentTime);
  993. 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);
  994. if(isUnitA)
  995. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  996. else
  997. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  998. compositeProfile->ChargingSchedule.Duration = durationReq;
  999. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1000. {
  1001. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1002. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1004. }
  1005. compositeProfile->ChargingProfileId = 0;
  1006. compositeProfile->StackLevel = 99 ;
  1007. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1008. maxProfile.ChargingProfileId = -1;
  1009. maxProfile.ChargingSchedule.Duration = -1;
  1010. system("rm -f /tmp/*.json");
  1011. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1012. // Search max profile
  1013. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1014. if((access(profileFileName, F_OK))!=-1)
  1015. {
  1016. fp = fopen(profileFileName, "r");
  1017. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1018. {
  1019. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1020. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1021. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1022. }
  1023. maxProfile.ChargingProfileId = -1;
  1024. maxProfile.StackLevel = -1;
  1025. while(getline(&line, &len, fp) != -1)
  1026. {
  1027. json_object *obj = NULL;
  1028. obj = json_tokener_parse(line);
  1029. if(is_error(obj))
  1030. {
  1031. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1032. }
  1033. else
  1034. {
  1035. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1036. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1037. )
  1038. {
  1039. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1040. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1041. )
  1042. {
  1043. struct tm tmFrom, tmTo;
  1044. struct timeb tbFrom, tbTo;
  1045. 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) &&
  1046. (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))
  1047. {
  1048. tmFrom.tm_year -= 1900;
  1049. tmFrom.tm_mon -= 1;
  1050. tbFrom.time = mktime(&tmFrom);
  1051. tmTo.tm_year -= 1900;
  1052. tmTo.tm_mon -= 1;
  1053. tbTo.time = mktime(&tmTo);
  1054. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1055. {
  1056. if(maxProfile.ChargingProfileId == -1)
  1057. DEBUG_INFO("MaxProfile found.\n");
  1058. else
  1059. DEBUG_INFO("MaxProfile updated.\n");
  1060. // Required item
  1061. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1062. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1063. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1064. if(isUnitA)
  1065. {
  1066. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1067. 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++)
  1068. {
  1069. 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"));
  1070. 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?
  1071. 3:
  1072. 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")));
  1073. 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")));
  1074. }
  1075. }
  1076. else
  1077. {
  1078. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1079. 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++)
  1080. {
  1081. 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"));
  1082. 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?
  1083. 3:
  1084. 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")));
  1085. 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));
  1086. }
  1087. }
  1088. // Optional item
  1089. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1090. {
  1091. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1092. }
  1093. else
  1094. {
  1095. sprintf((char*)maxProfile.ValidFrom, " ");
  1096. }
  1097. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1098. {
  1099. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1100. }
  1101. else
  1102. {
  1103. sprintf((char*)maxProfile.ValidTo, " ");
  1104. }
  1105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1106. {
  1107. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1108. }
  1109. else
  1110. {
  1111. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1112. }
  1113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1114. {
  1115. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1116. }
  1117. else
  1118. {
  1119. maxProfile.TransactionId = -1;
  1120. }
  1121. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1122. {
  1123. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1124. }
  1125. else
  1126. {
  1127. maxProfile.ChargingSchedule.Duration = 86400;
  1128. }
  1129. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1130. {
  1131. 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")));
  1132. }
  1133. else
  1134. {
  1135. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1136. }
  1137. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1138. {
  1139. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1140. }
  1141. else
  1142. {
  1143. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. else
  1149. {
  1150. if(maxProfile.ChargingProfileId == -1)
  1151. DEBUG_INFO("MaxProfile found.\n");
  1152. else
  1153. DEBUG_INFO("MaxProfile updated.\n");
  1154. // Required item
  1155. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1156. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1157. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1158. if(isUnitA)
  1159. {
  1160. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1161. 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++)
  1162. {
  1163. 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"));
  1164. 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?
  1165. 3:
  1166. 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")));
  1167. 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")));
  1168. }
  1169. }
  1170. else
  1171. {
  1172. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1173. 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++)
  1174. {
  1175. 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"));
  1176. 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?
  1177. 3:
  1178. 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")));
  1179. 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));
  1180. }
  1181. }
  1182. // Optional item
  1183. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1184. {
  1185. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1186. }
  1187. else
  1188. {
  1189. sprintf((char*)maxProfile.ValidFrom, " ");
  1190. }
  1191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1192. {
  1193. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1194. }
  1195. else
  1196. {
  1197. sprintf((char*)maxProfile.ValidTo, " ");
  1198. }
  1199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1200. {
  1201. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1202. }
  1203. else
  1204. {
  1205. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1206. }
  1207. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1208. {
  1209. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1210. }
  1211. else
  1212. {
  1213. maxProfile.TransactionId = -1;
  1214. }
  1215. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1216. {
  1217. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1218. }
  1219. else
  1220. {
  1221. maxProfile.ChargingSchedule.Duration = 86400;
  1222. }
  1223. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1224. {
  1225. 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")));
  1226. }
  1227. else
  1228. {
  1229. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1230. }
  1231. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1232. {
  1233. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1234. }
  1235. else
  1236. {
  1237. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. json_object_put(obj);
  1243. }
  1244. fclose(fp);
  1245. /*
  1246. if(maxProfile.ChargingProfileId !=-1)
  1247. {
  1248. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1249. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1250. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1251. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1252. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1253. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1254. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1255. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1256. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1257. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1258. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1259. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1260. {
  1261. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1262. {
  1263. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1264. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1265. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1266. }
  1267. }
  1268. }
  1269. else
  1270. DEBUG_INFO("MaxProfile not found.\n");
  1271. DEBUG_INFO("------------------------------------\n");*/
  1272. }
  1273. if(maxProfile.ChargingProfileId != -1)
  1274. {
  1275. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1276. {
  1277. if(maxProfile.ChargingSchedule.Duration != -1)
  1278. {
  1279. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1280. 0:
  1281. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1282. }
  1283. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1284. {
  1285. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1286. {
  1287. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1288. 0:
  1289. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1290. if(idxPeriod > 0)
  1291. {
  1292. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1293. {
  1294. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1295. }
  1296. }
  1297. }
  1298. }
  1299. }
  1300. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1301. {
  1302. if(maxProfile.ChargingSchedule.Duration != -1)
  1303. {
  1304. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1305. }
  1306. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1307. {
  1308. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1309. {
  1310. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1311. if(idxPeriod > 0)
  1312. {
  1313. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1314. {
  1315. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1316. }
  1317. }
  1318. }
  1319. }
  1320. }
  1321. else
  1322. {
  1323. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1324. {
  1325. if(maxProfile.ChargingSchedule.Duration != -1)
  1326. {
  1327. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1328. 0:
  1329. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1330. }
  1331. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1332. {
  1333. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1334. {
  1335. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1336. 0:
  1337. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1338. if(idxPeriod > 0)
  1339. {
  1340. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1341. {
  1342. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. else
  1349. {
  1350. if(maxProfile.ChargingSchedule.Duration != -1)
  1351. {
  1352. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1353. 0:
  1354. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1355. }
  1356. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1357. {
  1358. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1359. {
  1360. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1361. 0:
  1362. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1363. if(idxPeriod > 0)
  1364. {
  1365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1366. {
  1367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. /*
  1375. DEBUG_INFO("MaxProfile after align.\n");
  1376. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1377. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1378. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1379. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1380. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1381. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1382. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1383. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1384. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1385. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1386. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1387. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1388. {
  1389. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1390. {
  1391. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1392. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1393. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1394. }
  1395. }
  1396. DEBUG_INFO("------------------------------------\n");*/
  1397. }
  1398. // Find each profile period quantity
  1399. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1400. {
  1401. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1402. limitMax = idx+1;
  1403. }
  1404. if(maxProfile.ChargingProfileId != -1)
  1405. {
  1406. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1407. {
  1408. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1409. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1410. (maxProfile.ChargingSchedule.Duration > 0))
  1411. {
  1412. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1413. {
  1414. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1415. compositePeriodIdx++;
  1416. }
  1417. else
  1418. {
  1419. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1420. }
  1421. }
  1422. }
  1423. }
  1424. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1425. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1426. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1427. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1428. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1429. {
  1430. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1431. {
  1432. compositeProfile->ChargingProfileId = 1;
  1433. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1434. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1435. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1436. }
  1437. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1438. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1439. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1440. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1441. }
  1442. if(line)
  1443. free(line);
  1444. }
  1445. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1446. {
  1447. FILE *fp;
  1448. char profileFileName[128];
  1449. char *line = NULL;
  1450. size_t len = 0;
  1451. time_t CurrentTime;
  1452. struct tm *tmComposite;
  1453. struct StructChargingProfile maxProfile;
  1454. struct StructChargingProfile defaultTxProfile;
  1455. struct StructChargingProfile txProfile;
  1456. struct StructChargingSchedulePeriod tmpPeriod;
  1457. uint8_t limitMax=0;
  1458. uint8_t limitDef=0;
  1459. uint8_t limitTx=0;
  1460. int compositePeriodIdx = 0;
  1461. CurrentTime = time(NULL);
  1462. tmComposite=localtime(&CurrentTime);
  1463. 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);
  1464. if(isUnitA)
  1465. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1466. else
  1467. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1468. compositeProfile->ChargingSchedule.Duration = durationReq;
  1469. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1470. {
  1471. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1472. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1473. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1474. }
  1475. compositeProfile->ChargingProfileId = 0;
  1476. compositeProfile->StackLevel = 99 ;
  1477. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1478. maxProfile.ChargingProfileId = -1;
  1479. defaultTxProfile.ChargingProfileId = -1;
  1480. txProfile.ChargingProfileId = -1;
  1481. maxProfile.ChargingSchedule.Duration = -1;
  1482. defaultTxProfile.ChargingSchedule.Duration = -1;
  1483. txProfile.ChargingSchedule.Duration = -1;
  1484. system("rm -f /tmp/*.json");
  1485. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1486. /*
  1487. * Search valid charging profile
  1488. */
  1489. //DEBUG_INFO("====================================\n");
  1490. // Search tx profile
  1491. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1492. if((access(profileFileName, F_OK))!=-1)
  1493. {
  1494. fp = fopen(profileFileName, "r");
  1495. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1496. {
  1497. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1498. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1499. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1500. }
  1501. txProfile.ChargingProfileId = -1;
  1502. txProfile.StackLevel = -1;
  1503. while(getline(&line, &len, fp) != -1)
  1504. {
  1505. json_object *obj = NULL;
  1506. obj = json_tokener_parse(line);
  1507. if(is_error(obj))
  1508. {
  1509. DEBUG_ERROR("Parse txProfile from file error.\n");
  1510. }
  1511. else
  1512. {
  1513. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1514. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1515. )
  1516. {
  1517. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1518. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1519. )
  1520. {
  1521. struct tm tmFrom, tmTo;
  1522. struct timeb tbFrom, tbTo;
  1523. 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) &&
  1524. (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))
  1525. {
  1526. tmFrom.tm_year -= 1900;
  1527. tmFrom.tm_mon -= 1;
  1528. tbFrom.time = mktime(&tmFrom);
  1529. tmTo.tm_year -= 1900;
  1530. tmTo.tm_mon -= 1;
  1531. tbTo.time = mktime(&tmTo);
  1532. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1533. {
  1534. if(txProfile.ChargingProfileId == -1)
  1535. DEBUG_INFO("TxProfile found.\n");
  1536. else
  1537. DEBUG_INFO("TxProfile updated.\n");
  1538. // Required item
  1539. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1540. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1541. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1542. if(isUnitA)
  1543. {
  1544. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1545. 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++)
  1546. {
  1547. 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"));
  1548. 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?
  1549. 3:
  1550. 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")));
  1551. 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")));
  1552. }
  1553. }
  1554. else
  1555. {
  1556. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1557. 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++)
  1558. {
  1559. 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"));
  1560. 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?
  1561. 3:
  1562. 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")));
  1563. 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));
  1564. }
  1565. }
  1566. // Optional item
  1567. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1568. {
  1569. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1570. }
  1571. else
  1572. {
  1573. sprintf((char*)txProfile.ValidFrom, " ");
  1574. }
  1575. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1576. {
  1577. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1578. }
  1579. else
  1580. {
  1581. sprintf((char*)txProfile.ValidTo, " ");
  1582. }
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1584. {
  1585. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)txProfile.RecurrencyKind, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1592. {
  1593. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1594. }
  1595. else
  1596. {
  1597. txProfile.TransactionId = -1;
  1598. }
  1599. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1600. {
  1601. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1602. }
  1603. else
  1604. {
  1605. txProfile.ChargingSchedule.Duration = 86400;
  1606. }
  1607. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1608. {
  1609. 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")));
  1610. }
  1611. else
  1612. {
  1613. 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));
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1616. {
  1617. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1618. }
  1619. else
  1620. {
  1621. txProfile.ChargingSchedule.MinChargingRate = -1;
  1622. }
  1623. }
  1624. }
  1625. }
  1626. else
  1627. {
  1628. if(txProfile.ChargingProfileId == -1)
  1629. DEBUG_INFO("TxProfile found.\n");
  1630. else
  1631. DEBUG_INFO("TxProfile updated.\n");
  1632. // Required item
  1633. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1634. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1635. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1636. if(isUnitA)
  1637. {
  1638. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1639. 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++)
  1640. {
  1641. 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"));
  1642. 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?
  1643. 3:
  1644. 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")));
  1645. 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")));
  1646. }
  1647. }
  1648. else
  1649. {
  1650. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1651. 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++)
  1652. {
  1653. 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"));
  1654. 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?
  1655. 3:
  1656. 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")));
  1657. 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));
  1658. }
  1659. }
  1660. // Optional item
  1661. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1662. {
  1663. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1664. }
  1665. else
  1666. {
  1667. sprintf((char*)txProfile.ValidFrom, " ");
  1668. }
  1669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1670. {
  1671. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1672. }
  1673. else
  1674. {
  1675. sprintf((char*)txProfile.ValidTo, " ");
  1676. }
  1677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1678. {
  1679. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1680. }
  1681. else
  1682. {
  1683. sprintf((char*)txProfile.RecurrencyKind, " ");
  1684. }
  1685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1686. {
  1687. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1688. }
  1689. else
  1690. {
  1691. txProfile.TransactionId = -1;
  1692. }
  1693. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1694. {
  1695. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1696. }
  1697. else
  1698. {
  1699. txProfile.ChargingSchedule.Duration = 86400;
  1700. }
  1701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1702. {
  1703. 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")));
  1704. }
  1705. else
  1706. {
  1707. 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));
  1708. }
  1709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1710. {
  1711. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1712. }
  1713. else
  1714. {
  1715. txProfile.ChargingSchedule.MinChargingRate = -1;
  1716. }
  1717. }
  1718. }
  1719. }
  1720. json_object_put(obj);
  1721. }
  1722. fclose(fp);
  1723. /*
  1724. if(txProfile.ChargingProfileId != -1)
  1725. {
  1726. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1727. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1728. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1729. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1730. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1731. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1732. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1733. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1734. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1735. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1736. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1737. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1738. {
  1739. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1740. {
  1741. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1742. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1743. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1744. }
  1745. }
  1746. }
  1747. else
  1748. DEBUG_INFO("TxProfile not found.\n");*/
  1749. }
  1750. // Search default tx profile
  1751. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1752. if((access(profileFileName, F_OK))==-1)
  1753. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1754. if((access(profileFileName, F_OK))!=-1)
  1755. {
  1756. fp = fopen(profileFileName, "r");
  1757. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1758. {
  1759. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1760. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1761. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1762. }
  1763. defaultTxProfile.ChargingProfileId = -1;
  1764. defaultTxProfile.StackLevel = -1;
  1765. while(getline(&line, &len, fp) != -1)
  1766. {
  1767. json_object *obj = NULL;
  1768. obj = json_tokener_parse(line);
  1769. if(is_error(obj))
  1770. {
  1771. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1772. }
  1773. else
  1774. {
  1775. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1776. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1777. )
  1778. {
  1779. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1780. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1781. )
  1782. {
  1783. struct tm tmFrom, tmTo;
  1784. struct timeb tbFrom, tbTo;
  1785. 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) &&
  1786. (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))
  1787. {
  1788. tmFrom.tm_year -= 1900;
  1789. tmFrom.tm_mon -= 1;
  1790. tbFrom.time = mktime(&tmFrom);
  1791. tmTo.tm_year -= 1900;
  1792. tmTo.tm_mon -= 1;
  1793. tbTo.time = mktime(&tmTo);
  1794. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1795. {
  1796. if(defaultTxProfile.ChargingProfileId == -1)
  1797. DEBUG_INFO("TxDefaultProfile found.\n");
  1798. else
  1799. DEBUG_INFO("TxDefaultProfile updated.\n");
  1800. // Required item
  1801. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1802. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1803. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1804. if(isUnitA)
  1805. {
  1806. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1807. 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++)
  1808. {
  1809. 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"));
  1810. 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?
  1811. 3:
  1812. 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")));
  1813. 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")));
  1814. }
  1815. }
  1816. else
  1817. {
  1818. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1819. 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++)
  1820. {
  1821. 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"));
  1822. 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?
  1823. 3:
  1824. 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")));
  1825. 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));
  1826. }
  1827. }
  1828. // Optional item
  1829. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1830. {
  1831. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1832. }
  1833. else
  1834. {
  1835. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1836. }
  1837. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1838. {
  1839. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1840. }
  1841. else
  1842. {
  1843. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1844. }
  1845. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1846. {
  1847. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1848. }
  1849. else
  1850. {
  1851. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1852. }
  1853. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1854. {
  1855. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1856. }
  1857. else
  1858. {
  1859. defaultTxProfile.TransactionId = -1;
  1860. }
  1861. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1862. {
  1863. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1864. }
  1865. else
  1866. {
  1867. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1868. }
  1869. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1870. {
  1871. 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")));
  1872. }
  1873. else
  1874. {
  1875. 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));
  1876. }
  1877. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1880. }
  1881. else
  1882. {
  1883. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1884. }
  1885. }
  1886. }
  1887. }
  1888. else
  1889. {
  1890. if(defaultTxProfile.ChargingProfileId == -1)
  1891. DEBUG_INFO("TxDefaultProfile found.\n");
  1892. else
  1893. DEBUG_INFO("TxDefaultProfile updated.\n");
  1894. // Required item
  1895. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1896. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1897. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1898. if(isUnitA)
  1899. {
  1900. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1901. 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++)
  1902. {
  1903. 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"));
  1904. 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?
  1905. 3:
  1906. 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")));
  1907. 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")));
  1908. }
  1909. }
  1910. else
  1911. {
  1912. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1913. 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++)
  1914. {
  1915. 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"));
  1916. 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?
  1917. 3:
  1918. 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")));
  1919. 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));
  1920. }
  1921. }
  1922. // Optional item
  1923. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1924. {
  1925. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1926. }
  1927. else
  1928. {
  1929. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1930. }
  1931. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1932. {
  1933. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1934. }
  1935. else
  1936. {
  1937. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1938. }
  1939. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1940. {
  1941. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1942. }
  1943. else
  1944. {
  1945. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1946. }
  1947. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1948. {
  1949. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1950. }
  1951. else
  1952. {
  1953. defaultTxProfile.TransactionId = -1;
  1954. }
  1955. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1956. {
  1957. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1958. }
  1959. else
  1960. {
  1961. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1962. }
  1963. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1964. {
  1965. 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")));
  1966. }
  1967. else
  1968. {
  1969. 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));
  1970. }
  1971. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1972. {
  1973. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1974. }
  1975. else
  1976. {
  1977. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1978. }
  1979. }
  1980. }
  1981. }
  1982. json_object_put(obj);
  1983. }
  1984. fclose(fp);
  1985. /*
  1986. if(defaultTxProfile.ChargingProfileId != -1)
  1987. {
  1988. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1989. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1990. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1991. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1992. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1993. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1994. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1995. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1996. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1997. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1998. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1999. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2000. {
  2001. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2002. {
  2003. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2004. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2005. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2006. }
  2007. }
  2008. }
  2009. else
  2010. DEBUG_INFO("TxDefaultProfile not found.\n");
  2011. DEBUG_INFO("------------------------------------\n");*/
  2012. }
  2013. // Search max profile
  2014. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2015. if((access(profileFileName, F_OK))!=-1)
  2016. {
  2017. fp = fopen(profileFileName, "r");
  2018. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2019. {
  2020. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2021. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2022. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2023. }
  2024. maxProfile.ChargingProfileId = -1;
  2025. maxProfile.StackLevel = -1;
  2026. while(getline(&line, &len, fp) != -1)
  2027. {
  2028. json_object *obj = NULL;
  2029. obj = json_tokener_parse(line);
  2030. if(is_error(obj))
  2031. {
  2032. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2033. }
  2034. else
  2035. {
  2036. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2037. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2038. )
  2039. {
  2040. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2041. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2042. )
  2043. {
  2044. struct tm tmFrom, tmTo;
  2045. struct timeb tbFrom, tbTo;
  2046. 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) &&
  2047. (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))
  2048. {
  2049. tmFrom.tm_year -= 1900;
  2050. tmFrom.tm_mon -= 1;
  2051. tbFrom.time = mktime(&tmFrom);
  2052. tmTo.tm_year -= 1900;
  2053. tmTo.tm_mon -= 1;
  2054. tbTo.time = mktime(&tmTo);
  2055. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2056. {
  2057. if(maxProfile.ChargingProfileId == -1)
  2058. DEBUG_INFO("MaxProfile found.\n");
  2059. else
  2060. DEBUG_INFO("MaxProfile updated.\n");
  2061. // Required item
  2062. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2063. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2064. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2065. if(isUnitA)
  2066. {
  2067. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2068. 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++)
  2069. {
  2070. 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"));
  2071. 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?
  2072. 3:
  2073. 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")));
  2074. 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")));
  2075. }
  2076. }
  2077. else
  2078. {
  2079. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2080. 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++)
  2081. {
  2082. 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"));
  2083. 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?
  2084. 3:
  2085. 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")));
  2086. 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));
  2087. }
  2088. }
  2089. // Optional item
  2090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2091. {
  2092. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2093. }
  2094. else
  2095. {
  2096. sprintf((char*)maxProfile.ValidFrom, " ");
  2097. }
  2098. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2099. {
  2100. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2101. }
  2102. else
  2103. {
  2104. sprintf((char*)maxProfile.ValidTo, " ");
  2105. }
  2106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2107. {
  2108. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2109. }
  2110. else
  2111. {
  2112. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2113. }
  2114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2115. {
  2116. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2117. }
  2118. else
  2119. {
  2120. maxProfile.TransactionId = -1;
  2121. }
  2122. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2123. {
  2124. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2125. }
  2126. else
  2127. {
  2128. maxProfile.ChargingSchedule.Duration = 86400;
  2129. }
  2130. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2131. {
  2132. 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")));
  2133. }
  2134. else
  2135. {
  2136. 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));
  2137. }
  2138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2139. {
  2140. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2141. }
  2142. else
  2143. {
  2144. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2145. }
  2146. }
  2147. }
  2148. }
  2149. else
  2150. {
  2151. if(maxProfile.ChargingProfileId == -1)
  2152. DEBUG_INFO("MaxProfile found.\n");
  2153. else
  2154. DEBUG_INFO("MaxProfile updated.\n");
  2155. // Required item
  2156. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2157. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2158. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2159. if(isUnitA)
  2160. {
  2161. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2162. 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++)
  2163. {
  2164. 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"));
  2165. 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?
  2166. 3:
  2167. 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")));
  2168. 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")));
  2169. }
  2170. }
  2171. else
  2172. {
  2173. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2174. 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++)
  2175. {
  2176. 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"));
  2177. 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?
  2178. 3:
  2179. 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")));
  2180. 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));
  2181. }
  2182. }
  2183. // Optional item
  2184. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2185. {
  2186. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2187. }
  2188. else
  2189. {
  2190. sprintf((char*)maxProfile.ValidFrom, " ");
  2191. }
  2192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2193. {
  2194. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2195. }
  2196. else
  2197. {
  2198. sprintf((char*)maxProfile.ValidTo, " ");
  2199. }
  2200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2201. {
  2202. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2203. }
  2204. else
  2205. {
  2206. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2207. }
  2208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2209. {
  2210. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2211. }
  2212. else
  2213. {
  2214. maxProfile.TransactionId = -1;
  2215. }
  2216. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2217. {
  2218. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2219. }
  2220. else
  2221. {
  2222. maxProfile.ChargingSchedule.Duration = 86400;
  2223. }
  2224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2225. {
  2226. 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")));
  2227. }
  2228. else
  2229. {
  2230. 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));
  2231. }
  2232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2233. {
  2234. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2235. }
  2236. else
  2237. {
  2238. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2239. }
  2240. }
  2241. }
  2242. }
  2243. json_object_put(obj);
  2244. }
  2245. fclose(fp);
  2246. /*
  2247. if(maxProfile.ChargingProfileId !=-1)
  2248. {
  2249. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2250. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2251. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2252. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2253. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2254. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2255. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2256. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2257. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2258. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2259. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2260. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2261. {
  2262. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2263. {
  2264. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2265. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2266. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2267. }
  2268. }
  2269. }
  2270. else
  2271. DEBUG_INFO("MaxProfile not found.\n");
  2272. DEBUG_INFO("------------------------------------\n");*/
  2273. }
  2274. /*
  2275. * Align found profile start schedule & periods
  2276. */
  2277. //DEBUG_INFO("====================================\n");
  2278. /*
  2279. // For local test usage, force modify found profile start schedule info
  2280. 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);
  2281. 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);
  2282. 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);
  2283. */
  2284. if(txProfile.ChargingProfileId != -1)
  2285. {
  2286. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2287. {
  2288. if(txProfile.ChargingSchedule.Duration != -1)
  2289. {
  2290. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2291. 0:
  2292. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2293. }
  2294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2295. {
  2296. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2297. {
  2298. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2299. 0:
  2300. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2301. if(idxPeriod > 0)
  2302. {
  2303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2304. {
  2305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2312. {
  2313. if(txProfile.ChargingSchedule.Duration != -1)
  2314. {
  2315. 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?
  2316. 0:
  2317. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2318. }
  2319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2320. {
  2321. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2322. {
  2323. 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?
  2324. 0:
  2325. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2326. if(idxPeriod > 0)
  2327. {
  2328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2329. {
  2330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. else
  2337. {
  2338. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2339. {
  2340. if(txProfile.ChargingSchedule.Duration != -1)
  2341. {
  2342. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2343. 0:
  2344. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2345. }
  2346. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2347. {
  2348. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2349. {
  2350. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2351. 0:
  2352. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2353. if(idxPeriod > 0)
  2354. {
  2355. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2356. {
  2357. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. else
  2364. {
  2365. if(txProfile.ChargingSchedule.Duration != -1)
  2366. {
  2367. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2368. 0:
  2369. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2370. }
  2371. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2372. {
  2373. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2374. {
  2375. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2376. 0:
  2377. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2378. if(idxPeriod > 0)
  2379. {
  2380. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2381. {
  2382. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2383. }
  2384. }
  2385. }
  2386. }
  2387. }
  2388. }
  2389. /*
  2390. DEBUG_INFO("txProfile after align.\n");
  2391. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2392. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2393. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2394. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2395. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2396. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2397. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2398. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2399. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2400. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2401. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2402. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2403. {
  2404. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2405. {
  2406. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2407. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2408. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2409. }
  2410. }*/
  2411. }
  2412. if(defaultTxProfile.ChargingProfileId != -1)
  2413. {
  2414. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2415. {
  2416. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2417. {
  2418. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2419. 0:
  2420. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2421. }
  2422. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2423. {
  2424. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2425. {
  2426. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2427. 0:
  2428. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2429. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2430. {
  2431. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2432. }
  2433. if(idxPeriod > 0)
  2434. {
  2435. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2436. {
  2437. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2444. {
  2445. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2446. {
  2447. 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?
  2448. 0:
  2449. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2450. }
  2451. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2452. {
  2453. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2454. {
  2455. 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?
  2456. 0:
  2457. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2458. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2459. {
  2460. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2461. }
  2462. if(idxPeriod > 0)
  2463. {
  2464. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2465. {
  2466. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2467. }
  2468. }
  2469. }
  2470. }
  2471. }
  2472. else
  2473. {
  2474. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2475. {
  2476. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2477. {
  2478. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2479. 0:
  2480. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2481. }
  2482. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2483. {
  2484. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2485. {
  2486. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2487. 0:
  2488. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2489. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2490. {
  2491. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2492. }
  2493. if(idxPeriod > 0)
  2494. {
  2495. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2496. {
  2497. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. else
  2504. {
  2505. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2506. {
  2507. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2508. 0:
  2509. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2510. }
  2511. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2512. {
  2513. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2514. {
  2515. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2516. 0:
  2517. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2518. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2519. {
  2520. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2521. }
  2522. if(idxPeriod > 0)
  2523. {
  2524. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2525. {
  2526. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2527. }
  2528. }
  2529. }
  2530. }
  2531. }
  2532. }
  2533. /*
  2534. DEBUG_INFO("defaultTxProfile after align.\n");
  2535. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2536. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2537. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2538. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2539. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2540. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2541. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2542. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2543. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2544. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2545. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2547. {
  2548. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2549. {
  2550. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2551. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2552. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2553. }
  2554. }
  2555. DEBUG_INFO("------------------------------------\n");*/
  2556. }
  2557. if(maxProfile.ChargingProfileId != -1)
  2558. {
  2559. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2560. {
  2561. if(maxProfile.ChargingSchedule.Duration != -1)
  2562. {
  2563. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2564. 0:
  2565. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2566. }
  2567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2568. {
  2569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2570. {
  2571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2572. 0:
  2573. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2574. if(idxPeriod > 0)
  2575. {
  2576. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2577. {
  2578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2585. {
  2586. if(maxProfile.ChargingSchedule.Duration != -1)
  2587. {
  2588. 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?
  2589. 0:
  2590. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2591. }
  2592. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2593. {
  2594. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2595. {
  2596. 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?
  2597. 0:
  2598. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2599. if(idxPeriod > 0)
  2600. {
  2601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2602. {
  2603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2604. }
  2605. }
  2606. }
  2607. }
  2608. }
  2609. else
  2610. {
  2611. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2612. {
  2613. if(maxProfile.ChargingSchedule.Duration != -1)
  2614. {
  2615. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2616. 0:
  2617. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2618. }
  2619. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2620. {
  2621. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2622. {
  2623. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2624. 0:
  2625. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2626. if(idxPeriod > 0)
  2627. {
  2628. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2629. {
  2630. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2631. }
  2632. }
  2633. }
  2634. }
  2635. }
  2636. else
  2637. {
  2638. if(maxProfile.ChargingSchedule.Duration != -1)
  2639. {
  2640. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2641. 0:
  2642. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2643. }
  2644. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2645. {
  2646. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2647. {
  2648. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2649. 0:
  2650. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2651. if(idxPeriod > 0)
  2652. {
  2653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2654. {
  2655. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. /*
  2663. DEBUG_INFO("MaxProfile after align.\n");
  2664. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2665. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2666. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2667. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2668. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2669. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2670. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2671. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2672. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2673. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2674. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2675. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2676. {
  2677. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2678. {
  2679. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2680. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2681. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2682. }
  2683. }
  2684. DEBUG_INFO("------------------------------------\n");*/
  2685. }
  2686. /*
  2687. * Merge to conposite schedule
  2688. */
  2689. //DEBUG_INFO("====================================\n");
  2690. // Find each profile period quantity
  2691. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2692. {
  2693. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2694. limitMax = idx+1;
  2695. }
  2696. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2697. {
  2698. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2699. limitDef = idx+1;
  2700. }
  2701. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2702. {
  2703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2704. limitTx = idx+1;
  2705. }
  2706. // TxProfile found, composite schedule based on it
  2707. if(txProfile.ChargingProfileId != -1)
  2708. {
  2709. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2710. {
  2711. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2712. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2713. (txProfile.ChargingSchedule.Duration > 0))
  2714. {
  2715. if(maxProfile.ChargingProfileId != -1)
  2716. {
  2717. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2718. {
  2719. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2720. {
  2721. if((maxProfile.ChargingSchedule.Duration > 0))
  2722. {
  2723. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2724. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2725. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2726. }
  2727. else
  2728. {
  2729. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2730. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2731. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2732. }
  2733. }
  2734. if(idxMaxPeriod == (limitMax-1))
  2735. {
  2736. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2737. {
  2738. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2739. {
  2740. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2741. compositePeriodIdx++;
  2742. }
  2743. else
  2744. {
  2745. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2746. }
  2747. }
  2748. }
  2749. }
  2750. }
  2751. else
  2752. {
  2753. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2754. {
  2755. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2756. compositePeriodIdx++;
  2757. }
  2758. else
  2759. {
  2760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2761. }
  2762. }
  2763. }
  2764. if(idxTxPeriod == (limitTx-1))
  2765. {
  2766. if(defaultTxProfile.ChargingProfileId != -1)
  2767. {
  2768. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2769. {
  2770. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2771. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2772. (defaultTxProfile.ChargingSchedule.Duration>0))
  2773. {
  2774. if(maxProfile.ChargingProfileId != -1)
  2775. {
  2776. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2777. {
  2778. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2779. {
  2780. if((maxProfile.ChargingSchedule.Duration > 0))
  2781. {
  2782. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2783. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2784. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2785. }
  2786. else
  2787. {
  2788. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2789. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2790. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2791. }
  2792. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2793. {
  2794. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2795. {
  2796. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2797. compositePeriodIdx++;
  2798. }
  2799. else
  2800. {
  2801. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2802. }
  2803. }
  2804. // Delete duplicate period
  2805. if(compositePeriodIdx > 1)
  2806. {
  2807. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2808. {
  2809. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2810. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2811. compositePeriodIdx -= 1;
  2812. }
  2813. }
  2814. }
  2815. else
  2816. break;
  2817. }
  2818. }
  2819. else
  2820. {
  2821. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2822. {
  2823. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2824. compositePeriodIdx++;
  2825. }
  2826. else
  2827. {
  2828. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2829. }
  2830. }
  2831. }
  2832. }
  2833. }
  2834. }
  2835. }
  2836. }
  2837. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2838. else if(defaultTxProfile.ChargingProfileId != -1)
  2839. {
  2840. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2841. {
  2842. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2843. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2844. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2845. {
  2846. if(maxProfile.ChargingProfileId != -1)
  2847. {
  2848. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2849. {
  2850. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2851. {
  2852. if((maxProfile.ChargingSchedule.Duration > 0))
  2853. {
  2854. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2855. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2856. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2857. }
  2858. else
  2859. {
  2860. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2861. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2862. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2863. }
  2864. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2865. {
  2866. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2867. {
  2868. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2869. compositePeriodIdx++;
  2870. }
  2871. else
  2872. {
  2873. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2874. }
  2875. }
  2876. // Delete duplicate period
  2877. if(compositePeriodIdx > 1)
  2878. {
  2879. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2880. {
  2881. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2882. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2883. compositePeriodIdx -= 1;
  2884. }
  2885. }
  2886. }
  2887. else
  2888. break;
  2889. }
  2890. }
  2891. else
  2892. {
  2893. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2894. {
  2895. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2896. compositePeriodIdx++;
  2897. }
  2898. else
  2899. {
  2900. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2901. }
  2902. }
  2903. }
  2904. }
  2905. }
  2906. // Fill other period by MaxProfile
  2907. if(maxProfile.ChargingProfileId != -1)
  2908. {
  2909. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2910. {
  2911. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2912. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2913. (maxProfile.ChargingSchedule.Duration > 0))
  2914. {
  2915. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2916. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2917. {
  2918. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2919. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2920. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2921. }
  2922. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2923. {
  2924. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2925. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2926. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2927. }
  2928. if(tmpPeriod.Limit != -1)
  2929. {
  2930. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2931. {
  2932. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2933. {
  2934. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2935. compositePeriodIdx++;
  2936. }
  2937. else
  2938. {
  2939. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2940. }
  2941. }
  2942. // Delete duplicate period
  2943. if(compositePeriodIdx > 1)
  2944. {
  2945. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2946. {
  2947. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2948. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2949. compositePeriodIdx -= 1;
  2950. }
  2951. }
  2952. }
  2953. }
  2954. }
  2955. }
  2956. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2957. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2958. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2959. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2960. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2961. {
  2962. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2963. {
  2964. compositeProfile->ChargingProfileId = 1;
  2965. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2966. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2967. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2968. }
  2969. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2970. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2971. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2972. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2973. }
  2974. if(line)
  2975. free(line);
  2976. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  2977. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2978. }
  2979. //==========================================
  2980. // Init all share memory
  2981. //==========================================
  2982. int InitShareMemory()
  2983. {
  2984. int result = PASS;
  2985. int MeterSMId;
  2986. //creat ShmSysConfigAndInfo
  2987. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2988. {
  2989. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2990. result = FAIL;
  2991. }
  2992. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2993. {
  2994. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2995. result = FAIL;
  2996. }
  2997. else
  2998. {}
  2999. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3000. {
  3001. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3002. result = FAIL;
  3003. }
  3004. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3005. {
  3006. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3007. result = FAIL;
  3008. }
  3009. else
  3010. {}
  3011. //creat ShmPsuData
  3012. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3013. {
  3014. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3015. result = FAIL;
  3016. }
  3017. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3018. {
  3019. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3020. result = FAIL;
  3021. }
  3022. else
  3023. {}
  3024. //link ShmOCPP16Data
  3025. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3026. {
  3027. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3028. result = FAIL;
  3029. }
  3030. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3031. {
  3032. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3033. result = FAIL;
  3034. }
  3035. else
  3036. {}
  3037. //creat ShmOCPP16DataPH
  3038. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3039. {
  3040. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3041. result = FAIL;
  3042. }
  3043. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3044. {
  3045. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3046. result = FAIL;
  3047. }
  3048. else
  3049. {}
  3050. /****************************** For Initial Settings************************************************/
  3051. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3052. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3053. // allocate Configuration memory address
  3054. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3055. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3056. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3057. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3058. //offline MeterValue Interval
  3059. TempMeterValueInterval = 0;
  3060. return result;
  3061. }
  3062. int ProcessShareMemory()
  3063. {
  3064. if(InitShareMemory() == FAIL)
  3065. {
  3066. DEBUG_ERROR("InitShareMemory NG\n");
  3067. if(ShmStatusCodeData!=NULL)
  3068. {
  3069. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3070. }
  3071. sleep(5);
  3072. return FAIL;
  3073. }
  3074. return PASS;
  3075. }
  3076. void CheckSystemValue(void)
  3077. {
  3078. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3079. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3080. char filenmae[100]={0};
  3081. char str[100]={0};
  3082. int tempIndex = 0;
  3083. //===============================
  3084. // send Heartbeat
  3085. //===============================
  3086. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3087. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3088. {
  3089. clientTime.Heartbeat=time((time_t*)NULL);
  3090. if(server_sign == TRUE)
  3091. {
  3092. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3093. }
  3094. else
  3095. {
  3096. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3097. }
  3098. }
  3099. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3100. {
  3101. //parameter for test
  3102. sendHeartbeatRequest(0);
  3103. //==============================================
  3104. // Reset Waiting Time
  3105. //==============================================
  3106. HeartBeatWithNOResponse += 2;
  3107. }
  3108. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3109. {
  3110. //==========================================
  3111. // csu trigger DataTransferReq
  3112. //==========================================
  3113. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3114. {
  3115. sendDataTransferRequest(gun_index);
  3116. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3117. }
  3118. //===============================
  3119. // CSU Trigger Authorize Request
  3120. //===============================
  3121. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3122. {
  3123. sendAuthorizeRequest(0);
  3124. authorizeRetryTimes = authorizeRetryTimes + 1;
  3125. if(authorizeRetryTimes < 3)
  3126. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3127. }
  3128. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3129. {
  3130. authorizeRetryTimes = 0;
  3131. SetOcppConnStatus(FALSE);
  3132. server_sign = FALSE;
  3133. }
  3134. 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))
  3135. {
  3136. sendAuthorizeRequest(0);
  3137. }
  3138. //==============================================
  3139. // Charger start transaction
  3140. //==============================================
  3141. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3142. {
  3143. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3144. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3145. sendStartTransactionRequest(gun_index);
  3146. clientTime.StartTransaction = time((time_t*)NULL);
  3147. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3148. storeTempStopTransaction(gun_index);
  3149. }
  3150. //==============================================
  3151. // Charger stop transaction
  3152. //==============================================
  3153. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3154. {
  3155. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3156. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3157. sendStopTransactionRequest(gun_index);
  3158. clientTime.StopTransaction = time((time_t*)NULL);
  3159. }
  3160. //==============================================
  3161. // Charger status report
  3162. //==============================================
  3163. //--- Check Mode Change ---//
  3164. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3165. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3166. {
  3167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3168. {
  3169. tempIndex = ((gun_index==2) ? 1: 0);
  3170. }
  3171. else
  3172. {
  3173. tempIndex = gun_index;
  3174. }
  3175. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3176. {
  3177. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3178. {
  3179. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3180. {
  3181. // Sent unplug message for California pricing logic
  3182. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3183. {
  3184. uint8_t ts[20];
  3185. getNowDatetime(ts);
  3186. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3187. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3188. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3189. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3190. }
  3191. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3192. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3193. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3194. }
  3195. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3196. {
  3197. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3198. if((access(filenmae,F_OK))!=-1)
  3199. {
  3200. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3201. sprintf(str,"rm -f %s",filenmae);
  3202. system(str);
  3203. }
  3204. }
  3205. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3206. #if 1 // for TempStopTransaction
  3207. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3208. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3209. {
  3210. checkTempStopTransaction(gun_index);
  3211. }
  3212. #endif
  3213. }
  3214. }
  3215. }
  3216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3217. {
  3218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3219. {
  3220. tempIndex = ((gun_index==2) ? 1: 0);
  3221. }
  3222. else
  3223. {
  3224. tempIndex = gun_index;
  3225. }
  3226. for (int index = 0; index < CCS_QUANTITY; index++)
  3227. {
  3228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3229. {
  3230. 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]*/ )
  3231. {
  3232. // Sent unplug message for California pricing logic
  3233. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3234. {
  3235. uint8_t ts[20];
  3236. getNowDatetime(ts);
  3237. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3238. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3239. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3240. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3241. }
  3242. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3243. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3244. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3245. }
  3246. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3247. {
  3248. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3249. if((access(filenmae,F_OK))!=-1)
  3250. {
  3251. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3252. sprintf(str,"rm -f %s",filenmae);
  3253. system(str);
  3254. }
  3255. }
  3256. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3257. #if 1 // for TempStopTransaction
  3258. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3259. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3260. {
  3261. checkTempStopTransaction(gun_index);
  3262. }
  3263. #endif
  3264. }
  3265. }
  3266. }
  3267. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3268. {
  3269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3270. {
  3271. tempIndex = ((gun_index==2) ? 1: 0);
  3272. }
  3273. else
  3274. {
  3275. tempIndex = gun_index;
  3276. }
  3277. for (int index = 0; index < GB_QUANTITY; index++)
  3278. {
  3279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3280. {
  3281. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3282. {
  3283. // Sent unplug message for California pricing logic
  3284. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3285. {
  3286. uint8_t ts[20];
  3287. getNowDatetime(ts);
  3288. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3289. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3290. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3291. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3292. }
  3293. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3294. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3295. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3296. }
  3297. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3298. {
  3299. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3300. if((access(filenmae,F_OK))!=-1)
  3301. {
  3302. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3303. sprintf(str,"rm -f %s",filenmae);
  3304. system(str);
  3305. }
  3306. }
  3307. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3308. #if 1 // for TempStopTransaction
  3309. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3310. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3311. {
  3312. checkTempStopTransaction(gun_index);
  3313. }
  3314. #endif
  3315. }
  3316. }
  3317. }
  3318. else if(gunType[gun_index] == GUN_TYPE_DO)
  3319. {
  3320. tempIndex = gun_index;
  3321. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3322. {
  3323. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3324. {
  3325. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3326. {
  3327. // Sent unplug message for California pricing logic
  3328. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3329. {
  3330. uint8_t ts[20];
  3331. getNowDatetime(ts);
  3332. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3333. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3334. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3335. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3336. }
  3337. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3338. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3339. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3340. }
  3341. 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_PREPARING))) // complete
  3342. {
  3343. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3344. if((access(filenmae,F_OK))!=-1)
  3345. {
  3346. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3347. sprintf(str,"rm -f %s",filenmae);
  3348. system(str);
  3349. }
  3350. }
  3351. 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);
  3352. #if 1 // for TempStopTransaction
  3353. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3354. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3355. {
  3356. checkTempStopTransaction(gun_index);
  3357. }
  3358. #endif
  3359. }
  3360. }
  3361. }
  3362. else
  3363. {
  3364. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3365. {
  3366. tempIndex = 2;
  3367. }
  3368. else
  3369. {
  3370. tempIndex = gun_index;
  3371. }
  3372. for (int index = 0; index < AC_QUANTITY; index++)
  3373. {
  3374. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3375. {
  3376. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3377. {
  3378. // Sent unplug message for California pricing logic
  3379. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3380. {
  3381. uint8_t ts[20];
  3382. getNowDatetime(ts);
  3383. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3384. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3385. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3386. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3387. }
  3388. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3389. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3390. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3391. }
  3392. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3393. {
  3394. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3395. if((access(filenmae,F_OK))!=-1)
  3396. {
  3397. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3398. sprintf(str,"rm -f %s",filenmae);
  3399. system(str);
  3400. }
  3401. }
  3402. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3403. #if 1 // for TempStopTransaction
  3404. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3405. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3406. {
  3407. checkTempStopTransaction(gun_index);
  3408. }
  3409. #endif
  3410. }
  3411. }// END
  3412. }
  3413. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3414. (
  3415. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3416. )
  3417. )
  3418. {
  3419. if(SystemInitial > 0)
  3420. SystemInitial -= 1;
  3421. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3422. sendStatusNotificationRequest(gun_index);
  3423. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3424. }
  3425. //==============================================
  3426. // CSU Trigger Smart Charging Profilw
  3427. //==============================================
  3428. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3429. {
  3430. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3431. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3432. }
  3433. //==============================================
  3434. // Meter report
  3435. //==============================================
  3436. // Trigger MeterValue
  3437. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3438. {
  3439. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3440. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3441. }
  3442. // ClockAlign MeterValue
  3443. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3444. {
  3445. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3446. {
  3447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3448. {
  3449. tempIndex = ((gun_index==2) ? 1: 0);
  3450. }
  3451. else
  3452. {
  3453. tempIndex = gun_index;
  3454. }
  3455. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3456. {
  3457. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3458. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3459. {
  3460. reqClockAlignMeter[gun_index] = 1;
  3461. }
  3462. }// End for CHAdeMO
  3463. }
  3464. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3465. {
  3466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3467. {
  3468. tempIndex = ((gun_index==2) ? 1: 0);
  3469. }
  3470. else
  3471. {
  3472. tempIndex = gun_index;
  3473. }
  3474. for (int index = 0; index < CCS_QUANTITY; index++)
  3475. {
  3476. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3477. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3478. {
  3479. reqClockAlignMeter[gun_index] = 1;
  3480. }
  3481. } // End for CCS
  3482. }
  3483. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3484. {
  3485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3486. {
  3487. tempIndex = ((gun_index==2) ? 1: 0);
  3488. }
  3489. else
  3490. {
  3491. tempIndex = gun_index;
  3492. }
  3493. for (int index = 0; index < GB_QUANTITY; index++)
  3494. {
  3495. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3496. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3497. {
  3498. reqClockAlignMeter[gun_index] = 1;
  3499. }
  3500. }// End for GB
  3501. }
  3502. else if(gunType[gun_index] == GUN_TYPE_DO)
  3503. {
  3504. tempIndex = gun_index;
  3505. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3506. {
  3507. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3508. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3509. {
  3510. reqClockAlignMeter[gun_index] = 1;
  3511. }
  3512. }
  3513. }
  3514. else
  3515. {
  3516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3517. {
  3518. tempIndex = 2;
  3519. }
  3520. else
  3521. {
  3522. tempIndex = gun_index;
  3523. }
  3524. for (int index = 0; index < AC_QUANTITY; index++)
  3525. {
  3526. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3527. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3528. {
  3529. reqClockAlignMeter[gun_index] = 1;
  3530. }
  3531. }//End for AC
  3532. }
  3533. if(reqClockAlignMeter[gun_index] == 1)
  3534. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3535. }
  3536. // Sample period MeterValue
  3537. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3538. {
  3539. //check Transaction active
  3540. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3541. {
  3542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3543. {
  3544. tempIndex = ((gun_index==2) ? 1: 0);
  3545. }
  3546. else
  3547. {
  3548. tempIndex = gun_index;
  3549. }
  3550. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3551. {
  3552. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3553. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3554. {
  3555. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3556. {
  3557. reqSampleMeter[gun_index] = 1;
  3558. }
  3559. }
  3560. }// End for CHAdeMO
  3561. }
  3562. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3563. {
  3564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3565. {
  3566. tempIndex = ((gun_index==2) ? 1: 0);
  3567. }
  3568. else
  3569. {
  3570. tempIndex = gun_index;
  3571. }
  3572. for (int index = 0; index < CCS_QUANTITY; index++)
  3573. {
  3574. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3575. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3576. {
  3577. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3578. {
  3579. reqSampleMeter[gun_index] = 1;
  3580. }
  3581. }
  3582. } // End for CCS
  3583. }
  3584. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3587. {
  3588. tempIndex = ((gun_index==2) ? 1: 0);
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < GB_QUANTITY; index++)
  3595. {
  3596. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3597. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3598. {
  3599. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3600. {
  3601. reqSampleMeter[gun_index] = 1;
  3602. }
  3603. }
  3604. }// End for GB
  3605. }
  3606. else if(gunType[gun_index] == GUN_TYPE_DO)
  3607. {
  3608. tempIndex = gun_index;
  3609. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3610. {
  3611. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3612. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3613. {
  3614. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3615. {
  3616. reqSampleMeter[gun_index] = 1;
  3617. }
  3618. }
  3619. }
  3620. }
  3621. else
  3622. {
  3623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3624. {
  3625. tempIndex = 2;
  3626. }
  3627. else
  3628. {
  3629. tempIndex = gun_index;
  3630. }
  3631. for (int index = 0; index < AC_QUANTITY; index++)
  3632. {
  3633. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3634. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3635. {
  3636. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3637. {
  3638. reqSampleMeter[gun_index] = 1;
  3639. }
  3640. }
  3641. }//End for AC
  3642. }
  3643. if(reqSampleMeter[gun_index] == 1)
  3644. {
  3645. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3646. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3647. storeTempStopTransaction(gun_index);
  3648. }
  3649. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3650. }
  3651. //==============================================
  3652. // Check Connector reserved
  3653. //==============================================
  3654. //===============================
  3655. // Check if Reserve is expired
  3656. //===============================
  3657. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3658. {
  3659. double diff_t;
  3660. struct tm tp;
  3661. // current time
  3662. time_t t = time(NULL);
  3663. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3664. tp.tm_isdst = -1;
  3665. time_t utc = mktime(&tp);
  3666. diff_t = difftime(utc, t);
  3667. if(diff_t <= 0)
  3668. {
  3669. DEBUG_INFO("reserve expired.\n");
  3670. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3671. }
  3672. }//END OF Check if Reserve is expired
  3673. //==========================================
  3674. // csu trigger FirmwareStatusNotificationReq
  3675. //==========================================
  3676. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3677. {
  3678. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3679. }
  3680. //==========================================
  3681. // csu trigger DiagnosticsStatusNotificationReq
  3682. //==========================================
  3683. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3684. {
  3685. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3686. }
  3687. //==========================================
  3688. // csu trigger CancelReservationConf
  3689. //==========================================
  3690. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3691. {
  3692. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3693. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3694. }
  3695. //==========================================
  3696. // csu trigger ChangeAvailabilityConf
  3697. //==========================================
  3698. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3699. {
  3700. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3701. }
  3702. //==========================================
  3703. // csu trigger UnlockConnectorConf
  3704. //==========================================
  3705. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3706. {
  3707. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3708. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3709. }
  3710. //==========================================
  3711. // csu trigger ReserveNowConf
  3712. //==========================================
  3713. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3714. {
  3715. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3716. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3717. }
  3718. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3719. {
  3720. sendSignCertificateRequest();
  3721. }
  3722. }
  3723. }
  3724. //==========================================
  3725. // send request routine
  3726. //==========================================
  3727. int sendAuthorizeRequest(int gun_index)
  3728. {
  3729. mtrace();
  3730. int result = FAIL;
  3731. char message[100]={0};
  3732. char guid[37];
  3733. char tempdata[65]={0};
  3734. DEBUG_INFO("sendAuthorizeRequest...\n");
  3735. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3736. //Local Authorize
  3737. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3738. {
  3739. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3740. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3741. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3742. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3743. result = PASS;
  3744. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3745. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3746. authorizeRetryTimes = 0;
  3747. return result;
  3748. }
  3749. 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))||
  3750. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3751. {
  3752. // Query from cache
  3753. DEBUG_INFO("Authorize from cache.\n");
  3754. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3755. // Query from list
  3756. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3757. {
  3758. DEBUG_INFO("Authorize from list.\n");
  3759. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3760. }
  3761. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3762. {
  3763. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3764. {
  3765. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3766. }
  3767. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3768. {
  3769. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3770. }
  3771. if(!GetOcppConnStatus())
  3772. {
  3773. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3774. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3775. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3776. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3777. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3778. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3779. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3780. authorizeRetryTimes = 0;
  3781. return result;
  3782. }
  3783. }
  3784. else
  3785. {
  3786. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3787. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3788. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3789. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3790. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3791. else
  3792. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3793. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3794. result = PASS;
  3795. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3796. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3797. authorizeRetryTimes = 0;
  3798. return result;
  3799. }
  3800. }
  3801. //initialize struct Authorize
  3802. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3803. //get data from shared memory
  3804. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3805. random_uuid(guid);
  3806. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3807. LWS_Send(message);
  3808. sprintf(tempdata, "Authorize,%d", gun_index);
  3809. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3810. {
  3811. result = PASS;
  3812. DEBUG_INFO("Authorize mapItem pass\n");
  3813. }
  3814. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3815. return result;
  3816. }
  3817. int sendBootNotificationRequest(void)
  3818. {
  3819. mtrace();
  3820. int result = FAIL;
  3821. char message[500]={0}, payload[700]={0};
  3822. char guid[37]={0};
  3823. char tempdata[65]={0};
  3824. // Fill BootNotification fields
  3825. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3826. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3827. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3828. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3829. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3830. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3831. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3832. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3833. ShmOCPP16DataPH->ChargeBoxId
  3834. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3835. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3836. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3837. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3838. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3839. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3840. random_uuid(guid);
  3841. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3842. LWS_Send(message);
  3843. sprintf(tempdata, "BootNotification,0");
  3844. 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*/)
  3845. {
  3846. result = PASS;
  3847. }
  3848. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3849. strcpy(queuedata,message);
  3850. return result;
  3851. }
  3852. int sendDataTransferRequest(int gun_index)
  3853. {
  3854. mtrace();
  3855. char message[1000]={0};
  3856. char guid[37]={0};
  3857. char tempdata[65]={0};
  3858. int result = FAIL;
  3859. random_uuid(guid);
  3860. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3861. MESSAGE_TYPE_CALL,
  3862. guid,
  3863. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3864. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3865. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3866. LWS_Send(message);
  3867. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3868. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3869. {
  3870. result = PASS;
  3871. DEBUG_INFO("DataTransfer mapItem pass\n");
  3872. }
  3873. return result;
  3874. }
  3875. int sendDiagnosticsStatusNotificationRequest(char *status)
  3876. {
  3877. mtrace();
  3878. int result = FAIL;
  3879. char message[110]={0};
  3880. char guid[37]={0};
  3881. char tempdata[65]={0};
  3882. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3883. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3884. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3885. random_uuid(guid);
  3886. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3887. LWS_SendNow(message);
  3888. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3889. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3890. {
  3891. result = PASS;
  3892. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3893. }
  3894. //#ifdef SystemLogMessage
  3895. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3896. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3897. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3898. //#endif
  3899. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3900. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3901. //record status
  3902. if(strcmp(status,"Idle")==0)
  3903. {
  3904. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3905. }
  3906. else if(strcmp(status,"Uploaded")==0)
  3907. {
  3908. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3909. }
  3910. else if(strcmp(status,"UploadFailed")==0)
  3911. {
  3912. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3913. }
  3914. else if(strcmp(status,"Uploading")==0)
  3915. {
  3916. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3917. }
  3918. return result;
  3919. }
  3920. int sendFirmwareStatusNotificationRequest(char *status)
  3921. {
  3922. mtrace();
  3923. int result = FAIL;
  3924. char message[110]={0};
  3925. char guid[37]={0};
  3926. char tempdata[65]={0};
  3927. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3928. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3929. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3930. random_uuid(guid);
  3931. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3932. LWS_SendNow(message);
  3933. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3934. 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*/)
  3935. {
  3936. result = PASS;
  3937. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3938. }
  3939. //#ifdef SystemLogMessage
  3940. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3941. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3942. //#endif
  3943. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3944. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3945. //record status
  3946. if(strcmp(status,"Downloaded")==0)
  3947. {
  3948. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3949. }
  3950. else if(strcmp(status,"DownloadFailed")==0)
  3951. {
  3952. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3953. }
  3954. else if(strcmp(status,"Downloading")==0)
  3955. {
  3956. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3957. }
  3958. else if(strcmp(status,"Idle")==0)
  3959. {
  3960. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3961. }
  3962. else if(strcmp(status,"InstallationFailed")==0)
  3963. {
  3964. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3965. }
  3966. else if(strcmp(status,"Installing")==0)
  3967. {
  3968. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3969. }
  3970. else if(strcmp(status,"Installed")==0)
  3971. {
  3972. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3973. }
  3974. return result;
  3975. }
  3976. int sendHeartbeatRequest(int gun_index)
  3977. {
  3978. mtrace();
  3979. int result = FAIL;
  3980. char message[80]={0};
  3981. char guid[37]={0};
  3982. char tempdata[65]={0};
  3983. random_uuid(guid);
  3984. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3985. , MESSAGE_TYPE_CALL
  3986. , guid );
  3987. LWS_Send(message);
  3988. sprintf(tempdata, "Heartbeat,%d", 0);
  3989. 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*/)
  3990. {
  3991. result = PASS;
  3992. }
  3993. return result;
  3994. }
  3995. int sendStartTransactionRequest(int gun_index)
  3996. {
  3997. mtrace();
  3998. int result = FAIL;
  3999. char message[250]={0};
  4000. char guid[37]={0};
  4001. struct timeval tmnow;
  4002. struct tm *tm;
  4003. char buf[28];//, usec_buf[6];
  4004. char tempdata[65]={0};
  4005. int tempIndex = 0;
  4006. DEBUG_INFO("sendStartTransactionRequest...\n");
  4007. gettimeofday(&tmnow, NULL);
  4008. time_t t;
  4009. t = time(NULL);
  4010. /*UTC time and date*/
  4011. tm = gmtime(&t);
  4012. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4013. #if 0 // remove temporally
  4014. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4015. strcat(buf,".");
  4016. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4017. strcat(buf,usec_buf);
  4018. #endif
  4019. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4020. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4021. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4022. // clear StartTransaction Response
  4023. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4024. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4025. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4026. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4027. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4028. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4029. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4030. {
  4031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4032. {
  4033. tempIndex = ((gun_index==2) ? 1: 0);
  4034. }
  4035. else
  4036. {
  4037. tempIndex = gun_index;
  4038. }
  4039. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4040. {
  4041. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4042. {
  4043. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4044. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4045. }
  4046. }
  4047. }
  4048. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4049. {
  4050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4051. {
  4052. tempIndex = ((gun_index==2) ? 1: 0);
  4053. }
  4054. else
  4055. {
  4056. tempIndex = gun_index;
  4057. }
  4058. for (int index = 0; index < CCS_QUANTITY; index++)
  4059. {
  4060. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4061. {
  4062. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4063. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4064. }
  4065. }
  4066. }
  4067. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4068. {
  4069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4070. {
  4071. tempIndex = ((gun_index==2) ? 1: 0);
  4072. }
  4073. else
  4074. {
  4075. tempIndex = gun_index;
  4076. }
  4077. for (int index = 0; index < GB_QUANTITY; index++)
  4078. {
  4079. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4080. {
  4081. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4082. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4083. }
  4084. }
  4085. }
  4086. else if(gunType[gun_index] == GUN_TYPE_DO)
  4087. {
  4088. tempIndex = gun_index;
  4089. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4090. {
  4091. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4092. {
  4093. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4094. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4095. }
  4096. }
  4097. }
  4098. else
  4099. {
  4100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4101. {
  4102. tempIndex = 2;
  4103. }
  4104. else
  4105. {
  4106. tempIndex = gun_index;
  4107. }
  4108. for (int index = 0; index < AC_QUANTITY; index++)
  4109. {
  4110. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4111. {
  4112. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4113. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4114. }
  4115. }
  4116. }
  4117. random_uuid(guid);
  4118. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4119. {
  4120. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4121. , gun_index +1
  4122. , MESSAGE_TYPE_CALL
  4123. , guid
  4124. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4125. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4126. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4127. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4128. }
  4129. else
  4130. {
  4131. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4132. , gun_index +1
  4133. , MESSAGE_TYPE_CALL
  4134. , guid
  4135. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4136. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4137. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4138. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4139. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4140. }
  4141. #if 1
  4142. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4143. 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*/)
  4144. {
  4145. result = PASS;
  4146. }
  4147. #endif
  4148. strcpy(queuedata, message);
  4149. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4150. OCPP_insert_transaction_msg(YES, queuedata);
  4151. return result;
  4152. }
  4153. int sendStatusNotificationRequest(int gun_index)
  4154. {
  4155. mtrace();
  4156. int result = FAIL;
  4157. char message[600]={0};
  4158. char guid[37];
  4159. int currentStatus = 0;
  4160. struct timeval tmnow;
  4161. struct tm *tm;
  4162. char buf[28];//, usec_buf[6];
  4163. char tempdata[65]={0};
  4164. int tempIndex = 0;
  4165. uint8_t isStateChanged = TRUE;
  4166. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4167. gettimeofday(&tmnow, NULL);
  4168. time_t t;
  4169. t = time(NULL);
  4170. /*UTC time and date*/
  4171. tm = gmtime(&t);
  4172. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4173. #if 0 // remove temporally
  4174. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4175. strcat(buf,".");
  4176. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4177. strcat(buf,usec_buf);
  4178. #endif
  4179. //printf("%s",buf);
  4180. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4181. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4182. // it's option
  4183. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4184. /*
  4185. enum _SYSTEM_STATUS
  4186. {
  4187. S_BOOTING = 0,
  4188. S_IDLE, = 1
  4189. S_AUTHORIZING, =2
  4190. S_REASSIGN_CHECK, =3
  4191. S_REASSIGN, =4
  4192. S_PRECHARGE, =5
  4193. S_PREPARING_FOR_EV, =6
  4194. S_PREPARING_FOR_EVSE, =7
  4195. S_CHARGING, =8
  4196. S_TERMINATING, =9
  4197. S_COMPLETE, =10
  4198. S_ALARM, =11
  4199. S_FAULT =12
  4200. }
  4201. */
  4202. //check Transaction active
  4203. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4204. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4205. {
  4206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4207. {
  4208. tempIndex = ((gun_index==2) ? 1: 0);
  4209. }
  4210. else
  4211. {
  4212. tempIndex = gun_index;
  4213. }
  4214. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4215. {
  4216. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4217. {
  4218. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4219. {
  4220. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4221. {
  4222. currentStatus = Preparing; //OCPP Status: Preparing
  4223. }
  4224. else
  4225. {
  4226. currentStatus = Available; //OCPP Status: Available
  4227. }
  4228. }
  4229. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4230. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4231. ) //S_PRECHARGE
  4232. {
  4233. currentStatus = Preparing; //OCPP Status: Preparing
  4234. }
  4235. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4236. {
  4237. currentStatus = Charging; //OCPP Status: Charging
  4238. }
  4239. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4240. {
  4241. currentStatus = Finishing; //OCPP Status: Finishing
  4242. }
  4243. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4244. {
  4245. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4246. }
  4247. 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
  4248. {
  4249. currentStatus = Unavailable; //OCPP Status: Unavailable
  4250. }
  4251. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4252. {
  4253. currentStatus = Faulted; //OCPP Status: Faulted
  4254. }
  4255. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4256. {
  4257. currentStatus = Reserved; //OCPP Status: Reserved
  4258. }
  4259. } //end of the same index
  4260. }//end of for CHAdeMO_QUANTITY
  4261. }
  4262. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4263. {
  4264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4265. {
  4266. tempIndex = ((gun_index==2) ? 1: 0);
  4267. }
  4268. else
  4269. {
  4270. tempIndex = gun_index;
  4271. }
  4272. for (int index = 0; index < CCS_QUANTITY; index++)
  4273. {
  4274. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4275. {
  4276. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4277. {
  4278. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4279. {
  4280. currentStatus = Preparing; //OCPP Status: Preparing
  4281. }
  4282. else
  4283. {
  4284. currentStatus = Available; //OCPP Status: Available
  4285. }
  4286. }
  4287. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4288. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4289. ) //S_PRECHARGE
  4290. {
  4291. currentStatus = Preparing; //OCPP Status: Preparing
  4292. }
  4293. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4294. {
  4295. currentStatus = Charging; //OCPP Status: Charging
  4296. }
  4297. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4298. {
  4299. currentStatus = Finishing; //OCPP Status: Finishing
  4300. }
  4301. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4302. {
  4303. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4304. }
  4305. 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
  4306. {
  4307. currentStatus = Unavailable; //OCPP Status : Unavailable
  4308. }
  4309. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4310. {
  4311. currentStatus = Faulted; //OCPP Status: Faulted
  4312. }
  4313. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4314. {
  4315. currentStatus = Reserved; //OCPP Status: Reserved
  4316. }
  4317. } //end of the same index
  4318. } // end of for CCS_QUANTITY
  4319. }
  4320. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4321. {
  4322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4323. {
  4324. tempIndex = ((gun_index==2) ? 1: 0);
  4325. }
  4326. else
  4327. {
  4328. tempIndex = gun_index;
  4329. }
  4330. for (int index = 0; index < GB_QUANTITY; index++)
  4331. {
  4332. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4333. {
  4334. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4335. {
  4336. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4337. {
  4338. currentStatus = Preparing; //OCPP Status: Preparing
  4339. }
  4340. else
  4341. {
  4342. currentStatus = Available; //OCPP Status: Available
  4343. }
  4344. }
  4345. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4346. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4347. ) //S_PRECHARGE
  4348. {
  4349. currentStatus = Preparing; //OCPP Status: Preparing
  4350. }
  4351. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4352. {
  4353. currentStatus = Charging; //OCPP Status: Charging
  4354. }
  4355. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4356. {
  4357. currentStatus = Finishing; //OCPP Status: Finishing
  4358. }
  4359. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4360. {
  4361. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4362. }
  4363. 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
  4364. {
  4365. currentStatus = Unavailable; //OCPP Status: Unavailable
  4366. }
  4367. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4368. {
  4369. currentStatus = Faulted; //OCPP Status: Faulted
  4370. }
  4371. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4372. {
  4373. currentStatus = Reserved; //OCPP Status: Reserved
  4374. }
  4375. } //end of the same index
  4376. } // end of for GB_QUANTITY
  4377. }
  4378. else if(gunType[gun_index] == GUN_TYPE_DO)
  4379. {
  4380. tempIndex = gun_index;
  4381. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4382. {
  4383. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4384. {
  4385. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4386. {
  4387. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4388. {
  4389. currentStatus = Preparing; //OCPP Status: Preparing
  4390. }
  4391. else
  4392. {
  4393. currentStatus = Available; //OCPP Status: Available
  4394. }
  4395. }
  4396. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4397. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4398. ) //S_PRECHARGE
  4399. {
  4400. currentStatus = Preparing; //OCPP Status: Preparing
  4401. }
  4402. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4403. {
  4404. currentStatus = Charging; //OCPP Status: Charging
  4405. }
  4406. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4407. {
  4408. currentStatus = Finishing; //OCPP Status: Finishing
  4409. }
  4410. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4411. {
  4412. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4413. }
  4414. 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
  4415. {
  4416. currentStatus = Unavailable; //OCPP Status: Unavailable
  4417. }
  4418. 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
  4419. {
  4420. currentStatus = Faulted; //OCPP Status: Faulted
  4421. }
  4422. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4423. {
  4424. currentStatus = Reserved; //OCPP Status: Reserved
  4425. }
  4426. } //end of the same index
  4427. }
  4428. }
  4429. else
  4430. {
  4431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4432. {
  4433. tempIndex = 2;
  4434. }
  4435. else
  4436. {
  4437. tempIndex = gun_index;
  4438. }
  4439. for (int index = 0; index < AC_QUANTITY; index++)
  4440. {
  4441. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4442. {
  4443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4444. {
  4445. 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))
  4446. {
  4447. currentStatus = Preparing; //OCPP Status: Preparing
  4448. }
  4449. else
  4450. {
  4451. currentStatus = Available; //OCPP Status: Available
  4452. }
  4453. }
  4454. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4455. {
  4456. currentStatus = Preparing; //OCPP Status: Preparing
  4457. }
  4458. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4459. {
  4460. currentStatus = Charging; //OCPP Status: Charging
  4461. }
  4462. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4463. {
  4464. currentStatus = Finishing; //OCPP Status: Finishing
  4465. }
  4466. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4467. {
  4468. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4469. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4470. else
  4471. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4472. }
  4473. 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
  4474. {
  4475. currentStatus = Unavailable; //OCPP Status: Unavailable
  4476. }
  4477. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4478. {
  4479. currentStatus = Faulted; //OCPP Status: Faulted
  4480. }
  4481. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4482. {
  4483. currentStatus = Reserved; //OCPP Status: Reserved
  4484. }
  4485. }//end of the same index
  4486. }//end of for AC_QUANTITY
  4487. }
  4488. //it's option
  4489. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4490. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4491. {
  4492. isStateChanged = FALSE;
  4493. }
  4494. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4495. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4496. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4497. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4498. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4499. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4500. random_uuid(guid);
  4501. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4502. , MESSAGE_TYPE_CALL
  4503. , guid
  4504. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4505. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4506. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4507. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4508. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4509. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4510. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4511. if((server_sign == TRUE) && isStateChanged)
  4512. {
  4513. LWS_Send(message);
  4514. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4515. 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*/)
  4516. {
  4517. //DEBUG_ERROR("statusNotification mapitem pass");
  4518. result = PASS;
  4519. }
  4520. }
  4521. else
  4522. {
  4523. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4524. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4525. result = PASS;
  4526. }
  4527. return result;
  4528. }
  4529. int sendStopTransactionRequest(int gun_index)
  4530. {
  4531. mtrace();
  4532. int result = FAIL;
  4533. //char message[1500]={0};
  4534. char guid[37]={0};
  4535. char tempdata[65]={0};
  4536. int tempIndex = 0;
  4537. char TempStopTransaction[256];
  4538. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4539. //int idx_sample=0;
  4540. DEBUG_INFO("sendStopTransactionRequest \n");
  4541. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4542. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4543. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4544. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4545. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4546. {
  4547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4548. {
  4549. tempIndex = ((gun_index==2) ? 1: 0);
  4550. }
  4551. else
  4552. {
  4553. tempIndex = gun_index;
  4554. }
  4555. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4556. {
  4557. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4558. {
  4559. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4560. }
  4561. }// END OF CHAdeMO_QUANTITY
  4562. }
  4563. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4564. {
  4565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4566. {
  4567. tempIndex = ((gun_index==2) ? 1: 0);
  4568. }
  4569. else
  4570. {
  4571. tempIndex = gun_index;
  4572. }
  4573. for (int index = 0; index < CCS_QUANTITY; index++)
  4574. {
  4575. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4576. {
  4577. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4578. }
  4579. }// END OF CCS_QUANTITY
  4580. }
  4581. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4582. {
  4583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4584. {
  4585. tempIndex = ((gun_index==2) ? 1: 0);
  4586. }
  4587. else
  4588. {
  4589. tempIndex = gun_index;
  4590. }
  4591. for (int index = 0; index < GB_QUANTITY; index++)
  4592. {
  4593. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4594. {
  4595. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4596. }
  4597. }// END OF GB_QUANTITY
  4598. }
  4599. else if(gunType[gun_index] == GUN_TYPE_DO)
  4600. {
  4601. tempIndex = gun_index;
  4602. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4603. {
  4604. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4605. {
  4606. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4607. }
  4608. }// END OF GB_QUANTITY
  4609. }
  4610. else
  4611. {
  4612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4613. {
  4614. tempIndex = 2;
  4615. }
  4616. else
  4617. {
  4618. tempIndex = gun_index;
  4619. }
  4620. for (int index = 0; index < AC_QUANTITY; index++)
  4621. {
  4622. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4623. {
  4624. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4625. }
  4626. }// END OF AC_QUANTITY
  4627. }
  4628. //====================================== Stop Transaction Time =====================================================
  4629. struct timeval tmnow;
  4630. struct tm *tm;
  4631. char buf[28];//, usec_buf[6];
  4632. gettimeofday(&tmnow, NULL);
  4633. time_t t;
  4634. t = time(NULL);
  4635. /*UTC time and date*/
  4636. tm = gmtime(&t);
  4637. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4638. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4639. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4640. random_uuid(guid);
  4641. /***********************************transactionData******************************************************/
  4642. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4643. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4644. //=================================
  4645. // Transaction_Begin
  4646. //=================================
  4647. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4648. {
  4649. //============================================ Energy.Active.Import.Interval ================================
  4650. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4653. 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*/]);
  4654. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4655. 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))
  4656. {
  4657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4658. }
  4659. else
  4660. {
  4661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4662. }
  4663. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4664. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4665. }
  4666. //=================================
  4667. // Transaction_End
  4668. //=================================
  4669. // ================================= Current.Import L1 ===============================================
  4670. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4671. {
  4672. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4673. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4674. {
  4675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4676. {
  4677. tempIndex = ((gun_index==2) ? 1: 0);
  4678. }
  4679. else
  4680. {
  4681. tempIndex = gun_index;
  4682. }
  4683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4684. {
  4685. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4686. {
  4687. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4688. }
  4689. }// End of for CHAdeMO_QUANTITY
  4690. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4691. }
  4692. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4693. {
  4694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4695. {
  4696. tempIndex = ((gun_index==2) ? 1: 0);
  4697. }
  4698. else
  4699. {
  4700. tempIndex = gun_index;
  4701. }
  4702. for (int index = 0; index < CCS_QUANTITY; index++)
  4703. {
  4704. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4705. {
  4706. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4707. }
  4708. }// End of for CCS_QUANTITY
  4709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4710. }
  4711. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4712. {
  4713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4714. {
  4715. tempIndex = ((gun_index==2) ? 1: 0);
  4716. }
  4717. else
  4718. {
  4719. tempIndex = gun_index;
  4720. }
  4721. for (int index = 0; index < GB_QUANTITY; index++)
  4722. {
  4723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4724. {
  4725. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4726. }
  4727. }// End of for GB_QUANTITY
  4728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4729. }
  4730. else if(gunType[gun_index] == GUN_TYPE_DO)
  4731. {
  4732. tempIndex = gun_index;
  4733. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4734. {
  4735. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4736. {
  4737. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4738. }
  4739. }
  4740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4741. }
  4742. else
  4743. {
  4744. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4745. {
  4746. tempIndex = 2;
  4747. }
  4748. else
  4749. {
  4750. tempIndex = gun_index;
  4751. }
  4752. for (int index = 0; index < AC_QUANTITY; index++)
  4753. {
  4754. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4755. {
  4756. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4757. }
  4758. }// End of for AC_QUANTITY
  4759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4760. }
  4761. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4762. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4763. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4764. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4765. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4766. }
  4767. // ================================= Energy.Active.Import.Interval ==============================================
  4768. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4769. {
  4770. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4771. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4772. {
  4773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4774. {
  4775. tempIndex = ((gun_index==2) ? 1: 0);
  4776. }
  4777. else
  4778. {
  4779. tempIndex = gun_index;
  4780. }
  4781. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4782. {
  4783. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4784. {
  4785. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4786. }
  4787. }// END OF CHAdeMO_QUANTITY
  4788. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4789. }
  4790. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4791. {
  4792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4793. {
  4794. tempIndex = ((gun_index==2) ? 1: 0);
  4795. }
  4796. else
  4797. {
  4798. tempIndex = gun_index;
  4799. }
  4800. for (int index = 0; index < CCS_QUANTITY; index++)
  4801. {
  4802. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4803. {
  4804. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4805. }
  4806. }// END OF CCS_QUANTITY
  4807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4808. }
  4809. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4810. {
  4811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4812. {
  4813. tempIndex = ((gun_index==2) ? 1: 0);
  4814. }
  4815. else
  4816. {
  4817. tempIndex = gun_index;
  4818. }
  4819. for (int index = 0; index < GB_QUANTITY; index++)
  4820. {
  4821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4822. {
  4823. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4824. }
  4825. }// END OF GB_QUANTITY
  4826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4827. }
  4828. else if(gunType[gun_index] == GUN_TYPE_DO)
  4829. {
  4830. tempIndex = gun_index;
  4831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4832. {
  4833. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4834. {
  4835. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4836. }
  4837. }
  4838. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4839. }
  4840. else
  4841. {
  4842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4843. {
  4844. tempIndex = 2;
  4845. }
  4846. else
  4847. {
  4848. tempIndex = gun_index;
  4849. }
  4850. for (int index = 0; index < AC_QUANTITY; index++)
  4851. {
  4852. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4853. {
  4854. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4855. }
  4856. }// END OF AC_QUANTITY
  4857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4858. }
  4859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4864. }
  4865. //=================================== Power.Active.Import ==================================================
  4866. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4867. {
  4868. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4869. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4872. {
  4873. tempIndex = ((gun_index==2) ? 1: 0);
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4880. {
  4881. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4882. {
  4883. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4884. }
  4885. } // End for CHAdeMO_QUANTITY
  4886. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4887. }
  4888. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4889. {
  4890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4891. {
  4892. tempIndex = ((gun_index==2) ? 1: 0);
  4893. }
  4894. else
  4895. {
  4896. tempIndex = gun_index;
  4897. }
  4898. for (int index = 0; index < CCS_QUANTITY; index++)
  4899. {
  4900. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4901. {
  4902. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4903. }
  4904. } // END for CCS_QUANTITY
  4905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4906. }
  4907. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4908. {
  4909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4910. {
  4911. tempIndex = ((gun_index==2) ? 1: 0);
  4912. }
  4913. else
  4914. {
  4915. tempIndex = gun_index;
  4916. }
  4917. for (int index = 0; index < GB_QUANTITY; index++)
  4918. {
  4919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4920. {
  4921. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4922. }
  4923. }// END for GB_QUANTITY
  4924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4925. }
  4926. else if(gunType[gun_index] == GUN_TYPE_DO)
  4927. {
  4928. tempIndex = gun_index;
  4929. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4930. {
  4931. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4932. {
  4933. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4934. }
  4935. }
  4936. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4937. }
  4938. else
  4939. {
  4940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4941. {
  4942. tempIndex = 2;
  4943. }
  4944. else
  4945. {
  4946. tempIndex = gun_index;
  4947. }
  4948. for (int index = 0; index < AC_QUANTITY; index++)
  4949. {
  4950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4951. {
  4952. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4953. }
  4954. } // END for AC_QUANTITY
  4955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4956. }
  4957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4960. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4961. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4962. }
  4963. //============================ Voltage L1 ====================================
  4964. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4965. {
  4966. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4967. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4968. {
  4969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4970. {
  4971. tempIndex = ((gun_index==2) ? 1: 0);
  4972. }
  4973. else
  4974. {
  4975. tempIndex = gun_index;
  4976. }
  4977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4978. {
  4979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4980. {
  4981. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4982. }
  4983. } // END OF FOR CHAdeMO_QUANTITY
  4984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4985. }
  4986. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4987. {
  4988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4989. {
  4990. tempIndex = ((gun_index==2) ? 1: 0);
  4991. }
  4992. else
  4993. {
  4994. tempIndex = gun_index;
  4995. }
  4996. for (int index = 0; index < CCS_QUANTITY; index++)
  4997. {
  4998. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4999. {
  5000. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5001. }
  5002. } // END OF FOR CCS_QUANTITY
  5003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5004. }
  5005. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5006. {
  5007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5008. {
  5009. tempIndex = ((gun_index==2) ? 1: 0);
  5010. }
  5011. else
  5012. {
  5013. tempIndex = gun_index;
  5014. }
  5015. for (int index = 0; index < GB_QUANTITY; index++)
  5016. {
  5017. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5018. {
  5019. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5020. }
  5021. } // END OF FOR GB_QUANTITY
  5022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5023. }
  5024. else if(gunType[gun_index] == GUN_TYPE_DO)
  5025. {
  5026. tempIndex = gun_index;
  5027. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5028. {
  5029. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5030. {
  5031. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5032. }
  5033. }
  5034. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5035. }
  5036. else
  5037. {
  5038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5039. {
  5040. tempIndex = 2;
  5041. }
  5042. else
  5043. {
  5044. tempIndex = gun_index;
  5045. }
  5046. for (int index = 0; index < AC_QUANTITY; index++)
  5047. {
  5048. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5049. {
  5050. 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
  5051. }
  5052. } // END OF FOR AC_QUANTITY
  5053. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5054. }
  5055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5060. }
  5061. //====================== End SoC ================================
  5062. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5063. {
  5064. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5065. 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))
  5066. {
  5067. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5068. {
  5069. tempIndex = ((gun_index==2) ? 1: 0);
  5070. }
  5071. else
  5072. {
  5073. tempIndex = gun_index;
  5074. }
  5075. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5076. {
  5077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5078. {
  5079. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5080. {
  5081. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5082. }
  5083. }
  5084. }
  5085. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5086. {
  5087. for (int index = 0; index < CCS_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5090. {
  5091. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5092. }
  5093. }
  5094. }
  5095. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5096. {
  5097. for (int index = 0; index < GB_QUANTITY; index++)
  5098. {
  5099. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5100. {
  5101. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5102. }
  5103. }
  5104. }
  5105. else if(gunType[gun_index] == GUN_TYPE_DO)
  5106. {
  5107. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5108. {
  5109. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5110. {
  5111. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5112. }
  5113. }
  5114. }
  5115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5121. } // END FOR DC CASE
  5122. }
  5123. // ================================= Current.Import L2 ===============================================
  5124. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5125. {
  5126. // AC 3 phse L2 current
  5127. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5128. {
  5129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5130. {
  5131. tempIndex = 2;
  5132. }
  5133. else
  5134. {
  5135. tempIndex = gun_index;
  5136. }
  5137. for (int index = 0; index < AC_QUANTITY; index++)
  5138. {
  5139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5140. {
  5141. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5142. }
  5143. }// End of for AC_QUANTITY
  5144. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5145. }
  5146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5149. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5151. }
  5152. // ================================= Current.Import L3 ===============================================
  5153. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5154. {
  5155. // AC 3 phse L3 current
  5156. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5157. {
  5158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5159. {
  5160. tempIndex = 2;
  5161. }
  5162. else
  5163. {
  5164. tempIndex = gun_index;
  5165. }
  5166. for (int index = 0; index < AC_QUANTITY; index++)
  5167. {
  5168. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5169. {
  5170. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5171. }
  5172. }// End of for AC_QUANTITY
  5173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5174. }
  5175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5180. }
  5181. //============================ Voltage L2 ====================================
  5182. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5183. {
  5184. // AC 3 phse L2 voltage
  5185. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5186. {
  5187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5188. {
  5189. tempIndex = 2;
  5190. }
  5191. else
  5192. {
  5193. tempIndex = gun_index;
  5194. }
  5195. for (int index = 0; index < AC_QUANTITY; index++)
  5196. {
  5197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5198. {
  5199. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5200. }
  5201. } // END OF FOR AC_QUANTITY
  5202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5203. }
  5204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5205. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5206. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5208. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5209. }
  5210. //============================ Voltage L3 ====================================
  5211. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5212. {
  5213. // AC 3 phse L3 voltage
  5214. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5215. {
  5216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5217. {
  5218. tempIndex = 2;
  5219. }
  5220. else
  5221. {
  5222. tempIndex = gun_index;
  5223. }
  5224. for (int index = 0; index < AC_QUANTITY; index++)
  5225. {
  5226. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5227. {
  5228. 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
  5229. }
  5230. } // END OF FOR AC_QUANTITY
  5231. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5232. }
  5233. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5234. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5235. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5236. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5237. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5238. }
  5239. //====================== Start SoC ================================
  5240. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5241. {
  5242. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5243. 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))
  5244. {
  5245. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5246. {
  5247. tempIndex = ((gun_index==2) ? 1: 0);
  5248. }
  5249. else
  5250. {
  5251. tempIndex = gun_index;
  5252. }
  5253. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5254. {
  5255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5256. {
  5257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5258. {
  5259. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5260. }
  5261. }
  5262. }
  5263. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5264. {
  5265. for (int index = 0; index < CCS_QUANTITY; index++)
  5266. {
  5267. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5268. {
  5269. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5270. }
  5271. }
  5272. }
  5273. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5274. {
  5275. for (int index = 0; index < GB_QUANTITY; index++)
  5276. {
  5277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5278. {
  5279. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5280. }
  5281. }
  5282. }
  5283. else if(gunType[gun_index] == GUN_TYPE_DO)
  5284. {
  5285. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5288. {
  5289. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5290. }
  5291. }
  5292. }
  5293. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5294. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5295. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5296. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5297. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5298. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5299. } // END FOR DC CASE
  5300. }
  5301. //================================================ Message create ====================================================
  5302. json_object *StopTransaction = json_object_new_object();
  5303. json_object *transactionDatas = json_object_new_array();
  5304. json_object *sampledValues = json_object_new_array();
  5305. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5306. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5307. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5308. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5309. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5310. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5311. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5312. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5313. {
  5314. json_object *transactionData = json_object_new_object();
  5315. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5316. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5317. {
  5318. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5319. {
  5320. json_object *sampledValue = json_object_new_object();
  5321. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5322. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5323. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5324. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5325. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5326. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5327. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5328. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5329. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5330. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5331. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5332. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5333. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5334. json_object_array_add(sampledValues, sampledValue);
  5335. }
  5336. }
  5337. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5338. json_object_array_add(transactionDatas, transactionData);
  5339. }
  5340. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5341. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5342. ,MESSAGE_TYPE_CALL
  5343. ,guid
  5344. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5345. json_object_put(StopTransaction);
  5346. #if 1 // for TempStopTransaction
  5347. //Delete TempStopTransaction
  5348. if((access(TempStopTransaction,F_OK))!=-1)
  5349. {
  5350. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5351. }
  5352. #endif
  5353. #if 1
  5354. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5355. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5356. {
  5357. result = PASS;
  5358. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5359. }
  5360. #endif
  5361. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5362. OCPP_insert_transaction_msg(NO, queuedata);
  5363. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5364. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5365. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5366. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5367. {
  5368. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5369. }
  5370. //for test
  5371. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5372. return result;
  5373. }
  5374. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5375. {
  5376. mtrace();
  5377. int result = FAIL;
  5378. char guid[37]={0};
  5379. char tempdata[65]={0};
  5380. int tempIndex = 0;
  5381. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5382. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5383. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5384. //set value
  5385. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5386. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5387. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5388. -1);
  5389. random_uuid(guid);
  5390. //UTC Date time
  5391. struct timeval tmnow;
  5392. struct tm *tm;
  5393. char buf[28];//, usec_buf[6];
  5394. gettimeofday(&tmnow, NULL);
  5395. time_t t;
  5396. t = time(NULL);
  5397. /*UTC time and date*/
  5398. tm = gmtime(&t);
  5399. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5400. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5401. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5402. //********************************(1)Current.Import L1************************************************/
  5403. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5404. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5405. (dataType == ReadingContext_Trigger))
  5406. {
  5407. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5409. {
  5410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5411. {
  5412. tempIndex = ((gun_index==2) ? 1: 0);
  5413. }
  5414. else
  5415. {
  5416. tempIndex = gun_index;
  5417. }
  5418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5419. {
  5420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5421. {
  5422. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5423. }
  5424. }
  5425. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5426. }
  5427. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5428. {
  5429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5430. {
  5431. tempIndex = ((gun_index==2) ? 1: 0);
  5432. }
  5433. else
  5434. {
  5435. tempIndex = gun_index;
  5436. }
  5437. for (int index = 0; index < CCS_QUANTITY; index++)
  5438. {
  5439. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5440. {
  5441. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5442. }
  5443. }
  5444. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5445. }
  5446. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5447. {
  5448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5449. {
  5450. tempIndex = ((gun_index==2) ? 1: 0);
  5451. }
  5452. else
  5453. {
  5454. tempIndex = gun_index;
  5455. }
  5456. for (int index = 0; index < GB_QUANTITY; index++)
  5457. {
  5458. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5459. {
  5460. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5461. }
  5462. }
  5463. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5464. }
  5465. else if(gunType[gun_index] == GUN_TYPE_DO)
  5466. {
  5467. tempIndex = gun_index;
  5468. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5471. {
  5472. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5473. }
  5474. }
  5475. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5476. }
  5477. else
  5478. {
  5479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5480. {
  5481. tempIndex = 2;
  5482. }
  5483. else
  5484. {
  5485. tempIndex = gun_index;
  5486. }
  5487. for (int index = 0; index < AC_QUANTITY; index++)
  5488. {
  5489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5490. {
  5491. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5492. }
  5493. }
  5494. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5495. }
  5496. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5497. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5498. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5499. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5500. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5501. }
  5502. //********************************(2)Energy.Active.Import.Register ************************************************/
  5503. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5504. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5505. (dataType == ReadingContext_Trigger))
  5506. {
  5507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5508. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  5519. {
  5520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5521. {
  5522. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5523. }
  5524. }
  5525. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5526. }
  5527. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5528. {
  5529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5530. {
  5531. tempIndex = ((gun_index==2) ? 1: 0);
  5532. }
  5533. else
  5534. {
  5535. tempIndex = gun_index;
  5536. }
  5537. for (int index = 0; index < CCS_QUANTITY; index++)
  5538. {
  5539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5540. {
  5541. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5542. }
  5543. }
  5544. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5545. }
  5546. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5547. {
  5548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5549. {
  5550. tempIndex = ((gun_index==2) ? 1: 0);
  5551. }
  5552. else
  5553. {
  5554. tempIndex = gun_index;
  5555. }
  5556. for (int index = 0; index < GB_QUANTITY; index++)
  5557. {
  5558. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5559. {
  5560. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5561. }
  5562. }
  5563. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5564. }
  5565. else if(gunType[gun_index] == GUN_TYPE_DO)
  5566. {
  5567. tempIndex = gun_index;
  5568. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5569. {
  5570. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5571. {
  5572. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5573. }
  5574. }
  5575. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5576. }
  5577. else
  5578. {
  5579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5580. {
  5581. tempIndex = 2;
  5582. }
  5583. else
  5584. {
  5585. tempIndex = gun_index;
  5586. }
  5587. for (int index = 0; index < AC_QUANTITY; index++)
  5588. {
  5589. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5590. {
  5591. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5592. }
  5593. }
  5594. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5595. }
  5596. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5598. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5599. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5600. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5601. }
  5602. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5603. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5604. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5605. (dataType == ReadingContext_Trigger))
  5606. {
  5607. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5608. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5609. {
  5610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5611. {
  5612. tempIndex = ((gun_index==2) ? 1: 0);
  5613. }
  5614. else
  5615. {
  5616. tempIndex = gun_index;
  5617. }
  5618. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5619. {
  5620. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5621. {
  5622. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5623. }
  5624. } // END OF FOR CHAdeMO_QUANTITY
  5625. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5626. }
  5627. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5628. {
  5629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5630. {
  5631. tempIndex = ((gun_index==2) ? 1: 0);
  5632. }
  5633. else
  5634. {
  5635. tempIndex = gun_index;
  5636. }
  5637. for (int index = 0; index < CCS_QUANTITY; index++)
  5638. {
  5639. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5640. {
  5641. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5642. }
  5643. } // END OF CCS_QUANTITY
  5644. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5645. }
  5646. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5647. {
  5648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5649. {
  5650. tempIndex = ((gun_index==2) ? 1: 0);
  5651. }
  5652. else
  5653. {
  5654. tempIndex = gun_index;
  5655. }
  5656. for (int index = 0; index < GB_QUANTITY; index++)
  5657. {
  5658. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5659. {
  5660. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5661. }
  5662. } // END OF GB_QUANTITY
  5663. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5664. }
  5665. else if(gunType[gun_index] == GUN_TYPE_DO)
  5666. {
  5667. tempIndex = gun_index;
  5668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5669. {
  5670. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5671. {
  5672. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5673. }
  5674. }
  5675. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5676. }
  5677. else
  5678. {
  5679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5680. {
  5681. tempIndex = 2;
  5682. }
  5683. else
  5684. {
  5685. tempIndex = gun_index;
  5686. }
  5687. for (int index = 0; index < AC_QUANTITY; index++)
  5688. {
  5689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5690. {
  5691. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5692. }
  5693. }
  5694. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5695. }
  5696. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5697. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5698. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5699. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5701. }
  5702. //********************************(4)Power.Active.Import************************************************/
  5703. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5704. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5705. (dataType == ReadingContext_Trigger))
  5706. {
  5707. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5709. {
  5710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5711. {
  5712. tempIndex = ((gun_index==2) ? 1: 0);
  5713. }
  5714. else
  5715. {
  5716. tempIndex = gun_index;
  5717. }
  5718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5719. {
  5720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5721. {
  5722. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5723. }
  5724. } // END OF FOR
  5725. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5726. }
  5727. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5728. {
  5729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5730. {
  5731. tempIndex = ((gun_index==2) ? 1: 0);
  5732. }
  5733. else
  5734. {
  5735. tempIndex = gun_index;
  5736. }
  5737. for (int index = 0; index < CCS_QUANTITY; index++)
  5738. {
  5739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5740. {
  5741. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5742. }
  5743. }
  5744. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5745. }
  5746. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5747. {
  5748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5749. {
  5750. tempIndex = ((gun_index==2) ? 1: 0);
  5751. }
  5752. else
  5753. {
  5754. tempIndex = gun_index;
  5755. }
  5756. for (int index = 0; index < GB_QUANTITY; index++)
  5757. {
  5758. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5759. {
  5760. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5761. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5762. }
  5763. }
  5764. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5765. }
  5766. else if(gunType[gun_index] == GUN_TYPE_DO)
  5767. {
  5768. tempIndex = gun_index;
  5769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5770. {
  5771. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5772. {
  5773. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5774. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5775. }
  5776. }
  5777. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5778. }
  5779. else
  5780. {
  5781. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5782. {
  5783. tempIndex = 2;
  5784. }
  5785. else
  5786. {
  5787. tempIndex = gun_index;
  5788. }
  5789. for (int index = 0; index < AC_QUANTITY; index++)
  5790. {
  5791. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5792. {
  5793. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5794. }
  5795. }
  5796. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5797. }
  5798. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5799. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5800. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5801. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5802. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5803. }
  5804. //***********************************************(5)VOLTAGE L1******************************************************/
  5805. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5806. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5807. (dataType == ReadingContext_Trigger))
  5808. {
  5809. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5810. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5811. {
  5812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5813. {
  5814. tempIndex = ((gun_index==2) ? 1: 0);
  5815. }
  5816. else
  5817. {
  5818. tempIndex = gun_index;
  5819. }
  5820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5821. {
  5822. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5823. {
  5824. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5825. }
  5826. }
  5827. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5828. }
  5829. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5830. {
  5831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5832. {
  5833. tempIndex = ((gun_index==2) ? 1: 0);
  5834. }
  5835. else
  5836. {
  5837. tempIndex = gun_index;
  5838. }
  5839. for (int index = 0; index < CCS_QUANTITY; index++)
  5840. {
  5841. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5842. {
  5843. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5844. }
  5845. }
  5846. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5847. }
  5848. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5849. {
  5850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5851. {
  5852. tempIndex = ((gun_index==2) ? 1: 0);
  5853. }
  5854. else
  5855. {
  5856. tempIndex = gun_index;
  5857. }
  5858. for (int index = 0; index < GB_QUANTITY; index++)
  5859. {
  5860. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5861. {
  5862. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5863. }
  5864. }
  5865. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5866. }
  5867. else if(gunType[gun_index] == GUN_TYPE_DO)
  5868. {
  5869. tempIndex = gun_index;
  5870. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5871. {
  5872. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5873. {
  5874. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5875. }
  5876. }
  5877. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5878. }
  5879. else
  5880. {
  5881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5882. {
  5883. tempIndex = 2;
  5884. }
  5885. else
  5886. {
  5887. tempIndex = gun_index;
  5888. }
  5889. for (int index = 0; index < AC_QUANTITY; index++)
  5890. {
  5891. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5892. {
  5893. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5894. }
  5895. }
  5896. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5897. }
  5898. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5899. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5900. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5901. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5902. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5903. }
  5904. //***********************************************(6)SOC******************************************************/
  5905. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  5906. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  5907. (dataType == ReadingContext_Trigger))
  5908. {
  5909. 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))
  5910. {
  5911. //idx_sample=5;
  5912. //sampledValue = NULL;
  5913. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5914. {
  5915. tempIndex = ((gun_index==2) ? 1: 0);
  5916. }
  5917. else
  5918. {
  5919. tempIndex = gun_index;
  5920. }
  5921. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5922. {
  5923. //tempIndex = ((gun_index==2) ? 1: 0);
  5924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5925. {
  5926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5927. {
  5928. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5929. }
  5930. }
  5931. }
  5932. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5933. {
  5934. //tempIndex = ((gun_index==2) ? 1: 0);
  5935. for (int index = 0; index < CCS_QUANTITY; index++)
  5936. {
  5937. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5938. {
  5939. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5940. }
  5941. }
  5942. }
  5943. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5944. {
  5945. //tempIndex = ((gun_index==2) ? 1: 0);
  5946. for (int index = 0; index < GB_QUANTITY; index++)
  5947. {
  5948. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5949. {
  5950. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5951. }
  5952. }
  5953. }
  5954. else if(gunType[gun_index] == GUN_TYPE_DO)
  5955. {
  5956. //tempIndex = ((gun_index==2) ? 1: 0);
  5957. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5958. {
  5959. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5960. {
  5961. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5962. }
  5963. }
  5964. }
  5965. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5966. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5967. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5968. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5969. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5970. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5971. }
  5972. }
  5973. //********************************(7)Current.Import L2************************************************/
  5974. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5975. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5976. (dataType == ReadingContext_Trigger))
  5977. {
  5978. // Only for AC 3 phase
  5979. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5980. {
  5981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5982. {
  5983. tempIndex = 2;
  5984. }
  5985. else
  5986. {
  5987. tempIndex = gun_index;
  5988. }
  5989. for (int index = 0; index < AC_QUANTITY; index++)
  5990. {
  5991. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5992. {
  5993. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5994. }
  5995. }
  5996. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5997. }
  5998. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5999. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6000. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6001. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6002. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6003. }
  6004. //********************************(8)Current.Import L3************************************************/
  6005. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6006. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6007. (dataType == ReadingContext_Trigger))
  6008. {
  6009. // Only for AC 3 phase
  6010. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6011. {
  6012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6013. {
  6014. tempIndex = 2;
  6015. }
  6016. else
  6017. {
  6018. tempIndex = gun_index;
  6019. }
  6020. for (int index = 0; index < AC_QUANTITY; index++)
  6021. {
  6022. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6023. {
  6024. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6025. }
  6026. }
  6027. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6028. }
  6029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6031. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6032. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6033. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6034. }
  6035. //***********************************************(9)VOLTAGE L2******************************************************/
  6036. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6037. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6038. (dataType == ReadingContext_Trigger))
  6039. {
  6040. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6041. {
  6042. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6043. {
  6044. tempIndex = 2;
  6045. }
  6046. else
  6047. {
  6048. tempIndex = gun_index;
  6049. }
  6050. for (int index = 0; index < AC_QUANTITY; index++)
  6051. {
  6052. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6053. {
  6054. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6055. }
  6056. }
  6057. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6058. }
  6059. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6060. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6061. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6062. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6063. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6064. }
  6065. //***********************************************(10)VOLTAGE L3******************************************************/
  6066. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6067. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6068. (dataType == ReadingContext_Trigger))
  6069. {
  6070. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6071. {
  6072. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6073. {
  6074. tempIndex = 2;
  6075. }
  6076. else
  6077. {
  6078. tempIndex = gun_index;
  6079. }
  6080. for (int index = 0; index < AC_QUANTITY; index++)
  6081. {
  6082. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6083. {
  6084. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6085. }
  6086. }
  6087. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6088. }
  6089. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6090. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6091. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6092. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6093. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6094. }
  6095. //***********************************************(11)Current.Offered******************************************************/
  6096. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6097. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6098. (dataType == ReadingContext_Trigger))
  6099. {
  6100. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6101. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6102. {
  6103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6104. {
  6105. tempIndex = ((gun_index==2) ? 1: 0);
  6106. }
  6107. else
  6108. {
  6109. tempIndex = gun_index;
  6110. }
  6111. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6112. {
  6113. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6114. {
  6115. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6116. }
  6117. } // END OF FOR CHAdeMO_QUANTITY
  6118. }
  6119. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6120. {
  6121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6122. {
  6123. tempIndex = ((gun_index==2) ? 1: 0);
  6124. }
  6125. else
  6126. {
  6127. tempIndex = gun_index;
  6128. }
  6129. for (int index = 0; index < CCS_QUANTITY; index++)
  6130. {
  6131. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6132. {
  6133. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6134. }
  6135. } // END OF CCS_QUANTITY
  6136. }
  6137. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6138. {
  6139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6140. {
  6141. tempIndex = ((gun_index==2) ? 1: 0);
  6142. }
  6143. else
  6144. {
  6145. tempIndex = gun_index;
  6146. }
  6147. for (int index = 0; index < GB_QUANTITY; index++)
  6148. {
  6149. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6150. {
  6151. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6152. }
  6153. } // END OF GB_QUANTITY
  6154. }
  6155. else if(gunType[gun_index] == GUN_TYPE_DO)
  6156. {
  6157. tempIndex = gun_index;
  6158. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6159. {
  6160. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6161. {
  6162. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6163. }
  6164. }
  6165. }
  6166. else
  6167. {
  6168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6169. {
  6170. tempIndex = 2;
  6171. }
  6172. else
  6173. {
  6174. tempIndex = gun_index;
  6175. }
  6176. for (int index = 0; index < AC_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6179. {
  6180. uint16_t currentOffer;
  6181. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6182. {
  6183. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6184. }
  6185. else
  6186. {
  6187. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6188. }
  6189. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6190. }
  6191. }
  6192. }
  6193. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6194. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6195. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6196. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6197. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6198. }
  6199. //***********************************************(12)Power.Offered******************************************************/
  6200. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6201. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6202. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6203. {
  6204. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6205. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6206. {
  6207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6208. {
  6209. tempIndex = ((gun_index==2) ? 1: 0);
  6210. }
  6211. else
  6212. {
  6213. tempIndex = gun_index;
  6214. }
  6215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6216. {
  6217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6218. {
  6219. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6220. }
  6221. } // END OF FOR CHAdeMO_QUANTITY
  6222. }
  6223. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6224. {
  6225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6226. {
  6227. tempIndex = ((gun_index==2) ? 1: 0);
  6228. }
  6229. else
  6230. {
  6231. tempIndex = gun_index;
  6232. }
  6233. for (int index = 0; index < CCS_QUANTITY; index++)
  6234. {
  6235. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6236. {
  6237. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6238. }
  6239. } // END OF CCS_QUANTITY
  6240. }
  6241. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6242. {
  6243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6244. {
  6245. tempIndex = ((gun_index==2) ? 1: 0);
  6246. }
  6247. else
  6248. {
  6249. tempIndex = gun_index;
  6250. }
  6251. for (int index = 0; index < GB_QUANTITY; index++)
  6252. {
  6253. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6254. {
  6255. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6256. }
  6257. } // END OF GB_QUANTITY
  6258. }
  6259. else if(gunType[gun_index] == GUN_TYPE_DO)
  6260. {
  6261. tempIndex = gun_index;
  6262. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6263. {
  6264. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6265. {
  6266. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6267. }
  6268. }
  6269. }
  6270. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6271. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6272. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6273. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6274. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6275. }
  6276. // Message create ====================================================================================================
  6277. if(TRUE)
  6278. {
  6279. json_object *MeterValueReq = json_object_new_object();
  6280. json_object *MeterValues = json_object_new_array();
  6281. json_object *sampledValues = json_object_new_array();
  6282. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6283. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6284. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6285. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6286. {
  6287. json_object *MeterValue = json_object_new_object();
  6288. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6289. {
  6290. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6291. {
  6292. json_object *sampledValue = json_object_new_object();
  6293. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6294. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6295. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6296. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6297. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6298. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6299. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6300. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6301. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6302. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6303. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6304. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6305. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6306. json_object_array_add(sampledValues, sampledValue);
  6307. }
  6308. }
  6309. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6310. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6311. json_object_array_add(MeterValues, MeterValue);
  6312. }
  6313. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6314. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6315. ,gun_index + 1
  6316. ,MESSAGE_TYPE_CALL
  6317. ,guid
  6318. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6319. json_object_put(MeterValueReq);
  6320. }
  6321. // Put request guid to hash map
  6322. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6323. 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*/)
  6324. {
  6325. result = PASS;
  6326. //DEBUG_INFO("MeterValues mapitem pass\n");
  6327. }
  6328. if((dataType != ReadingContext_Trigger) &&
  6329. (dataType != ReadingContext_Sample_Clock) &&
  6330. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6331. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6332. else
  6333. {
  6334. if(FirstHeartBeat)
  6335. LWS_Send(queuedata +2);
  6336. }
  6337. return result;
  6338. }
  6339. int sendLogStatusNotificationRequest(char *status)
  6340. {
  6341. mtrace();
  6342. int result = PASS;
  6343. char message[4096]={0};
  6344. char guid[37]={0};
  6345. char tempdata[128]={0};
  6346. json_object *LogStatusNotification = json_object_new_object();
  6347. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6348. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6349. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6350. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6351. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6352. random_uuid(guid);
  6353. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6354. json_object_put(LogStatusNotification);
  6355. LWS_Send(message);
  6356. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6357. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6358. {
  6359. result = PASS;
  6360. }
  6361. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6362. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6363. return result;
  6364. }
  6365. int sendSecurityEventNotificationRequest()
  6366. {
  6367. mtrace();
  6368. int result = PASS;
  6369. char message[4096]={0};
  6370. char guid[37]={0};
  6371. char tempdata[128]={0};
  6372. json_object *SecurityEventNotification = json_object_new_object();
  6373. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6374. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6375. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6376. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6377. random_uuid(guid);
  6378. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6379. json_object_put(SecurityEventNotification);
  6380. LWS_Send(message);
  6381. sprintf(tempdata, "SecurityEventNotification,0");
  6382. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6383. {
  6384. result = PASS;
  6385. }
  6386. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6387. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6388. return result;
  6389. }
  6390. int sendSignCertificateRequest()
  6391. {
  6392. mtrace();
  6393. int result = PASS;
  6394. char message[4096]={0};
  6395. char guid[37]={0};
  6396. char tempdata[128]={0};
  6397. json_object *SignCertificate = json_object_new_object();
  6398. DEBUG_INFO("sendSignCertificateRequest...\n");
  6399. // Read csr file content
  6400. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6401. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6402. char *line = NULL;
  6403. size_t len = 0;
  6404. while(getline(&line, &len, fp) != -1)
  6405. {
  6406. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6407. {
  6408. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6409. }
  6410. }
  6411. fclose(fp);
  6412. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6413. random_uuid(guid);
  6414. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6415. json_object_put(SignCertificate);
  6416. LWS_Send(message);
  6417. sprintf(tempdata, "SignCertificate,0");
  6418. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6419. {
  6420. result = PASS;
  6421. }
  6422. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6423. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6424. return result;
  6425. }
  6426. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6427. {
  6428. mtrace();
  6429. int result = PASS;
  6430. char message[110]={0};
  6431. char guid[37]={0};
  6432. char tempdata[65]={0};
  6433. json_object *FirmwareStatusNotification = json_object_new_object();
  6434. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6435. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6436. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6437. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6438. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6439. random_uuid(guid);
  6440. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6441. json_object_put(FirmwareStatusNotification);
  6442. LWS_Send(message);
  6443. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6444. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6445. {
  6446. result = PASS;
  6447. }
  6448. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6449. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6450. return result;
  6451. }
  6452. //==========================================
  6453. // send confirm routine
  6454. //==========================================
  6455. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6456. {
  6457. mtrace();
  6458. int result = FAIL;
  6459. char message[100]={0};
  6460. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6461. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6462. LWS_Send(message);
  6463. result = TRUE;
  6464. return result;
  6465. }
  6466. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6467. {
  6468. mtrace();
  6469. int result = FAIL;
  6470. char message[100]={0};
  6471. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6472. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6473. LWS_Send(message);
  6474. result = TRUE;
  6475. return result;
  6476. }
  6477. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6478. {
  6479. mtrace();
  6480. int result = FAIL;
  6481. char message[100]={0};
  6482. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6483. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6484. LWS_Send(message);
  6485. result = TRUE;
  6486. return result;
  6487. }
  6488. int sendClearCacheConfirmation(char *uuid,char *payload)
  6489. {
  6490. mtrace();
  6491. int result = FAIL;
  6492. char message[500]={0};
  6493. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6494. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6495. LWS_Send(message);
  6496. return result;
  6497. }
  6498. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6499. {
  6500. mtrace();
  6501. int result = FAIL;
  6502. char message[500]={0};
  6503. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6504. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6505. LWS_Send(message);
  6506. return result;
  6507. }
  6508. int sendDataTransferConfirmation(char *uuid,char *payload)
  6509. {
  6510. mtrace();
  6511. char statusStr[20]={0};
  6512. char dataStr[10]={0};
  6513. char sstr[20]={0};
  6514. int c = 0;
  6515. char *loc;
  6516. int result = FAIL;
  6517. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6518. /**********************status**************************/
  6519. loc = strstr(payload, "status");
  6520. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6521. c = 0;
  6522. while (loc[3+strlen("status")+c] != '\"')
  6523. {
  6524. sstr[c] = loc[3+strlen("status")+c];
  6525. c++;
  6526. }
  6527. sstr[c] = '\0';
  6528. strcpy(statusStr, sstr);
  6529. /**********************data**************************/
  6530. loc = strstr(payload, "data");
  6531. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6532. c = 0;
  6533. while (loc[3+strlen("data")+c] != '\"')
  6534. {
  6535. sstr[c] = loc[3+strlen("data")+c];
  6536. c++;
  6537. }
  6538. sstr[c] = '\0';
  6539. strcpy(dataStr, sstr);
  6540. return result;
  6541. }
  6542. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6543. {
  6544. mtrace();
  6545. int result = FAIL;
  6546. char message[1000]={0};
  6547. int CompositeScheduleIndex = 0;
  6548. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6549. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6550. if(nPeriod == 0)
  6551. {
  6552. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6553. {
  6554. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6555. ,MESSAGE_TYPE_CALLRESULT
  6556. ,uuid
  6557. ,payload
  6558. ,connectorIdInt);
  6559. }
  6560. else
  6561. {
  6562. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6563. ,MESSAGE_TYPE_CALLRESULT
  6564. ,uuid
  6565. ,payload
  6566. ,connectorIdInt
  6567. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6568. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6569. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6570. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6571. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6572. }
  6573. }
  6574. else
  6575. {
  6576. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6577. ,MESSAGE_TYPE_CALLRESULT
  6578. ,uuid
  6579. ,payload
  6580. ,connectorIdInt
  6581. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6582. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6583. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6584. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6585. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6586. {
  6587. if (idx_sample == 0)
  6588. {
  6589. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6590. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6591. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6592. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6593. }
  6594. else
  6595. {
  6596. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6597. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6598. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6599. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6600. }
  6601. }
  6602. sprintf(message + strlen(message), "]}}]");
  6603. }
  6604. LWS_Send(message);
  6605. result = TRUE;
  6606. return result;
  6607. }
  6608. int sendGetConfigurationConfirmation(char *uuid)
  6609. {
  6610. mtrace();
  6611. int result = FAIL;
  6612. int MaxKeySupported = 0;
  6613. int sentConfigurationNumber= 0;
  6614. int sentunConfigurationNumber= 0;
  6615. char message[1024*10]={0};
  6616. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6617. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6618. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6619. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6620. ,MESSAGE_TYPE_CALLRESULT
  6621. ,uuid );
  6622. //configuration key
  6623. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6624. {
  6625. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6626. {
  6627. if (sentConfigurationNumber == 0)
  6628. {
  6629. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6630. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6631. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6632. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6633. }
  6634. else
  6635. {
  6636. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6637. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6638. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6639. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6640. }
  6641. sentConfigurationNumber = sentConfigurationNumber + 1;
  6642. }
  6643. }
  6644. sprintf(message + strlen(message), "]");
  6645. if(UnknownKeynum != 0)
  6646. {
  6647. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6648. //unkown key
  6649. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6650. {
  6651. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6652. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6653. if(sentunConfigurationNumber == 0)
  6654. {
  6655. sprintf(message + strlen(message), "\"%s\""
  6656. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6657. }
  6658. else
  6659. {
  6660. sprintf(message + strlen(message), ",\"%s\""
  6661. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6662. }
  6663. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6664. }
  6665. sprintf(message + strlen(message), "]");
  6666. }
  6667. sprintf(message + strlen(message), "}]");
  6668. LWS_Send(message);
  6669. return result;
  6670. }
  6671. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6672. {
  6673. mtrace();
  6674. int result = FAIL;
  6675. char message[400]={0};
  6676. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6677. if(strcmp(payload,"")==0)
  6678. {
  6679. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6680. }
  6681. else
  6682. {
  6683. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6684. }
  6685. LWS_Send(message);
  6686. result = TRUE;
  6687. return result;
  6688. }
  6689. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6690. {
  6691. mtrace();
  6692. int result = FAIL;
  6693. char message[80]={0};
  6694. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6695. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  6696. LWS_Send(message);
  6697. result = TRUE;
  6698. return result;
  6699. }
  6700. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6701. {
  6702. mtrace();
  6703. int result = FAIL;
  6704. char message[80]={0};
  6705. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6706. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6707. LWS_Send(message);
  6708. result = TRUE;
  6709. return result;
  6710. }
  6711. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6712. {
  6713. mtrace();
  6714. int result = FAIL;
  6715. char message[80]={0};
  6716. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6717. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6718. LWS_Send(message);
  6719. result = TRUE;
  6720. return result;
  6721. }
  6722. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6723. {
  6724. mtrace();
  6725. int result = FAIL;
  6726. char message[80]={0};
  6727. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6728. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6729. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6730. LWS_Send(message);
  6731. result = TRUE;
  6732. return result;
  6733. }
  6734. int sendResetConfirmation(char *uuid,char *payload)
  6735. {
  6736. mtrace();
  6737. int result = FAIL;
  6738. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6739. char message[80]={0};
  6740. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6741. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6742. LWS_Send(message);
  6743. result = TRUE;
  6744. return result;
  6745. }
  6746. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6747. {
  6748. mtrace();
  6749. int result = FAIL;
  6750. char message[500]={0};
  6751. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6752. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6753. LWS_Send(message);
  6754. result = TRUE;
  6755. return result;
  6756. }
  6757. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6758. {
  6759. mtrace();
  6760. int result = FAIL;
  6761. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6762. char message[80]={0};
  6763. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6764. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6765. LWS_Send(message);
  6766. result = TRUE;
  6767. return result;
  6768. }
  6769. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6770. {
  6771. mtrace();
  6772. int result = FAIL;
  6773. char message[80]={0};
  6774. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6775. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6776. LWS_Send(message);
  6777. result = TRUE;
  6778. return result;
  6779. }
  6780. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6781. {
  6782. mtrace();
  6783. int result = FAIL;
  6784. char message[80]={0};
  6785. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6786. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6787. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6788. LWS_Send(message);
  6789. result = TRUE;
  6790. return result;
  6791. }
  6792. int sendUpdateFirmwareConfirmation(char *uuid)
  6793. {
  6794. mtrace();
  6795. int result = FAIL;
  6796. char message[60]={0};
  6797. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6798. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6799. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6800. LWS_Send(message);
  6801. result = TRUE;
  6802. return result;
  6803. }
  6804. int sendCertificateSignedConfirmation(char *uuid)
  6805. {
  6806. mtrace();
  6807. int result = PASS;
  6808. char message[4096]={0};
  6809. json_object *CertificateSigned = json_object_new_object();
  6810. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6811. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6812. sprintf(message,"[%d,\"%s\",%s]"
  6813. ,MESSAGE_TYPE_CALLRESULT
  6814. ,uuid
  6815. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6816. json_object_put(CertificateSigned);
  6817. LWS_Send(message);
  6818. return result;
  6819. }
  6820. int sendDeleteCertificateConfirmation(char *uuid)
  6821. {
  6822. mtrace();
  6823. int result = PASS;
  6824. char message[4096]={0};
  6825. json_object *DeleteCertificate = json_object_new_object();
  6826. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6827. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6828. sprintf(message,"[%d,\"%s\",%s]"
  6829. ,MESSAGE_TYPE_CALLRESULT
  6830. ,uuid
  6831. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6832. json_object_put(DeleteCertificate);
  6833. LWS_Send(message);
  6834. return result;
  6835. }
  6836. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6837. {
  6838. mtrace();
  6839. int result = PASS;
  6840. char message[4096]={0};
  6841. json_object *ExtendedTriggerMessage = json_object_new_object();
  6842. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6843. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6844. sprintf(message,"[%d,\"%s\",%s]"
  6845. ,MESSAGE_TYPE_CALLRESULT
  6846. ,uuid
  6847. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6848. json_object_put(ExtendedTriggerMessage);
  6849. LWS_Send(message);
  6850. return result;
  6851. }
  6852. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6853. {
  6854. mtrace();
  6855. int result = PASS;
  6856. char message[4096]={0};
  6857. json_object *GetInstalledCertificateIds = json_object_new_object();
  6858. json_object *certificateHashDataDatas = json_object_new_array();
  6859. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6860. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6861. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6862. {
  6863. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6864. {
  6865. json_object *certificateHashData = json_object_new_object();
  6866. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6867. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6868. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6869. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6870. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6871. }
  6872. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6873. }
  6874. else
  6875. {
  6876. json_object_put(certificateHashDataDatas);
  6877. }
  6878. sprintf(message,"[%d,\"%s\",%s]"
  6879. ,MESSAGE_TYPE_CALLRESULT
  6880. ,uuid
  6881. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6882. json_object_put(GetInstalledCertificateIds);
  6883. LWS_Send(message);
  6884. return result;
  6885. }
  6886. int sendGetLogConfirmation(char *uuid)
  6887. {
  6888. mtrace();
  6889. int result = PASS;
  6890. char message[4096]={0};
  6891. json_object *GetLog = json_object_new_object();
  6892. DEBUG_INFO("sendGetLogConfirmation...\n");
  6893. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6894. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6895. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6896. sprintf(message,"[%d,\"%s\",%s]"
  6897. ,MESSAGE_TYPE_CALLRESULT
  6898. ,uuid
  6899. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6900. json_object_put(GetLog);
  6901. LWS_Send(message);
  6902. return result;
  6903. }
  6904. int sendInstallCertificateConfirmation(char *uuid)
  6905. {
  6906. mtrace();
  6907. int result = PASS;
  6908. char message[4096]={0};
  6909. json_object *InstallCertificate = json_object_new_object();
  6910. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6911. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6912. sprintf(message,"[%d,\"%s\",%s]"
  6913. ,MESSAGE_TYPE_CALLRESULT
  6914. ,uuid
  6915. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6916. json_object_put(InstallCertificate);
  6917. LWS_Send(message);
  6918. return result;
  6919. }
  6920. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6921. {
  6922. mtrace();
  6923. int result = PASS;
  6924. char message[4096]={0};
  6925. json_object *SignedUpdateFirmware = json_object_new_object();
  6926. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6927. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6928. sprintf(message,"[%d,\"%s\",%s]"
  6929. ,MESSAGE_TYPE_CALLRESULT
  6930. ,uuid
  6931. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6932. json_object_put(SignedUpdateFirmware);
  6933. LWS_Send(message);
  6934. return result;
  6935. }
  6936. int sendUnknownConfirmation(char *uuid)
  6937. {
  6938. mtrace();
  6939. int result = PASS;
  6940. char message[256]={0};
  6941. DEBUG_INFO("sendUnknownConfirmation...\n");
  6942. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6943. LWS_Send(message);
  6944. return result;
  6945. }
  6946. //==========================================
  6947. // Handle server request routine Start
  6948. //==========================================
  6949. int handleCancelReservationRequest(char *uuid, char *payload)
  6950. {
  6951. mtrace();
  6952. int result = FAIL;
  6953. int gunNO = 0;
  6954. int reservationIdInt = -1;
  6955. char comfirmstr[20];
  6956. DEBUG_INFO("handleCancelReservationRequest...\n");
  6957. json_object *CancelReservation;
  6958. CancelReservation = json_tokener_parse(payload);
  6959. if(!is_error(CancelReservation))
  6960. {
  6961. // Required data
  6962. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6963. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6964. }
  6965. json_object_put(CancelReservation);
  6966. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6967. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6968. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6969. if(reservationIdInt != -1)
  6970. {
  6971. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6972. //check Transaction active
  6973. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6975. {
  6976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6977. {
  6978. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6979. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6980. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6981. {
  6982. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6983. }
  6984. else
  6985. {
  6986. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6987. }
  6988. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6989. goto end;
  6990. }
  6991. }
  6992. for (int index = 0; index < CCS_QUANTITY; index++)
  6993. {
  6994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6995. {
  6996. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6997. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6998. if(gunType[2] == GUN_TYPE_CCS)
  6999. {
  7000. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7001. }
  7002. else
  7003. {
  7004. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7005. }
  7006. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7007. goto end;
  7008. }
  7009. }
  7010. for (int index = 0; index < GB_QUANTITY; index++)
  7011. {
  7012. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7013. {
  7014. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7015. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7016. if(gunType[2] == GUN_TYPE_GBT)
  7017. {
  7018. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7019. }
  7020. else
  7021. {
  7022. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7023. }
  7024. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7025. goto end;
  7026. }
  7027. }
  7028. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7029. {
  7030. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7031. {
  7032. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7033. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7034. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7035. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7036. goto end;
  7037. }
  7038. }
  7039. for (int index = 0; index < AC_QUANTITY; index++)
  7040. {
  7041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7042. {
  7043. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7044. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7046. {
  7047. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7048. }
  7049. else
  7050. {
  7051. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7052. }
  7053. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7054. goto end;
  7055. }
  7056. }
  7057. }
  7058. //The reservationId does NOT match the reservationId
  7059. sendCancelReservationConfirmation(uuid, comfirmstr);
  7060. end:
  7061. // Fill in ocpp packet uuid
  7062. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7063. return result;
  7064. }
  7065. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7066. {
  7067. mtrace();
  7068. int result = FAIL;
  7069. int gunIndex = 0;
  7070. char typeStr[16]={0};
  7071. char comfirmstr[20];
  7072. int specificId = FALSE;
  7073. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7074. json_object *ChangeAvailability;
  7075. ChangeAvailability = json_tokener_parse(payload);
  7076. if(!is_error(ChangeAvailability))
  7077. {
  7078. // Required data
  7079. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7080. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7081. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7082. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7083. }
  7084. json_object_put(ChangeAvailability);
  7085. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7086. {
  7087. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7088. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7089. }
  7090. else if(gunIndex == 0)
  7091. {
  7092. for(int i=0; i < gunTotalNumber; i++)
  7093. {
  7094. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7095. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7096. }
  7097. }
  7098. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7099. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7100. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7101. {
  7102. specificId = TRUE;
  7103. }
  7104. if(specificId == FALSE)
  7105. goto end;
  7106. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7107. {
  7108. //----------------------gunIndex is 0 ------------------------------------------------//
  7109. if(gunIndex == 0)
  7110. {
  7111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7112. {
  7113. for(int i=0; i < gunTotalNumber; i++)
  7114. {
  7115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7116. {
  7117. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7118. {
  7119. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7120. {
  7121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7122. goto end;
  7123. }
  7124. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7125. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7126. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7127. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7128. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7129. {
  7130. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7131. goto end;
  7132. }
  7133. }
  7134. }//END FOR CHAdeMO_QUANTITY
  7135. for (int index = 0; index < CCS_QUANTITY; index++)
  7136. {
  7137. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7138. {
  7139. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7140. {
  7141. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7142. goto end;
  7143. }
  7144. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7145. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7146. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7147. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7148. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7149. {
  7150. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7151. goto end;
  7152. }
  7153. }
  7154. }//END FOR CCS_QUANTITY
  7155. for (int index = 0; index < GB_QUANTITY; index++)
  7156. {
  7157. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7158. {
  7159. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7160. {
  7161. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7162. goto end;
  7163. }
  7164. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7165. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7166. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7167. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7168. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7169. {
  7170. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7171. goto end;
  7172. }
  7173. }
  7174. }// END FOR GB_QUANTITY
  7175. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7176. {
  7177. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7178. {
  7179. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7180. {
  7181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7182. goto end;
  7183. }
  7184. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7185. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7186. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7187. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7188. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7189. {
  7190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7191. goto end;
  7192. }
  7193. }
  7194. }// END FOR GENERAL_GUN_QUANTITY
  7195. for (int index = 0; index < AC_QUANTITY; index++)
  7196. {
  7197. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7198. {
  7199. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7200. {
  7201. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7202. goto end;
  7203. }
  7204. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7205. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7206. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7207. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7208. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7209. {
  7210. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7211. goto end;
  7212. }
  7213. }
  7214. }//END FOR AC_QUANTITY
  7215. }// END FOR gunTotalNumber
  7216. }
  7217. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7218. {
  7219. for(int i=0; i < gunTotalNumber; i++)
  7220. {
  7221. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7222. {
  7223. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7224. goto end;
  7225. }
  7226. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7227. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7228. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7229. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7230. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7231. {
  7232. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7233. goto end;
  7234. }
  7235. }
  7236. }
  7237. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7238. goto end;
  7239. }
  7240. //----------------------gunIndex is not 0 ------------------------------------------------//
  7241. //check Transaction active
  7242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7243. {
  7244. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7245. {
  7246. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7247. {
  7248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7249. goto end;
  7250. }
  7251. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7252. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7253. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7254. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7255. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7256. {
  7257. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7258. goto end;
  7259. }
  7260. else
  7261. {
  7262. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7263. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7264. goto end;
  7265. }
  7266. }
  7267. }//END FOR CHAdeMO_QUANTITY
  7268. for (int index = 0; index < CCS_QUANTITY; index++)
  7269. {
  7270. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7271. {
  7272. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7273. {
  7274. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7275. goto end;
  7276. }
  7277. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7278. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7279. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7280. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7281. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7282. {
  7283. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7284. goto end;
  7285. }
  7286. else
  7287. {
  7288. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7289. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7290. goto end;
  7291. }
  7292. }
  7293. }//END FOR CCS_QUANTITY
  7294. for (int index = 0; index < GB_QUANTITY; index++)
  7295. {
  7296. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7297. {
  7298. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7299. {
  7300. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7301. goto end;
  7302. }
  7303. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7304. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7305. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7306. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7307. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7308. {
  7309. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7310. goto end;
  7311. }
  7312. else
  7313. {
  7314. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7315. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7316. goto end;
  7317. }
  7318. }
  7319. }// END FOR GB_QUANTITY
  7320. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7321. {
  7322. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7323. {
  7324. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7325. {
  7326. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7327. goto end;
  7328. }
  7329. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7330. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7331. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7332. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7333. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7334. {
  7335. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7336. goto end;
  7337. }
  7338. else
  7339. {
  7340. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7341. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7342. goto end;
  7343. }
  7344. }
  7345. }// END FOR GENERAL_GUN_QUANTITY
  7346. for (int index = 0; index < AC_QUANTITY; index++)
  7347. {
  7348. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7349. {
  7350. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7351. {
  7352. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7353. goto end;
  7354. }
  7355. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7356. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7357. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7358. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7359. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7360. {
  7361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7362. goto end;
  7363. }
  7364. else
  7365. {
  7366. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7367. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7368. goto end;
  7369. }
  7370. }
  7371. }//END FOR AC_QUANTITY
  7372. }//END FOR AvailabilityTypeStr[Inoperative]
  7373. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7374. {
  7375. //----------------------gunIndex is 0 ------------------------------------------------//
  7376. if(gunIndex == 0)
  7377. {
  7378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7379. {
  7380. for(int i=0; i < gunTotalNumber; i++)
  7381. {
  7382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7383. {
  7384. 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
  7385. {
  7386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7387. goto end;
  7388. }
  7389. }//END FOR CHAdeMO_QUANTITY
  7390. for (int index = 0; index < CCS_QUANTITY; index++)
  7391. {
  7392. 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
  7393. {
  7394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7395. goto end;
  7396. }
  7397. }//END FOR CCS_QUANTITY
  7398. for (int index = 0; index < GB_QUANTITY; index++)
  7399. {
  7400. 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
  7401. {
  7402. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7403. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7404. goto end;
  7405. }
  7406. }// END FOR GB_QUANTITY
  7407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7408. {
  7409. 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
  7410. {
  7411. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7413. goto end;
  7414. }
  7415. }// END FOR GENERAL_GUN_QUANTITY
  7416. for (int index = 0; index < AC_QUANTITY; index++)
  7417. {
  7418. 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
  7419. {
  7420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7421. goto end;
  7422. }
  7423. }//END FOR CHAdeMO_QUANTITY
  7424. }// END FOR gunTotalNumber
  7425. }
  7426. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7427. {
  7428. for(int i=0; i < gunTotalNumber; i++)
  7429. {
  7430. for (int index = 0; index < AC_QUANTITY; index++)
  7431. {
  7432. 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
  7433. {
  7434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7435. goto end;
  7436. }
  7437. }//END FOR CHAdeMO_QUANTITY
  7438. } // END FOR gunTotalNumber
  7439. }
  7440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7441. goto end;
  7442. }
  7443. //----------------------gunIndex is not 0 ------------------------------------------------//
  7444. //check Transaction active
  7445. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7446. {
  7447. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7448. {
  7449. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7450. goto end;
  7451. }
  7452. }//END FOR CHAdeMO_QUANTITY
  7453. for (int index = 0; index < CCS_QUANTITY; index++)
  7454. {
  7455. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7456. {
  7457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7458. goto end;
  7459. }
  7460. }//END FOR CCS_QUANTITY
  7461. for (int index = 0; index < GB_QUANTITY; index++)
  7462. {
  7463. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7464. {
  7465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7466. goto end;
  7467. }
  7468. }// END FOR GB_QUANTITY
  7469. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7470. {
  7471. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7472. {
  7473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7474. goto end;
  7475. }
  7476. }// END FOR GENERAL_GUN_QUANTITY
  7477. for (int index = 0; index < AC_QUANTITY; index++)
  7478. {
  7479. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7480. {
  7481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7482. goto end;
  7483. }
  7484. }//END FOR AC_QUANTITY
  7485. }//END FOR AvailabilityTypeStr[Operative]
  7486. end:
  7487. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7488. {
  7489. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7490. }
  7491. else
  7492. {
  7493. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7494. }
  7495. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7496. {
  7497. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7498. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7499. }
  7500. else if(gunIndex == 0)
  7501. {
  7502. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7503. {
  7504. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7505. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7506. }
  7507. }
  7508. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7509. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7510. return result;
  7511. }
  7512. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7513. {
  7514. mtrace();
  7515. int result = FAIL;
  7516. char keystr[40]={0};
  7517. char valuestr[256]={0};
  7518. char comfirmstr[20]={0};
  7519. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7520. json_object *ChangeConfiguration;
  7521. ChangeConfiguration = json_tokener_parse(payload);
  7522. if(!is_error(ChangeConfiguration))
  7523. {
  7524. // Required data
  7525. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7526. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7527. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7528. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7529. }
  7530. json_object_put(ChangeConfiguration);
  7531. if((uuid==NULL) || (payload ==NULL) )
  7532. {
  7533. DEBUG_ERROR("Payload is null\n");
  7534. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7535. }
  7536. else
  7537. {
  7538. int status = setKeyValue(keystr, valuestr);
  7539. switch(status)
  7540. {
  7541. case ConfigurationStatus_Accepted:
  7542. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7543. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7544. StoreConfigurationTable();
  7545. break;
  7546. case RebootRequired:
  7547. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7548. StoreConfigurationTable();
  7549. break;
  7550. case NotSupported:
  7551. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7552. break;
  7553. case ConfigurationStatus_Rejected:
  7554. default:
  7555. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7556. break;
  7557. }
  7558. }
  7559. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7560. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7561. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7562. {
  7563. ChageWebSocketPingInterval(atoi(valuestr));
  7564. }
  7565. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7566. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7567. {
  7568. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7569. SetOcppConnStatus(FALSE);
  7570. }
  7571. return result;
  7572. }
  7573. int handleClearCacheRequest(char *uuid, char *payload)
  7574. {
  7575. mtrace();
  7576. int result = FAIL;
  7577. char comfirmstr[20];
  7578. char rmFileCmd[100]={0};
  7579. struct stat stats;
  7580. DEBUG_INFO("handleClearCacheRequest...\n");
  7581. stat("/Storage/OCPP_PH", &stats);
  7582. // Check for directory existence
  7583. if (S_ISDIR(stats.st_mode) == 1)
  7584. {}
  7585. else
  7586. {
  7587. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7588. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  7589. system(rmFileCmd);
  7590. }
  7591. if(OCPP_cleanLocalCache())
  7592. {
  7593. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7594. }
  7595. else
  7596. {
  7597. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7598. }
  7599. sendClearCacheConfirmation(uuid, comfirmstr);
  7600. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7601. return result;
  7602. }
  7603. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7604. {
  7605. mtrace();
  7606. int result = FAIL;
  7607. int resultRename;
  7608. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7609. char chargingProfilePurposeStr[26]={0};
  7610. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7611. char tempchargingProfilePurposeStr[26]={0};
  7612. char str[100]={0};
  7613. char fname[200]={0};
  7614. char comfirmstr[20]={0};
  7615. char word[1600]={0};
  7616. int clearflag = FALSE;
  7617. int chargingProfileIdIsNULL = FALSE;
  7618. int connectorIsNULL = FALSE;
  7619. int chargingProfilePurposeIsNULL = FALSE;
  7620. int stackLevelIsNULL = FALSE;
  7621. //int GotoEnd = FALSE;
  7622. FILE *fptr1, *fptr2;
  7623. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  7624. int n_chargingProfile=0;
  7625. int isEmptyFile = FALSE;
  7626. char sLineWord[1600]={0};
  7627. char chargingProfiles[10][100]={0};
  7628. int ChargeProfileCount = 0;
  7629. int ch;
  7630. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7631. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7632. json_object *ClearChargingProfile;
  7633. ClearChargingProfile = json_tokener_parse(payload);
  7634. if(!is_error(ClearChargingProfile))
  7635. {
  7636. // Optional data
  7637. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7638. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7639. else
  7640. chargingProfileIdIsNULL = TRUE;
  7641. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7642. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7643. else
  7644. connectorIsNULL = TRUE;
  7645. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7646. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7647. else
  7648. chargingProfilePurposeIsNULL = TRUE;
  7649. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7650. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7651. else
  7652. stackLevelIsNULL = TRUE;
  7653. }
  7654. json_object_put(ClearChargingProfile);
  7655. if(connectorIsNULL == FALSE)
  7656. {
  7657. switch(connectorIdInt)
  7658. {
  7659. case 0:
  7660. if(chargingProfilePurposeIsNULL == TRUE)
  7661. {
  7662. int l = 0;
  7663. strcpy(fname, ChargePointMaxProfile_JSON);
  7664. if((access(fname,F_OK))!=-1)
  7665. {
  7666. strcpy(chargingProfiles[l], fname);
  7667. l = l + 1;
  7668. }
  7669. strcpy(fname, TxDefaultProfile_0_JSON);
  7670. if((access(fname,F_OK))!=-1)
  7671. {
  7672. strcpy(chargingProfiles[l], fname);
  7673. l = l + 1;
  7674. }
  7675. ChargeProfileCount = l;
  7676. }
  7677. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7678. {
  7679. strcpy(fname, ChargePointMaxProfile_JSON);
  7680. if((access(fname,F_OK))!=-1)
  7681. {
  7682. strcpy(chargingProfiles[0], fname);
  7683. ChargeProfileCount = 1;
  7684. }
  7685. }
  7686. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7687. {
  7688. strcpy(fname, TxDefaultProfile_0_JSON);
  7689. if((access(fname,F_OK))!=-1)
  7690. {
  7691. strcpy(chargingProfiles[0], fname);
  7692. ChargeProfileCount = 1;
  7693. }
  7694. }
  7695. break;
  7696. default:
  7697. if(chargingProfilePurposeIsNULL == TRUE)
  7698. {
  7699. int m = 0;
  7700. memset(fname, 0, ARRAY_SIZE(fname));
  7701. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7702. if((access(fname,F_OK))!=-1)
  7703. {
  7704. strcpy(chargingProfiles[m], fname);
  7705. m = m + 1;
  7706. }
  7707. memset(fname, 0, ARRAY_SIZE(fname));
  7708. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7709. if((access(fname,F_OK))!=-1)
  7710. {
  7711. strcpy(chargingProfiles[m], fname);
  7712. m = m + 1;
  7713. }
  7714. ChargeProfileCount = m;
  7715. }
  7716. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7717. {
  7718. //strcpy(fname, TxDefaultProfile_1_JSON);
  7719. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7720. if((access(fname,F_OK))!=-1)
  7721. {
  7722. strcpy(chargingProfiles[0], fname);
  7723. ChargeProfileCount = 1;
  7724. }
  7725. }
  7726. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7727. {
  7728. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7729. if((access(fname,F_OK))!=-1)
  7730. {
  7731. strcpy(chargingProfiles[0], fname);
  7732. ChargeProfileCount = 1;
  7733. }
  7734. //strcpy(fname, TxProfile_1_JSON);
  7735. }
  7736. //strcpy(fname, ChargePointMaxProfile_JSON );
  7737. break;
  7738. }
  7739. }
  7740. else // Check all Charging Profiles
  7741. {
  7742. int i = 0;
  7743. char fnametemp[200]={0};
  7744. ChargeProfileCount = 0;
  7745. //Check ChargePointMaxProfile.json exit
  7746. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7747. {
  7748. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7749. i = i + 1;
  7750. }
  7751. //Check TxDefaultProfile_0.json exit
  7752. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7753. {
  7754. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7755. i = i + 1;
  7756. }
  7757. //Check TxDefaultProfile_%d.json
  7758. for(int j=1; j <= gunTotalNumber; j++)
  7759. {
  7760. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7761. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7762. if((access(fnametemp,F_OK))!=-1)
  7763. {
  7764. strcpy(chargingProfiles[i], fnametemp);
  7765. i = i + 1;
  7766. }
  7767. }
  7768. //Check TxProfile_%d.json
  7769. for(int j=1; j <= gunTotalNumber; j++)
  7770. {
  7771. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7772. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7773. if((access(fnametemp,F_OK))!=-1)
  7774. {
  7775. strcpy(chargingProfiles[i], fnametemp);
  7776. i = i + 1;
  7777. }
  7778. }
  7779. ChargeProfileCount = i;
  7780. }// End connectorIsNULL is TRUE
  7781. if(ChargeProfileCount == 0)
  7782. {
  7783. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7784. goto end;
  7785. }
  7786. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7787. {
  7788. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7789. goto end;
  7790. }
  7791. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7792. {
  7793. memset(str, 0, ARRAY_SIZE(str));
  7794. // clear temp file
  7795. sprintf(str,"rm -f %s",temp);
  7796. system(str);
  7797. for(int k=0; k < ChargeProfileCount; k++)
  7798. {
  7799. memset(str, 0, ARRAY_SIZE(str));
  7800. //clear file in C
  7801. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7802. system(str);
  7803. }
  7804. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7805. goto end;
  7806. }
  7807. else if(connectorIsNULL == TRUE)
  7808. {
  7809. for(int k=0; k < ChargeProfileCount; k++)
  7810. {
  7811. fptr1 = fopen(chargingProfiles[k], "r");
  7812. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7813. //Check Charging Profile Count
  7814. while(fscanf(fptr1, "%s", word) != EOF)
  7815. {
  7816. //DEBUG_INFO("word=%s\n",word);
  7817. if(strstr(word, "chargingProfileId")!= NULL)
  7818. {
  7819. //DEBUG_INFO("test chargingProfileId \n");
  7820. n_chargingProfile = n_chargingProfile + 1;
  7821. //DEBUG_INFO("chargingProfileId Found\n");
  7822. }
  7823. }
  7824. rewind(fptr1);
  7825. //search Charging Profile Element
  7826. //int i= 0;
  7827. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7828. {
  7829. json_object *tmpProfilee;
  7830. tmpProfilee = json_tokener_parse(sLineWord);
  7831. if(!is_error(tmpProfilee))
  7832. {
  7833. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7834. {
  7835. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7836. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7837. }
  7838. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7839. {
  7840. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7841. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7842. }
  7843. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7844. {
  7845. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7846. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7847. }
  7848. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7849. {
  7850. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7851. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7852. }
  7853. }
  7854. json_object_put(tmpProfilee);
  7855. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7856. {
  7857. //------- not write to fptr2-------//
  7858. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7859. //clearflag = TRUE;
  7860. }
  7861. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7862. {
  7863. //------- not write to fptr2-------//
  7864. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7865. }
  7866. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7867. {
  7868. //------- not write to fptr2-------//
  7869. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7870. }
  7871. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7872. {
  7873. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7874. }
  7875. else
  7876. {
  7877. fprintf(fptr2, sLineWord);//writing data into file
  7878. }
  7879. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7880. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7881. if(clearflag == TRUE)
  7882. {
  7883. fclose(fptr1);
  7884. fclose(fptr2);
  7885. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7886. system(str);
  7887. // clear temp file
  7888. sprintf(str,"rm -f %s",temp);
  7889. system(str);
  7890. }
  7891. else
  7892. {
  7893. fclose(fptr1);
  7894. fclose(fptr2);
  7895. memset(str, 0, ARRAY_SIZE(str));
  7896. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7897. system(str);
  7898. resultRename = rename(temp, chargingProfiles[k]);
  7899. if(resultRename == 0)
  7900. {
  7901. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7902. }
  7903. else
  7904. {
  7905. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7906. }
  7907. if(comfirmstr[0]== 0)
  7908. {
  7909. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7910. }
  7911. //Check chargingProfile is empty file
  7912. /*------ Read the file ----------------*/
  7913. fptr1=fopen(chargingProfiles[k],"r");
  7914. ch=fgetc(fptr1);
  7915. rewind(fptr1);
  7916. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7917. if(ch!=EOF)
  7918. {
  7919. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7920. {
  7921. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7922. if(sLineWord[0]=='\0')
  7923. {
  7924. isEmptyFile = TRUE;
  7925. break;
  7926. }
  7927. else
  7928. {
  7929. isEmptyFile = FALSE;
  7930. break;
  7931. }
  7932. }
  7933. }
  7934. else
  7935. isEmptyFile = TRUE;
  7936. fclose(fptr1);
  7937. if(isEmptyFile == TRUE)
  7938. {
  7939. memset(str, 0, ARRAY_SIZE(str));
  7940. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7941. system(str);
  7942. }
  7943. }
  7944. }// End of while(int k=0; k < ChargePointCount; k++)
  7945. }
  7946. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7947. {
  7948. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7949. for(int k=0; k < ChargeProfileCount; k++)
  7950. {
  7951. fptr1 = fopen(chargingProfiles[k], "r");
  7952. fptr2 = fopen(temp, "w+");
  7953. //Check Charging Profile Count
  7954. while(fscanf(fptr1, "%s", word) != EOF)
  7955. {
  7956. //DEBUG_INFO("word=%s\n",word);
  7957. if(strstr(word, "chargingProfileId")!= NULL)
  7958. {
  7959. n_chargingProfile = n_chargingProfile + 1;
  7960. }
  7961. }
  7962. rewind(fptr1);
  7963. //search Charging Profile Element
  7964. //int i= 0;
  7965. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7966. {
  7967. json_object *tmpProfilee;
  7968. tmpProfilee = json_tokener_parse(sLineWord);
  7969. if(!is_error(tmpProfilee))
  7970. {
  7971. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7972. {
  7973. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7974. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7975. }
  7976. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7977. {
  7978. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7979. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7980. }
  7981. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7982. {
  7983. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7984. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7985. }
  7986. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7987. {
  7988. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7989. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7990. }
  7991. }
  7992. json_object_put(tmpProfilee);
  7993. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7994. {
  7995. //------- not write to fptr2-------//
  7996. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7997. //clearflag = TRUE;
  7998. }
  7999. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8000. {
  8001. //------- not write to fptr2-------//
  8002. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8003. }
  8004. else if(stackLevelIsNULL == TRUE)
  8005. {
  8006. //Clear Whole File
  8007. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8008. clearflag = TRUE;
  8009. break;
  8010. }
  8011. else
  8012. {
  8013. fprintf(fptr2, sLineWord);//writing data into file
  8014. }
  8015. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8016. }
  8017. if(clearflag == TRUE)
  8018. {
  8019. fclose(fptr1);
  8020. fclose(fptr2);
  8021. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8022. system(str);
  8023. // clear temp file
  8024. sprintf(str,"rm -f %s",temp);
  8025. system(str);
  8026. }
  8027. else
  8028. {
  8029. fclose(fptr1);
  8030. fclose(fptr2);
  8031. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8032. system(str);
  8033. resultRename = rename(temp, chargingProfiles[k]);
  8034. if(resultRename == 0)
  8035. {
  8036. DEBUG_INFO("File ChargingProfile renamed successfully");
  8037. }
  8038. else
  8039. {
  8040. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8041. }
  8042. if(comfirmstr[0]== 0)
  8043. {
  8044. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8045. }
  8046. //Check chargingProfile is empty file
  8047. /*------ Read the file ----------------*/
  8048. fptr1=fopen(chargingProfiles[k],"r");
  8049. ch=fgetc(fptr1);
  8050. rewind(fptr1);
  8051. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8052. if(ch!=EOF)
  8053. {
  8054. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8055. {
  8056. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8057. if(sLineWord[0]=='\0')
  8058. {
  8059. isEmptyFile = TRUE;
  8060. break;
  8061. }
  8062. else
  8063. {
  8064. isEmptyFile = FALSE;
  8065. break;
  8066. }
  8067. }
  8068. }
  8069. else
  8070. isEmptyFile = TRUE;
  8071. fclose(fptr1);
  8072. if(isEmptyFile == TRUE)
  8073. {
  8074. memset(str, 0, ARRAY_SIZE(str));
  8075. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8076. system(str);
  8077. }
  8078. /*------- End of reading ---------------*/
  8079. }
  8080. } // while(int k=0; k < ChargeProfileCount; k++)
  8081. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8082. end:
  8083. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8084. {
  8085. if(connectorIdInt == 0)
  8086. {
  8087. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8088. {
  8089. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8090. }
  8091. }
  8092. else
  8093. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8094. }
  8095. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8096. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8097. return result;
  8098. }
  8099. void createFirmwareVersionByDataTransfer(void)
  8100. {
  8101. json_object *FirmwareDataTransfer = json_object_new_object();
  8102. // AC & DC model
  8103. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8104. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8105. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8106. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8107. // DC model
  8108. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8109. {
  8110. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8111. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8112. (gunType[3] != GUN_TYPE_UNKNOWN))
  8113. {
  8114. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8115. }
  8116. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8117. {
  8118. // DS DM DW
  8119. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8120. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8121. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8122. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8123. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8124. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8125. }
  8126. else
  8127. {
  8128. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8129. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8130. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8131. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8132. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8133. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8134. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8135. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8136. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8137. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8138. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8139. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8140. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8141. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8142. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8143. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8144. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8145. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8146. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8147. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8148. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8149. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8150. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8151. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8152. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8153. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8154. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8155. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8156. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8157. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8158. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8159. }
  8160. }
  8161. // 4G model
  8162. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8163. {
  8164. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8165. }
  8166. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8167. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8168. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8169. json_object_put(FirmwareDataTransfer);
  8170. }
  8171. int handleDataTransferRequest(char *uuid, char *payload)
  8172. {
  8173. mtrace();
  8174. json_object *response = json_object_new_object();
  8175. int result = FAIL;
  8176. char tempvendorId[255]={0};
  8177. char tempmessageId[50]={0};
  8178. char tempdata[512]={0};
  8179. char message[2048]={0};
  8180. DEBUG_INFO("handleDataTransferRequest...\n");
  8181. if((uuid != NULL) && (payload != NULL))
  8182. {
  8183. json_object *DataTransfer;
  8184. DataTransfer = json_tokener_parse(payload);
  8185. if(!is_error(DataTransfer))
  8186. {
  8187. // Required data
  8188. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8189. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8190. // Optional data
  8191. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8192. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8193. if(json_object_object_get(DataTransfer, "data") != NULL)
  8194. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8195. result = PASS;
  8196. }
  8197. json_object_put(DataTransfer);
  8198. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8199. {
  8200. // Send all moudle firmware version on EVSE
  8201. createFirmwareVersionByDataTransfer();
  8202. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8203. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  8204. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8205. json_object_put(response);
  8206. }
  8207. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8208. {
  8209. system("/usr/bin/run_tmate_restart.sh &");
  8210. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8211. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8212. json_object_put(response);
  8213. }
  8214. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8215. {
  8216. json_object *data;
  8217. data = json_tokener_parse(tempdata);
  8218. if(!is_error(data))
  8219. {
  8220. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8221. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8222. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8223. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8224. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8225. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8226. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8227. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8228. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8229. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8230. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8231. }
  8232. else
  8233. {
  8234. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8235. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8236. }
  8237. json_object_put(data);
  8238. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8239. json_object_put(response);
  8240. }
  8241. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8242. {
  8243. json_object *data;
  8244. data = json_tokener_parse(tempdata);
  8245. if(!is_error(data))
  8246. {
  8247. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8248. if(json_object_object_get(data, "idToken") != NULL)
  8249. {
  8250. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8251. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8252. }
  8253. if(json_object_object_get(data, "price") != NULL)
  8254. {
  8255. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8256. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8257. }
  8258. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8259. }
  8260. else
  8261. {
  8262. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8263. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8264. }
  8265. json_object_put(data);
  8266. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8267. json_object_put(response);
  8268. }
  8269. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8270. {
  8271. json_object *data;
  8272. data = json_tokener_parse(tempdata);
  8273. if(!is_error(data))
  8274. {
  8275. if(json_object_object_get(data, "txId") != NULL)
  8276. {
  8277. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8278. for(int idx = 0;idx<gunTotalNumber;idx++)
  8279. {
  8280. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8281. {
  8282. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8283. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8284. if(json_object_object_get(data, "description") != NULL)
  8285. {
  8286. // California pricing V1.0
  8287. DEBUG_INFO("California pricing V1.0\n");
  8288. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8289. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8290. }
  8291. else
  8292. {
  8293. // California pricing V1.1
  8294. DEBUG_INFO("California pricing V1.1\n");
  8295. if(json_object_object_get(data, "timestamp") != NULL)
  8296. {
  8297. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8298. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8299. }
  8300. if(json_object_object_get(data, "meterValue") != NULL)
  8301. {
  8302. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8303. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8304. }
  8305. if(json_object_object_get(data, "cost") != NULL)
  8306. {
  8307. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8308. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8309. }
  8310. if(json_object_object_get(data, "state") != NULL)
  8311. {
  8312. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8313. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8314. }
  8315. if(json_object_object_get(data, "chargingPrice") != NULL)
  8316. {
  8317. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8318. {
  8319. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8320. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8321. }
  8322. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8323. {
  8324. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8325. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8326. }
  8327. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8328. {
  8329. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8330. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8331. }
  8332. }
  8333. if(json_object_object_get(data, "idlePrice") != NULL)
  8334. {
  8335. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8336. {
  8337. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8338. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8339. }
  8340. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8341. {
  8342. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8343. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8344. }
  8345. }
  8346. if(json_object_object_get(data, "nextPeriod") != NULL)
  8347. {
  8348. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8349. {
  8350. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8351. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8352. }
  8353. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8354. {
  8355. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8356. {
  8357. 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")));
  8358. 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"));
  8359. }
  8360. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8361. {
  8362. 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")));
  8363. 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"));
  8364. }
  8365. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8366. {
  8367. 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")));
  8368. 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"));
  8369. }
  8370. }
  8371. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8372. {
  8373. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8374. {
  8375. 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")));
  8376. 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"));
  8377. }
  8378. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8379. {
  8380. 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")));
  8381. 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"));
  8382. }
  8383. }
  8384. }
  8385. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8386. {
  8387. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8388. {
  8389. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8390. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8391. }
  8392. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8393. {
  8394. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8395. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8396. }
  8397. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8398. {
  8399. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8400. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8401. }
  8402. }
  8403. }
  8404. }
  8405. }
  8406. }
  8407. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8408. }
  8409. else
  8410. {
  8411. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8412. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8413. }
  8414. json_object_put(data);
  8415. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8416. json_object_put(response);
  8417. }
  8418. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8419. {
  8420. json_object *data;
  8421. data = json_tokener_parse(tempdata);
  8422. if(!is_error(data))
  8423. {
  8424. if(json_object_object_get(data, "txId") != NULL)
  8425. {
  8426. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8427. for(int idx = 0;idx<gunTotalNumber;idx++)
  8428. {
  8429. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8430. {
  8431. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8432. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8433. if(json_object_object_get(data, "description") != NULL)
  8434. {
  8435. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8436. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8437. }
  8438. }
  8439. }
  8440. }
  8441. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8442. }
  8443. else
  8444. {
  8445. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8446. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8447. }
  8448. json_object_put(data);
  8449. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8450. json_object_put(response);
  8451. }
  8452. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8453. {
  8454. json_object *data;
  8455. data = json_tokener_parse(tempdata);
  8456. if(!is_error(data))
  8457. {
  8458. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8459. if(json_object_object_get(data, "Content_Type") != NULL)
  8460. {
  8461. 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))
  8462. {
  8463. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8464. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8465. {
  8466. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8467. }
  8468. }
  8469. else
  8470. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8471. }
  8472. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8473. }
  8474. else
  8475. {
  8476. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8477. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8478. }
  8479. json_object_put(data);
  8480. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8481. json_object_put(response);
  8482. }
  8483. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8484. {
  8485. json_object *data;
  8486. data = json_tokener_parse(tempdata);
  8487. if(!is_error(data))
  8488. {
  8489. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8490. if(json_object_object_get(data, "Page_Index") != NULL)
  8491. {
  8492. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8493. }
  8494. if(json_object_object_get(data, "Duration") != NULL)
  8495. {
  8496. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8497. }
  8498. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8499. }
  8500. else
  8501. {
  8502. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8503. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8504. }
  8505. json_object_put(data);
  8506. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8507. json_object_put(response);
  8508. }
  8509. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8510. {
  8511. json_object *data;
  8512. data = json_tokener_parse(tempdata);
  8513. if(!is_error(data))
  8514. {
  8515. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8516. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8517. {
  8518. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8519. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8520. else
  8521. {
  8522. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8523. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8524. }
  8525. }
  8526. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8527. {
  8528. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8529. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8530. else
  8531. {
  8532. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8533. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8534. }
  8535. }
  8536. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8537. {
  8538. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8539. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8540. else
  8541. {
  8542. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8543. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8544. }
  8545. }
  8546. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8547. {
  8548. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8549. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8550. else
  8551. {
  8552. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8553. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8554. }
  8555. }
  8556. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8557. {
  8558. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8559. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8560. else
  8561. {
  8562. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8563. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8564. }
  8565. }
  8566. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8567. {
  8568. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8569. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8570. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8571. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8572. else
  8573. {
  8574. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8575. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8576. }
  8577. }
  8578. if(json_object_object_get(data, "isAuthentication") != NULL)
  8579. {
  8580. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8581. {
  8582. case 0:
  8583. case 1:
  8584. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8585. break;
  8586. default:
  8587. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8588. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8589. break;
  8590. }
  8591. }
  8592. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8593. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8594. }
  8595. else
  8596. {
  8597. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8598. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8599. }
  8600. json_object_put(data);
  8601. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8602. json_object_put(response);
  8603. }
  8604. else
  8605. {
  8606. // Can not find valid message id
  8607. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8608. }
  8609. }
  8610. else
  8611. {
  8612. // Payload is null
  8613. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8614. }
  8615. LWS_Send(message);
  8616. return result;
  8617. }
  8618. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8619. {
  8620. mtrace();
  8621. int result = FAIL;
  8622. int connectorIdInt, durationInt;
  8623. char chargingRateUnitStr[4]={0};
  8624. char comfirmstr[20];
  8625. int confirmPeriods = 0;
  8626. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8627. json_object *GetCompositeSchedule;
  8628. GetCompositeSchedule = json_tokener_parse(payload);
  8629. if(!is_error(GetCompositeSchedule))
  8630. {
  8631. // Required data
  8632. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8633. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8634. else
  8635. connectorIdInt = -1;
  8636. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8637. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8638. else
  8639. durationInt = 86400;
  8640. // Optional data
  8641. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8642. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8643. }
  8644. json_object_put(GetCompositeSchedule);
  8645. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8646. if((connectorIdInt == 0) ||
  8647. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8648. {
  8649. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8650. struct StructChargingProfile tmpProfile[1];
  8651. if(strstr(chargingRateUnitStr, "W") != NULL)
  8652. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8653. else
  8654. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8655. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8656. {
  8657. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8658. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8659. }
  8660. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8661. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8662. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8663. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8664. {
  8665. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8666. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8667. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8668. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8669. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8670. {
  8671. confirmPeriods = idx;
  8672. break;
  8673. }
  8674. }
  8675. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8676. {
  8677. confirmPeriods += 1;
  8678. }
  8679. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8680. }
  8681. else
  8682. {
  8683. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8684. }
  8685. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8686. return result;
  8687. }
  8688. int handleGetConfigurationRequest(char *uuid, char *payload)
  8689. {
  8690. mtrace();
  8691. int result = FAIL;
  8692. int MaxKeySupported = 0;
  8693. int n_keys = 0;
  8694. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8695. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8696. json_object *GetConfiguration;
  8697. GetConfiguration = json_tokener_parse(payload);
  8698. if(!is_error(GetConfiguration))
  8699. {
  8700. // Optional data
  8701. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8702. {
  8703. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8704. {
  8705. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8706. n_keys = idx + 1;
  8707. }
  8708. }
  8709. }
  8710. json_object_put(GetConfiguration);
  8711. UnknownKeynum = 0;
  8712. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8713. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8714. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8715. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8716. if(n_keys != 0)
  8717. {
  8718. for(int i=0;i<n_keys;i++)
  8719. {
  8720. getKeyValue(requestKey[i]);
  8721. }
  8722. }
  8723. else
  8724. {
  8725. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8726. getKeyValue("");
  8727. }
  8728. processUnkownKey();
  8729. sendGetConfigurationConfirmation(uuid);
  8730. return result;
  8731. }
  8732. static char fnamePlusPath[100]={0};
  8733. static char fnamePWithNoPath[60]={0};
  8734. void checkUploadLog(void)
  8735. {
  8736. FILE *fp;
  8737. /* Open the command for reading. */
  8738. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8739. if (fp == NULL) {
  8740. DEBUG_WARN("Failed to run command\n" );
  8741. exit(1);
  8742. }
  8743. int ftppathlen = 0;
  8744. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8745. int i = 0;
  8746. /* Read the output a line at a time - output it. */
  8747. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8748. if(i==0)
  8749. {
  8750. ftppathlen = strlen(fnamePlusPath);
  8751. DEBUG_INFO("%s\n", fnamePlusPath);
  8752. fnamePlusPath[ftppathlen]='\0';
  8753. break;
  8754. }
  8755. i= i+1;
  8756. }
  8757. /* close */
  8758. pclose(fp);
  8759. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8760. {
  8761. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8762. {
  8763. fnamePlusPath[k]='\0';
  8764. }
  8765. }
  8766. i=1;
  8767. //char fname[60]={0};
  8768. while(i < ftppathlen)
  8769. {
  8770. int len=ftppathlen-i;
  8771. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8772. {
  8773. DEBUG_INFO("compare '/' all right\n");
  8774. break;
  8775. }
  8776. i=i+1;
  8777. }
  8778. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8779. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8780. fnamePWithNoPath[i+1] = '\0';
  8781. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8782. {
  8783. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8784. {
  8785. fnamePWithNoPath[j]='\0';
  8786. }
  8787. }
  8788. FILE* fp1 = fopen(fnamePlusPath, "r");
  8789. if (fp1)
  8790. {
  8791. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8792. // file exists
  8793. fclose(fp1);
  8794. }
  8795. else
  8796. {
  8797. // file doesn't exist
  8798. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8799. }
  8800. }
  8801. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8802. {
  8803. mtrace();
  8804. int result = FAIL;
  8805. time_t CurrentTime;
  8806. struct tm *tm;
  8807. pthread_t th_Status;
  8808. CurrentTime = time(NULL);
  8809. tm = localtime(&CurrentTime);
  8810. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  8811. 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);
  8812. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8813. if(!interLock.isGetDiagnosticGoing)
  8814. {
  8815. interLock.isGetDiagnosticGoing = 1;
  8816. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8817. sleep(1);
  8818. }
  8819. else
  8820. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  8821. return result;
  8822. }
  8823. void* GetDiagnosticsProcess(void* data)
  8824. {
  8825. pthread_detach(pthread_self());
  8826. mtrace();
  8827. int retriesInt=0, retryIntervalInt=0;
  8828. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8829. 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};
  8830. int port=0;
  8831. int isSuccess = FALSE;
  8832. char ftpbuf[200]={0};
  8833. char cmdBuf[2048];
  8834. struct tm *tmNow;
  8835. time_t CurrentTime;
  8836. struct tm tmStart;
  8837. struct tm tmStop;
  8838. CurrentTime = time(NULL);
  8839. tmNow=localtime(&CurrentTime);
  8840. uint16_t targetYear, targetMonth;
  8841. json_object *GetDiagnostics;
  8842. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8843. GetDiagnostics = json_tokener_parse(data);
  8844. if(!is_error(GetDiagnostics))
  8845. {
  8846. // Required data
  8847. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8848. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8849. // Optional data
  8850. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8851. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8852. else
  8853. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8854. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8855. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8856. else
  8857. retryIntervalInt = 30;
  8858. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8859. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8860. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8861. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8862. }
  8863. json_object_put(GetDiagnostics);
  8864. // Pack log to compress file
  8865. 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) &&
  8866. (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))
  8867. {
  8868. // Pack system log
  8869. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8870. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8871. targetYear = tmStart.tm_year;
  8872. targetMonth = tmStart.tm_mon;
  8873. do
  8874. {
  8875. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8876. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8877. if(targetMonth+1>=13)
  8878. {
  8879. targetYear += 1;
  8880. targetMonth = 1;
  8881. }
  8882. else
  8883. {
  8884. targetMonth += 1;
  8885. }
  8886. }while((targetYear < (tmNow->tm_year+1900)) ||
  8887. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8888. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8889. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8890. system(cmdBuf);
  8891. // Pack charging & event log
  8892. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8893. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8894. targetYear = tmStart.tm_year;
  8895. targetMonth = tmStart.tm_mon;
  8896. do
  8897. {
  8898. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8899. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8900. if(targetMonth+1>=13)
  8901. {
  8902. targetYear += 1;
  8903. targetMonth = 1;
  8904. }
  8905. else
  8906. {
  8907. targetMonth += 1;
  8908. }
  8909. }while((targetYear < (tmNow->tm_year+1900)) ||
  8910. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8911. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8912. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8913. system(cmdBuf);
  8914. // Combine log file
  8915. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8916. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8917. }
  8918. else
  8919. {
  8920. system("exec /root/logPackTools 'log' 6");
  8921. }
  8922. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8923. system(cmdBuf);
  8924. checkUploadLog();
  8925. //****************location*******************/
  8926. if(strcmp(locationstr,"")==0)
  8927. {
  8928. DEBUG_INFO("location is <Empty>!\n");
  8929. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8930. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8931. goto end;
  8932. }
  8933. memset(protocol, 0, ARRAY_SIZE(protocol));
  8934. memset(user, 0, ARRAY_SIZE(user) );
  8935. memset(password, 0, ARRAY_SIZE(password));
  8936. memset(host, 0, ARRAY_SIZE(host));
  8937. memset(path, 0, ARRAY_SIZE(path));
  8938. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8939. memset(host1, 0, ARRAY_SIZE(host1));
  8940. memset(path1, 0, ARRAY_SIZE(path1));
  8941. /*location: ftp://user:password@host:port/path*/
  8942. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8943. if((access(fnamePlusPath,F_OK))!=-1)
  8944. {
  8945. DEBUG_INFO("fnamePlusPath exist.\n");
  8946. }
  8947. else
  8948. {
  8949. DEBUG_INFO("fnamePlusPath not exist!\n");
  8950. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8951. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8952. goto end;
  8953. }
  8954. if(strchr(locationstr,'@')==NULL)
  8955. {
  8956. sscanf(locationstr,
  8957. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8958. protocol, host, &port, path);
  8959. strcpy(user,"anonymous");
  8960. strcpy(password,"");
  8961. }
  8962. else
  8963. {
  8964. //DEBUG_INFO("pch=%s\n", pch);
  8965. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8966. protocol, user, password, host, &port, path);
  8967. }
  8968. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8969. {
  8970. DEBUG_INFO("protocol is not ftp/http ! \n");
  8971. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8972. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8973. goto end;
  8974. }
  8975. if(strncmp(locationstr,"http", 4) == 0)
  8976. {
  8977. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8978. sprintf(ftppath,"/%s", path);
  8979. do
  8980. {
  8981. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8982. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8983. sleep(3);
  8984. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8985. if(!isSuccess)
  8986. {
  8987. DEBUG_INFO("Diagnostics fail.\n");
  8988. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8989. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8990. sleep(retryIntervalInt);
  8991. }
  8992. else
  8993. {
  8994. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8995. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8996. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8997. }
  8998. retriesInt--;
  8999. }while((isSuccess == 0)&&(retriesInt >= 0));
  9000. }
  9001. else
  9002. {
  9003. sscanf(host,"%[^/]%s",host1, path1);
  9004. if(strlen(path) > 0)
  9005. sprintf(ftppath,"/%s", path);
  9006. else
  9007. sprintf(ftppath,"/%s", path1);
  9008. int ftppathlen=strlen(ftppath);
  9009. int i=1;
  9010. char filenametemp[50];
  9011. while(i < ftppathlen)
  9012. {
  9013. int len=ftppathlen-i;
  9014. if(ftppath[len]== 47) // '/' ascll code: 47
  9015. {
  9016. DEBUG_INFO("find '/' all right\n");
  9017. break;
  9018. }
  9019. i=i+1;
  9020. }
  9021. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9022. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9023. filenametemp[i+1] = 0;
  9024. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9025. if(port == 0)
  9026. port = 21;
  9027. do
  9028. {
  9029. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9030. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9031. sleep(3);
  9032. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9033. if(!isSuccess)
  9034. {
  9035. DEBUG_INFO("Diagnostics fail.\n");
  9036. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9037. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9038. sleep(retryIntervalInt);
  9039. }
  9040. else
  9041. {
  9042. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9043. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9044. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9045. }
  9046. retriesInt--;
  9047. }while((!isSuccess)&&(retriesInt >= 0));
  9048. }
  9049. end:
  9050. system("rm -f /mnt/*");
  9051. sleep(5);
  9052. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9053. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9054. interLock.isGetDiagnosticGoing = 0;
  9055. pthread_exit(NULL);
  9056. }
  9057. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9058. {
  9059. mtrace();
  9060. int result = FAIL;
  9061. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9062. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9063. {
  9064. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9065. locallistVersion = -1;
  9066. }
  9067. else
  9068. {
  9069. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9070. OCPP_getListVerion();
  9071. }
  9072. //from db.OCPP_getListVerion
  9073. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9074. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9075. sendGetLocalListVersionConfirmation(uuid,"");
  9076. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9077. return result;
  9078. }
  9079. int handleRemoteStartRequest(char *uuid, char *payload)
  9080. {
  9081. mtrace();
  9082. int result = FAIL;
  9083. int connectorIdInt=-1;
  9084. int tempIndex = 0;
  9085. int connectorIdIsNULL, chargingProfileIsNULL;
  9086. char comfirmstr[20]={0};
  9087. char cmdBuf[512];
  9088. json_object *RemoteStartTransaction;
  9089. FILE *fp;
  9090. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9091. if(server_pending == TRUE)
  9092. {
  9093. return 0;
  9094. }
  9095. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9096. RemoteStartTransaction = json_tokener_parse(payload);
  9097. if(!is_error(RemoteStartTransaction))
  9098. {
  9099. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9100. {
  9101. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9102. }
  9103. else
  9104. {
  9105. connectorIdIsNULL = TRUE;
  9106. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9107. {
  9108. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9109. {
  9110. connectorIdIsNULL = FALSE;
  9111. connectorIdInt = (gun_index+1);
  9112. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9113. break;
  9114. }
  9115. }
  9116. }
  9117. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9118. {
  9119. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9120. // Required data
  9121. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9122. // Optional data
  9123. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9124. {
  9125. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9126. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9127. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9128. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9129. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9130. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9131. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9132. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9133. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9134. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9135. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9136. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9137. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9138. {
  9139. 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")));
  9140. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9141. 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"));
  9142. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9143. 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"));
  9144. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9145. 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")));
  9146. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9147. {
  9148. 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++)
  9149. {
  9150. 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"));
  9151. 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"));
  9152. 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)
  9153. 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"));
  9154. }
  9155. }
  9156. }
  9157. }
  9158. else
  9159. {
  9160. chargingProfileIsNULL = TRUE;
  9161. }
  9162. }
  9163. }
  9164. else
  9165. {
  9166. connectorIdIsNULL = TRUE;
  9167. }
  9168. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9169. {
  9170. DEBUG_WARN("Connector id is NULL\n.");
  9171. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9172. goto end;
  9173. }
  9174. /*
  9175. enum _SYSTEM_STATUS
  9176. {
  9177. S_BOOTING = 0,
  9178. S_IDLE, = 1
  9179. S_AUTHORIZING, = 2
  9180. S_REASSIGN_CHECK, = 3
  9181. S_REASSIGN, = 4
  9182. S_PRECHARGE, = 5
  9183. S_PREPARING_FOR_EV, = 6
  9184. S_PREPARING_FOR_EVSE, = 7
  9185. S_CHARGING, = 8
  9186. S_TERMINATING, = 9
  9187. S_COMPLETE, = 10
  9188. S_ALARM, = 11
  9189. S_FAULT = 12
  9190. }
  9191. */
  9192. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9193. {
  9194. //check Transaction active
  9195. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9196. {
  9197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9198. {
  9199. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9200. }
  9201. else
  9202. {
  9203. tempIndex = connectorIdInt -1;
  9204. }
  9205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9206. {
  9207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9208. {
  9209. 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))
  9210. {
  9211. //Reserved
  9212. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9213. }
  9214. 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))
  9215. {
  9216. //Reserved
  9217. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9218. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9219. goto end;
  9220. }
  9221. else
  9222. {
  9223. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9224. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9225. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9226. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9227. {
  9228. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9229. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9230. goto end;
  9231. }
  9232. }//END FOR ELSE
  9233. }
  9234. }// END FOR CHAdeMO_QUANTITY
  9235. }
  9236. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9237. {
  9238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9239. {
  9240. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9241. }
  9242. else
  9243. {
  9244. tempIndex = connectorIdInt -1;
  9245. }
  9246. for (int index = 0; index < CCS_QUANTITY; index++)
  9247. {
  9248. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9249. {
  9250. 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))
  9251. {
  9252. //Reserved
  9253. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9254. }
  9255. 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))
  9256. {
  9257. //Reserved
  9258. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9259. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9260. goto end;
  9261. }
  9262. else
  9263. {
  9264. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9265. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9266. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9267. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9268. {
  9269. DEBUG_WARN("CCS connector not allow start\n.");
  9270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9271. goto end;
  9272. }
  9273. }// END FOR ELSE
  9274. }
  9275. }// END FOR CCS_QUANTITY
  9276. }
  9277. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9278. {
  9279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9280. {
  9281. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9282. }
  9283. else
  9284. {
  9285. tempIndex = connectorIdInt -1;
  9286. }
  9287. for (int index = 0; index < GB_QUANTITY; index++)
  9288. {
  9289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9290. {
  9291. 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))
  9292. {
  9293. //Reserved
  9294. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9295. }
  9296. 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))
  9297. {
  9298. //Reserved
  9299. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9301. goto end;
  9302. }
  9303. else
  9304. {
  9305. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9306. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9307. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9308. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9309. {
  9310. DEBUG_WARN("GB connector not allow start\n.");
  9311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9312. goto end;
  9313. }
  9314. }// END FOR ELSE
  9315. }
  9316. } // END FOR GB_QUANTITY
  9317. }
  9318. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9319. {
  9320. tempIndex = connectorIdInt -1;
  9321. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9322. {
  9323. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9324. {
  9325. 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))
  9326. {
  9327. //Reserved
  9328. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9329. }
  9330. 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))
  9331. {
  9332. //Reserved
  9333. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9335. goto end;
  9336. }
  9337. else
  9338. {
  9339. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9340. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9341. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9342. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9343. {
  9344. DEBUG_WARN("GB connector not allow start\n.");
  9345. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9346. goto end;
  9347. }
  9348. }// END FOR ELSE
  9349. }
  9350. } // END FOR GB_QUANTITY
  9351. }
  9352. else
  9353. {
  9354. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9355. {
  9356. tempIndex = 2;
  9357. }
  9358. else
  9359. {
  9360. tempIndex = connectorIdInt -1;
  9361. }
  9362. for (int index = 0; index < AC_QUANTITY; index++)
  9363. {
  9364. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9365. {
  9366. 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))
  9367. {
  9368. //Reserved
  9369. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9370. }
  9371. 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))
  9372. {
  9373. //Reserved
  9374. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9375. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9376. goto end;
  9377. }
  9378. else
  9379. {
  9380. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9381. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9382. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9383. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9384. {
  9385. DEBUG_WARN("AC connector not allow start\n.");
  9386. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9387. goto end;
  9388. }
  9389. }//END FOR ELSE
  9390. }
  9391. }// END FOR AC_QUANTITY
  9392. }
  9393. if(chargingProfileIsNULL == FALSE)
  9394. {
  9395. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9396. {
  9397. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9398. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9399. //memset idTag
  9400. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9401. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9402. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9403. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9404. // Save profile to file
  9405. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9406. system(cmdBuf);
  9407. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9408. fp = fopen(cmdBuf, "w");
  9409. 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));
  9410. fclose(fp);
  9411. }
  9412. else
  9413. {
  9414. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9415. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9416. }
  9417. }
  9418. else
  9419. {
  9420. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9421. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9422. //memset idTag
  9423. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9424. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9425. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9426. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9427. }
  9428. }
  9429. else
  9430. {
  9431. DEBUG_WARN("Connector id over\n.");
  9432. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9433. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9434. }
  9435. end:
  9436. json_object_put(RemoteStartTransaction);
  9437. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9438. {
  9439. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9440. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9441. }
  9442. //OCPP send RemoteStartConfirmation by first.
  9443. sendRemoteStartConfirmation(uuid, comfirmstr);
  9444. return result;
  9445. }
  9446. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9447. {
  9448. mtrace();
  9449. int result = FAIL;
  9450. int match = FALSE;
  9451. int GunNO = 0;
  9452. int tempIndex = 0;
  9453. int transactionIdInt=0;
  9454. int transactionIdIsNULL= TRUE;
  9455. char comfirmstr[20];
  9456. json_object *RemoteStopTransaction;
  9457. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9458. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9459. if(server_pending == TRUE)
  9460. {
  9461. return 0;
  9462. }
  9463. RemoteStopTransaction = json_tokener_parse(payload);
  9464. if(!is_error(RemoteStopTransaction))
  9465. {
  9466. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9467. {
  9468. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9469. transactionIdIsNULL = FALSE;
  9470. }
  9471. }
  9472. json_object_put(RemoteStopTransaction);
  9473. if(transactionIdIsNULL == FALSE)
  9474. {
  9475. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9476. {
  9477. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9478. {
  9479. //check Transaction active
  9480. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9481. {
  9482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9483. {
  9484. tempIndex = ((gun_index==2) ? 1: 0);
  9485. }
  9486. else
  9487. {
  9488. tempIndex = gun_index;
  9489. }
  9490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9491. {
  9492. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9493. {
  9494. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9495. {
  9496. match = TRUE;
  9497. GunNO = gun_index;
  9498. }
  9499. }
  9500. }// END FOR CHAdeMO_QUANTITY
  9501. }
  9502. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9503. {
  9504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9505. {
  9506. tempIndex = ((gun_index==2) ? 1: 0);
  9507. }
  9508. else
  9509. {
  9510. tempIndex = gun_index;
  9511. }
  9512. for (int index = 0; index < CCS_QUANTITY; index++)
  9513. {
  9514. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9515. {
  9516. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9517. {
  9518. match = TRUE;
  9519. GunNO = gun_index;
  9520. }
  9521. }
  9522. }// END FOR CCS_QUANTITY
  9523. }
  9524. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9525. {
  9526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9527. {
  9528. tempIndex = ((gun_index==2) ? 1: 0);
  9529. }
  9530. else
  9531. {
  9532. tempIndex = gun_index;
  9533. }
  9534. for (int index = 0; index < GB_QUANTITY; index++)
  9535. {
  9536. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9537. {
  9538. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9539. {
  9540. match = TRUE;
  9541. GunNO = gun_index;
  9542. }
  9543. }
  9544. }// END FOR GB_QUANTITY
  9545. }
  9546. else if(gunType[gun_index] == GUN_TYPE_DO)
  9547. {
  9548. tempIndex = gun_index;
  9549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9550. {
  9551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9552. {
  9553. 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
  9554. {
  9555. match = TRUE;
  9556. GunNO = gun_index;
  9557. }
  9558. }
  9559. }// END FOR GB_QUANTITY
  9560. }
  9561. else
  9562. {
  9563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9564. {
  9565. tempIndex = 2;
  9566. }
  9567. else
  9568. {
  9569. tempIndex = gun_index;
  9570. }
  9571. for (int index = 0; index < AC_QUANTITY; index++)
  9572. {
  9573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9574. {
  9575. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9576. {
  9577. match = TRUE;
  9578. GunNO = gun_index;
  9579. }
  9580. }
  9581. }// END FOR CHAdeMO_QUANTITY
  9582. } // END FOR AC ELSE
  9583. }// CHECK IF ResponseTransactionId == transactionIdInt
  9584. }//END FOR
  9585. if( match == TRUE)
  9586. {
  9587. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9588. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9589. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9590. }
  9591. else
  9592. {
  9593. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9594. }
  9595. }
  9596. else
  9597. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9598. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9599. return result;
  9600. }
  9601. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9602. {
  9603. mtrace();
  9604. int result = FAIL;
  9605. int connectorIdInt=0, reservationIdInt=0;
  9606. int tempIndex = 0;
  9607. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9608. char comfirmstr[20]={0};
  9609. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9610. int c = 0;
  9611. char *loc;
  9612. //char *ptr;
  9613. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9614. strcpy(sstrtemp, stringtrimspace(payload));
  9615. //***(1)connectorId ****/
  9616. c=0;
  9617. loc = strstr(sstrtemp, "connectorId");
  9618. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9619. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9620. {
  9621. sstr[c] = loc[strlen("connectorId")+2+c];
  9622. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9623. c++;
  9624. }
  9625. sstr[c] = '\0';
  9626. connectorIdInt = atoi(sstr);
  9627. //***(2)expiryDate ****/
  9628. loc = strstr(sstrtemp, "expiryDate");
  9629. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9630. c = 0;
  9631. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9632. {
  9633. sstr[c] = loc[3+strlen("expiryDate")+c];
  9634. c++;
  9635. }
  9636. sstr[c] = '\0';
  9637. strcpy(expiryDatestr, sstr);
  9638. //***(3)idTag ****/
  9639. loc = strstr(sstrtemp, "idTag");
  9640. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9641. c = 0;
  9642. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9643. {
  9644. sstr[c] = loc[3+strlen("idTag")+c];
  9645. c++;
  9646. }
  9647. sstr[c] = '\0';
  9648. strcpy(idTagstr, sstr);
  9649. //***(4)parentIdTag ****/
  9650. loc = strstr(sstrtemp, "parentIdTag");
  9651. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9652. c = 0;
  9653. if(loc == NULL)
  9654. {
  9655. strcpy(parentIdTagstr, "");
  9656. }
  9657. else
  9658. {
  9659. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9660. {
  9661. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9662. c++;
  9663. }
  9664. sstr[c] = '\0';
  9665. strcpy(parentIdTagstr, sstr);
  9666. }
  9667. //***(5)reservationId ****/
  9668. c=0;
  9669. loc = strstr(sstrtemp, "reservationId");
  9670. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9671. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9672. {
  9673. sstr[c] = loc[strlen("reservationId")+2+c];
  9674. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9675. c++;
  9676. }
  9677. sstr[c] = '\0';
  9678. reservationIdInt = atoi(sstr);
  9679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9680. /*
  9681. enum SYSTEM_STATUS
  9682. {
  9683. SYS_MODE_BOOTING = 0,
  9684. SYS_MODE_IDLE = 1,
  9685. SYS_MODE_AUTHORIZING = 2,
  9686. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9687. SYS_MODE_REASSIGN = 4,
  9688. SYS_MODE_PREPARING = 5,
  9689. SYS_MODE_PREPARE_FOR_EV = 6,
  9690. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9691. SYS_MODE_CHARGING = 8,
  9692. SYS_MODE_TERMINATING = 9,
  9693. SYS_MODE_COMPLETE = 10,
  9694. SYS_MODE_ALARM = 11,
  9695. SYS_MODE_FAULT = 12,
  9696. SYS_MODE_RESERVATION = 13,
  9697. SYS_MODE_BOOKING = 14,
  9698. SYS_MODE_MAINTAIN = 15,
  9699. SYS_MODE_DEBUG = 16,
  9700. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9701. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9702. SYS_MODE_UPDATE = 19
  9703. };
  9704. */
  9705. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9706. {
  9707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9708. goto end;
  9709. }
  9710. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9711. {
  9712. //check Transaction active
  9713. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9714. {
  9715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9716. {
  9717. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9718. }
  9719. else
  9720. {
  9721. tempIndex = connectorIdInt -1;
  9722. }
  9723. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9724. {
  9725. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9726. {
  9727. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9728. {
  9729. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9730. {
  9731. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9732. {
  9733. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9735. }
  9736. 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'))
  9737. {
  9738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9739. }
  9740. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9741. {
  9742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9743. }
  9744. else
  9745. {
  9746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9747. }
  9748. }
  9749. 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
  9750. {
  9751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9752. }
  9753. }
  9754. else
  9755. {
  9756. //replace reservation
  9757. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9759. }
  9760. }
  9761. } // END FOR CHAdeMO_QUANTITY
  9762. }
  9763. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9764. {
  9765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9766. {
  9767. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9768. }
  9769. else
  9770. {
  9771. tempIndex = connectorIdInt -1;
  9772. }
  9773. for (int index = 0; index < CCS_QUANTITY; index++)
  9774. {
  9775. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9776. {
  9777. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9778. {
  9779. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9780. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9781. {
  9782. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9783. {
  9784. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9786. }
  9787. 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'))
  9788. {
  9789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9790. }
  9791. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9792. {
  9793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9794. }
  9795. else
  9796. {
  9797. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9798. }
  9799. }
  9800. 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
  9801. {
  9802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9803. }
  9804. }
  9805. else
  9806. {
  9807. //replace reservation
  9808. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9810. }
  9811. }
  9812. } // END FOR CCS_QUANTITY
  9813. }
  9814. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9815. {
  9816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9817. {
  9818. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9819. }
  9820. else
  9821. {
  9822. tempIndex = connectorIdInt -1;
  9823. }
  9824. for (int index = 0; index < GB_QUANTITY; index++)
  9825. {
  9826. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9827. {
  9828. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9829. {
  9830. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9831. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9832. {
  9833. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9834. {
  9835. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9837. }
  9838. 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'))
  9839. {
  9840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9841. }
  9842. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9843. {
  9844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9845. }
  9846. else
  9847. {
  9848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9849. }
  9850. }
  9851. 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
  9852. {
  9853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9854. }
  9855. }
  9856. else
  9857. {
  9858. //replace reservation
  9859. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9861. }
  9862. }
  9863. }// END FOR GB_QUANTITY
  9864. }
  9865. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9866. {
  9867. tempIndex = connectorIdInt -1;
  9868. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9869. {
  9870. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9871. {
  9872. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9873. {
  9874. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9875. 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
  9876. {
  9877. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9878. {
  9879. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9881. }
  9882. 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'))
  9883. {
  9884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9885. }
  9886. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9887. {
  9888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9889. }
  9890. else
  9891. {
  9892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9893. }
  9894. }
  9895. 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
  9896. {
  9897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9898. }
  9899. }
  9900. else
  9901. {
  9902. //replace reservation
  9903. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9905. }
  9906. }
  9907. }// END FOR GB_QUANTITY
  9908. }
  9909. else
  9910. {
  9911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9912. {
  9913. tempIndex = 2;
  9914. }
  9915. else
  9916. {
  9917. tempIndex = (connectorIdInt -1);
  9918. }
  9919. for (int index = 0; index < AC_QUANTITY; index++)
  9920. {
  9921. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9922. {
  9923. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9924. {
  9925. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9926. {
  9927. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9928. {
  9929. 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))
  9930. {
  9931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9932. }
  9933. else
  9934. {
  9935. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9937. }
  9938. }
  9939. 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'))
  9940. {
  9941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9942. }
  9943. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9944. {
  9945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9946. }
  9947. else
  9948. {
  9949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9950. }
  9951. }
  9952. 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
  9953. {
  9954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9955. }
  9956. }
  9957. else
  9958. {
  9959. //replace reservation
  9960. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9962. }
  9963. }
  9964. } // END FOR AC_QUANTITY
  9965. }
  9966. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9967. }
  9968. else if(connectorIdInt == 0)
  9969. {
  9970. //check Transaction active
  9971. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9972. {
  9973. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9974. {
  9975. 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'))
  9976. {
  9977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9978. goto end;
  9979. }
  9980. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9981. {
  9982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9983. goto end;
  9984. }
  9985. 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
  9986. {
  9987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9988. goto end;
  9989. }
  9990. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9991. {
  9992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9993. goto end;
  9994. }
  9995. }
  9996. }// END FOR CHAdeMO_QUANTITY
  9997. for (int index = 0; index < CCS_QUANTITY; index++)
  9998. {
  9999. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10000. {
  10001. 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'))
  10002. {
  10003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10004. goto end;
  10005. }
  10006. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10007. {
  10008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10009. goto end;
  10010. }
  10011. 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
  10012. {
  10013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10014. goto end;
  10015. }
  10016. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10017. {
  10018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10019. goto end;
  10020. }
  10021. }
  10022. } // END FOR CCS_QUANTITY
  10023. for (int index = 0; index < GB_QUANTITY; index++)
  10024. {
  10025. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10026. {
  10027. 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'))
  10028. {
  10029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10030. goto end;
  10031. }
  10032. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10033. {
  10034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10035. goto end;
  10036. }
  10037. 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
  10038. {
  10039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10040. goto end;
  10041. }
  10042. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10043. {
  10044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10045. goto end;
  10046. }
  10047. }
  10048. } // END FOR GB_QUANTITY
  10049. for (int index = 0; index < AC_QUANTITY; index++)
  10050. {
  10051. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10052. {
  10053. 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'))
  10054. {
  10055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10056. goto end;
  10057. }
  10058. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10059. {
  10060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10061. goto end;
  10062. }
  10063. 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
  10064. {
  10065. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10066. goto end;
  10067. }
  10068. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10069. {
  10070. 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))
  10071. {
  10072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10073. goto end;
  10074. }
  10075. }
  10076. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10077. {
  10078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10079. goto end;
  10080. }
  10081. }
  10082. }// END FOR AC_QUANTITY
  10083. //The connectorId is 0
  10084. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10086. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10087. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10088. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10089. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10090. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10091. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10092. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10093. result = TRUE;
  10094. return result;
  10095. }
  10096. else
  10097. {
  10098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10099. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10100. }
  10101. if(strcmp(comfirmstr,"Accepted") == 0)
  10102. {
  10103. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10104. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10105. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10106. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10107. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10108. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  10109. result = TRUE;
  10110. return result;
  10111. }
  10112. end:
  10113. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10114. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10115. return result;
  10116. }
  10117. int handleResetRequest(char *uuid, char *payload)
  10118. {
  10119. mtrace();
  10120. int result = FAIL;
  10121. char sstr[10]={0},sstrtemp[30]={ 0 };
  10122. char typestr[10]={0};
  10123. char comfirmstr[20]={0};
  10124. int c = 0;
  10125. char *loc;
  10126. DEBUG_INFO("handleResetRequest...\n");
  10127. strcpy(sstrtemp, stringtrimspace(payload));
  10128. loc = strstr(sstrtemp, "type");
  10129. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10130. c = 0;
  10131. while (loc[3+strlen("type")+c] != '\"')
  10132. {
  10133. sstr[c] = loc[3+strlen("type")+c];
  10134. c++;
  10135. }
  10136. sstr[c] = '\0';
  10137. strcpy(typestr,sstr);
  10138. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  10139. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10140. {
  10141. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  10142. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  10143. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10144. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10145. }
  10146. else
  10147. {
  10148. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10149. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10150. result = PASS;
  10151. }
  10152. sendResetConfirmation(uuid, comfirmstr);
  10153. return result;
  10154. }
  10155. int handleSendLocalListRequest(char *uuid, char *payload)
  10156. {
  10157. mtrace();
  10158. int result = FAIL;
  10159. char comfirmstr[20];
  10160. int checkState_Faulted = FALSE;
  10161. json_object *SendLocalList;
  10162. DEBUG_INFO("handleSendLocalListRequest...\n");
  10163. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10164. {
  10165. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10166. goto end;
  10167. }
  10168. //check Charge Point state
  10169. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10170. {
  10171. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10172. {
  10173. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10174. }
  10175. }
  10176. for (int index = 0; index < CCS_QUANTITY; index++)
  10177. {
  10178. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10179. {
  10180. checkState_Faulted = TRUE; //OCPP Status
  10181. }
  10182. }
  10183. for (int index = 0; index < GB_QUANTITY; index++)
  10184. {
  10185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10186. {
  10187. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10188. }
  10189. }
  10190. //check Charge Point state
  10191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10192. {
  10193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10194. {
  10195. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10196. }
  10197. }
  10198. //check Charge Point state
  10199. for (int index = 0; index < AC_QUANTITY; index++)
  10200. {
  10201. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10202. {
  10203. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10204. }
  10205. }
  10206. if(checkState_Faulted == TRUE)
  10207. {
  10208. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10209. goto end;
  10210. }
  10211. // Parsing payload
  10212. SendLocalList = json_tokener_parse(payload);
  10213. if(!is_error(SendLocalList))
  10214. {
  10215. // Required data
  10216. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10217. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10218. // Optional data
  10219. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10220. {
  10221. //Check UpdateType
  10222. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10223. {
  10224. //Local list full update
  10225. DEBUG_INFO("Local list full update.\n");
  10226. OCPP_getListVerion();
  10227. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10228. {
  10229. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10230. goto end;
  10231. }
  10232. OCPP_cleanLocalList();
  10233. }
  10234. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10235. {
  10236. //Local list different update
  10237. DEBUG_INFO("Local list different update.\n");
  10238. OCPP_getListVerion();
  10239. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10240. {
  10241. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10242. goto end;
  10243. }
  10244. }
  10245. else
  10246. {
  10247. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10248. goto end;
  10249. }
  10250. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10251. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10252. {
  10253. 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")));
  10254. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10255. {
  10256. 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")));
  10257. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10258. 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")));
  10259. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10260. 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")));
  10261. }
  10262. // Add to db
  10263. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10264. {
  10265. //Local list full update
  10266. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10267. idx,
  10268. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10269. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10270. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10271. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10272. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10273. // update list
  10274. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10275. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10276. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10277. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10278. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10279. }
  10280. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10281. {
  10282. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10283. idx,
  10284. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10285. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10286. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10287. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10288. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10289. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10290. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10291. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10292. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10293. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10294. }
  10295. }
  10296. }
  10297. else
  10298. {
  10299. //Check UpdateType
  10300. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10301. {
  10302. //Local list full update
  10303. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10304. OCPP_cleanLocalList();
  10305. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10306. goto end;
  10307. }
  10308. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10309. {
  10310. //Local list different update
  10311. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10312. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10313. goto end;
  10314. }
  10315. }
  10316. result = PASS;
  10317. }
  10318. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10319. end:
  10320. json_object_put(SendLocalList);
  10321. sendSendLocalListConfirmation(uuid, comfirmstr);
  10322. return result;
  10323. }
  10324. #define MAX 200
  10325. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10326. {
  10327. mtrace();
  10328. int result = FAIL;
  10329. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10330. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10331. char chargingProfilePurposeStr[30]={0};
  10332. char chargingProfileKindStr[16]={0};
  10333. char recurrencyKindStr[10]={0};
  10334. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10335. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10336. int chargingSchedulePeriodCount = 0;
  10337. char comfirmstr[20]={0};
  10338. int meet= FALSE;
  10339. FILE *fptr1;
  10340. char filename[MAX]={0};
  10341. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  10342. char rmFileCmd[50]={0};
  10343. char tempchargingProfilePurposeStr[30]={0};
  10344. char word[1600]={0};
  10345. int n_chargingProfile = 0;
  10346. json_object *SetChargingProfile;
  10347. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10348. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10349. SetChargingProfile = json_tokener_parse(payload);
  10350. if(!is_error(SetChargingProfile))
  10351. {
  10352. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10353. {
  10354. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10355. if(connectorIdInt == 0)
  10356. {
  10357. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10358. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10359. }
  10360. else
  10361. {
  10362. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10363. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10364. }
  10365. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10366. }
  10367. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10368. {
  10369. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10370. {
  10371. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10372. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10373. {
  10374. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10375. }
  10376. else
  10377. {
  10378. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10379. }
  10380. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10381. }
  10382. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10383. {
  10384. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10385. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10386. {
  10387. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10388. }
  10389. else
  10390. {
  10391. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10392. }
  10393. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10394. }
  10395. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10396. {
  10397. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10398. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10399. {
  10400. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10401. }
  10402. else
  10403. {
  10404. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10405. }
  10406. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10407. }
  10408. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10409. {
  10410. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10411. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10412. {
  10413. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10414. }
  10415. else
  10416. {
  10417. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10418. }
  10419. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10420. }
  10421. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10422. {
  10423. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10424. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10425. {
  10426. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10427. }
  10428. else
  10429. {
  10430. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10431. }
  10432. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10433. }
  10434. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10435. {
  10436. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10437. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10438. {
  10439. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10440. }
  10441. else
  10442. {
  10443. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10444. }
  10445. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10446. }
  10447. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10448. {
  10449. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10450. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10451. {
  10452. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10453. }
  10454. else
  10455. {
  10456. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10457. }
  10458. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10459. }
  10460. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10461. {
  10462. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10464. {
  10465. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10466. }
  10467. else
  10468. {
  10469. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10470. }
  10471. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10472. }
  10473. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10474. {
  10475. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10476. {
  10477. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10478. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10479. {
  10480. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10481. }
  10482. else
  10483. {
  10484. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10485. }
  10486. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10487. }
  10488. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10489. {
  10490. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10491. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10492. {
  10493. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10494. }
  10495. else
  10496. {
  10497. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10498. }
  10499. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10500. }
  10501. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10502. {
  10503. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10504. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10505. {
  10506. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10507. }
  10508. else
  10509. {
  10510. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10511. }
  10512. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10513. }
  10514. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10515. {
  10516. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10517. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10518. {
  10519. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10520. }
  10521. else
  10522. {
  10523. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10524. }
  10525. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10526. }
  10527. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10528. {
  10529. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10530. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10531. if(chargingSchedulePeriodCount <= 10)
  10532. {
  10533. 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++)
  10534. {
  10535. 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)
  10536. {
  10537. startPeriodInt[idxPeriod] = 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"));
  10538. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10539. {
  10540. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10541. }
  10542. else
  10543. {
  10544. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10545. }
  10546. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10547. }
  10548. 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)
  10549. {
  10550. limitflaot[idxPeriod] = 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"));
  10551. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10552. {
  10553. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10554. }
  10555. else
  10556. {
  10557. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10558. }
  10559. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10560. }
  10561. 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)
  10562. {
  10563. numberPhasesInt[idxPeriod] = 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"));
  10564. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10565. {
  10566. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10567. }
  10568. else
  10569. {
  10570. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10571. }
  10572. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10573. }
  10574. }
  10575. }
  10576. }
  10577. }
  10578. }
  10579. }
  10580. json_object_put(SetChargingProfile);
  10581. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10582. {
  10583. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10584. goto end;
  10585. }
  10586. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10587. {
  10588. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10589. if(connectorIdInt != 0)
  10590. {
  10591. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10592. goto end;
  10593. }
  10594. strcpy(filename, ChargePointMaxProfile_JSON );
  10595. fptr1 = fopen(filename, "r");
  10596. if (!fptr1)
  10597. {
  10598. //file not exist
  10599. DEBUG_INFO("Unable to open the input file!!\n");
  10600. fptr1 = fopen(filename, "w+");
  10601. }
  10602. else
  10603. {
  10604. //Check Charging Profile Count
  10605. while(fscanf(fptr1, "%s", word) != EOF)
  10606. {
  10607. //DEBUG_INFO("word=%s\n",word);
  10608. if(strstr(word, "chargingProfileId")!= NULL)
  10609. {
  10610. //DEBUG_INFO("test chargingProfileId \n");
  10611. n_chargingProfile = n_chargingProfile + 1;
  10612. //DEBUG_INFO("chargingProfileId Found\n");
  10613. }
  10614. }
  10615. }
  10616. fclose(fptr1);
  10617. }
  10618. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10619. {
  10620. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10621. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10622. {
  10623. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10624. goto end;
  10625. }
  10626. memset(filename, 0, ARRAY_SIZE(filename));
  10627. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  10628. fptr1 = fopen(filename, "r");
  10629. if (!fptr1)
  10630. {
  10631. //file not exist
  10632. //DEBUG_INFO("Unable to open the input file!!\n");
  10633. fptr1 = fopen(filename, "w+");
  10634. }
  10635. else
  10636. {
  10637. //Check Charging Profile Count
  10638. while(fscanf(fptr1, "%s", word) != EOF)
  10639. {
  10640. //DEBUG_INFO("word=%s\n",word);
  10641. if(strstr(word, "chargingProfileId")!= NULL)
  10642. {
  10643. //DEBUG_INFO("test chargingProfileId \n");
  10644. n_chargingProfile = n_chargingProfile + 1;
  10645. //DEBUG_INFO("chargingProfileId Found\n");
  10646. }
  10647. }
  10648. }
  10649. fclose(fptr1);
  10650. }
  10651. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10652. {
  10653. //printf("set chargingProfile 1-4\n");
  10654. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10655. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10656. if(connectorIdInt == 0)
  10657. {
  10658. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10659. goto end;
  10660. }
  10661. int tempIndex = 0;
  10662. //check Transaction active
  10663. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10664. {
  10665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10666. {
  10667. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10668. }
  10669. else
  10670. {
  10671. tempIndex = connectorIdInt -1;
  10672. }
  10673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10674. {
  10675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10676. {
  10677. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10678. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10679. {
  10680. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10681. {
  10682. meet = TRUE;
  10683. break;
  10684. }
  10685. }
  10686. }
  10687. }
  10688. }
  10689. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10690. {
  10691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10692. {
  10693. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10694. }
  10695. else
  10696. {
  10697. tempIndex = connectorIdInt -1;
  10698. }
  10699. for (int index = 0; index < CCS_QUANTITY; index++)
  10700. {
  10701. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10702. {
  10703. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10704. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10705. {
  10706. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10707. {
  10708. meet = TRUE;
  10709. break;
  10710. }
  10711. }
  10712. }
  10713. }
  10714. }
  10715. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10716. {
  10717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10718. {
  10719. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10720. }
  10721. else
  10722. {
  10723. tempIndex = connectorIdInt -1;
  10724. }
  10725. for (int index = 0; index < GB_QUANTITY; index++)
  10726. {
  10727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10728. {
  10729. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10730. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10731. {
  10732. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10733. {
  10734. meet = TRUE;
  10735. break;
  10736. }
  10737. }
  10738. }
  10739. }
  10740. }
  10741. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10742. {
  10743. tempIndex = connectorIdInt -1;
  10744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10745. {
  10746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10747. {
  10748. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10749. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10750. {
  10751. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10752. {
  10753. meet = TRUE;
  10754. break;
  10755. }
  10756. }
  10757. }
  10758. }
  10759. }
  10760. else
  10761. {
  10762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10763. {
  10764. tempIndex = 2;
  10765. }
  10766. else
  10767. {
  10768. tempIndex = (connectorIdInt -1);
  10769. }
  10770. for (int index = 0; index < AC_QUANTITY; index++)
  10771. {
  10772. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10773. {
  10774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10776. {
  10777. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10778. {
  10779. meet = TRUE;
  10780. break;
  10781. }
  10782. }
  10783. }
  10784. }
  10785. }
  10786. //check Transaction active
  10787. if(meet == FALSE)
  10788. {
  10789. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10790. goto end;
  10791. }
  10792. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10793. {
  10794. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10795. goto end;
  10796. }
  10797. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10798. fptr1 = fopen(filename, "r");
  10799. if (!fptr1)
  10800. {
  10801. //file not exist
  10802. DEBUG_INFO("Unable to open the input file!!\n");
  10803. fptr1 = fopen(filename, "w+");
  10804. }
  10805. else
  10806. {
  10807. //Check Charging Profile Count
  10808. while(fscanf(fptr1, "%s", word) != EOF)
  10809. {
  10810. //DEBUG_INFO("word=%s\n",word);
  10811. if(strstr(word, "chargingProfileId")!= NULL)
  10812. {
  10813. //DEBUG_INFO("test chargingProfileId \n");
  10814. n_chargingProfile = n_chargingProfile + 1;
  10815. //DEBUG_INFO("chargingProfileId Found\n");
  10816. }
  10817. }
  10818. }
  10819. fclose(fptr1);
  10820. }
  10821. // Check ChargeProfileMaxStackLevel
  10822. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10823. {
  10824. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10825. goto end;
  10826. }
  10827. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10828. {
  10829. int i = 0;
  10830. char fnametemp[200]={0};
  10831. n_chargingProfile = 0;
  10832. //Check ChargePointMaxProfile.json exit
  10833. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  10834. {
  10835. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  10836. //Check Charging Profile Count
  10837. while(fscanf(fptr1, "%s", word) != EOF)
  10838. {
  10839. //DEBUG_INFO("word=%s\n",word);
  10840. if(strstr(word, "chargingProfileId")!= NULL)
  10841. {
  10842. //DEBUG_INFO("test chargingProfileId \n");
  10843. n_chargingProfile = n_chargingProfile + 1;
  10844. i = i + 1;
  10845. //DEBUG_INFO("chargingProfileId Found\n");
  10846. }
  10847. memset(word, 0, ARRAY_SIZE(word));
  10848. }
  10849. fclose(fptr1);
  10850. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10851. }
  10852. //Check TxDefaultProfile_0.json exit
  10853. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  10854. {
  10855. i = 0;
  10856. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  10857. //Check Charging Profile Count
  10858. while(fscanf(fptr1, "%s", word) != EOF)
  10859. {
  10860. //DEBUG_INFO("word=%s\n",word);
  10861. if(strstr(word, "chargingProfileId")!= NULL)
  10862. {
  10863. //DEBUG_INFO("test chargingProfileId \n");
  10864. n_chargingProfile = n_chargingProfile + 1;
  10865. i = i + 1;
  10866. //DEBUG_INFO("chargingProfileId Found\n");
  10867. }
  10868. memset(word, 0, ARRAY_SIZE(word));
  10869. }
  10870. fclose(fptr1);
  10871. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10872. }
  10873. //Check TxDefaultProfile_%d.json
  10874. for(int j=1; j <= gunTotalNumber; j++)
  10875. {
  10876. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10877. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10878. if((access(fnametemp,F_OK))!=-1)
  10879. {
  10880. i = 0;
  10881. fptr1 = fopen(fnametemp, "r");
  10882. //Check Charging Profile Count
  10883. while(fscanf(fptr1, "%s", word) != EOF)
  10884. {
  10885. //DEBUG_INFO("word=%s\n",word);
  10886. if(strstr(word, "chargingProfileId")!= NULL)
  10887. {
  10888. //DEBUG_INFO("test chargingProfileId \n");
  10889. n_chargingProfile = n_chargingProfile + 1;
  10890. i = i + 1;
  10891. //DEBUG_INFO("chargingProfileId Found\n");
  10892. }
  10893. memset(word, 0, ARRAY_SIZE(word));
  10894. }
  10895. fclose(fptr1);
  10896. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10897. }
  10898. }
  10899. //Check TxProfile_%d.json
  10900. for(int j=1; j <= gunTotalNumber; j++)
  10901. {
  10902. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10903. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10904. if((access(fnametemp,F_OK))!=-1)
  10905. {
  10906. i = 0;
  10907. fptr1 = fopen(fnametemp, "r");
  10908. //Check Charging Profile Count
  10909. while(fscanf(fptr1, "%s", word) != EOF)
  10910. {
  10911. //DEBUG_INFO("word=%s\n",word);
  10912. if(strstr(word, "chargingProfileId")!= NULL)
  10913. {
  10914. //DEBUG_INFO("test chargingProfileId \n");
  10915. n_chargingProfile = n_chargingProfile + 1;
  10916. i = i + 1;
  10917. //DEBUG_INFO("chargingProfileId Found\n");
  10918. }
  10919. memset(word, 0, ARRAY_SIZE(word));
  10920. }
  10921. fclose(fptr1);
  10922. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10923. }
  10924. }
  10925. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10926. {
  10927. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10928. goto end;
  10929. }
  10930. }
  10931. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10932. //**********************************Write to File********************************************************/
  10933. FILE *infile;
  10934. FILE *outfile;
  10935. infile = fopen (filename, "r");
  10936. outfile = fopen (tempfile, "w");
  10937. int d =0;
  10938. d = fgetc(infile);
  10939. rewind(infile);
  10940. if(d == EOF)
  10941. {
  10942. // Profile is empty
  10943. fprintf(outfile,"%s\n",payload);
  10944. fclose(infile);
  10945. fclose(outfile);
  10946. sprintf(rmFileCmd,"rm -f %s",filename);
  10947. system(rmFileCmd);
  10948. rename(tempfile, filename);
  10949. }
  10950. else
  10951. {
  10952. // Profile is not empty
  10953. char buf[2048]={0};
  10954. int ChargingProfileAdded = FALSE;
  10955. while (fgets(buf, sizeof(buf), infile) != NULL)
  10956. {
  10957. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10958. json_object *tmpChargingProfile;
  10959. tmpChargingProfile = json_tokener_parse(buf);
  10960. if(!is_error(SetChargingProfile))
  10961. {
  10962. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10963. {
  10964. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10965. }
  10966. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10967. {
  10968. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10969. {
  10970. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10971. }
  10972. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10973. {
  10974. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10975. }
  10976. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10977. {
  10978. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10979. }
  10980. }
  10981. }
  10982. json_object_put(tmpChargingProfile);
  10983. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10984. {
  10985. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10986. {
  10987. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10988. if(ChargingProfileAdded == FALSE)
  10989. {
  10990. fprintf(outfile,"%s\n",payload);
  10991. ChargingProfileAdded = TRUE;
  10992. }
  10993. }
  10994. else
  10995. {
  10996. if(tempstackLevelInt < stackLevelInt)
  10997. {
  10998. if(ChargingProfileAdded == FALSE)
  10999. {
  11000. fprintf(outfile,"%s\n",buf);
  11001. fprintf(outfile,"%s\n",payload);
  11002. ChargingProfileAdded = TRUE;
  11003. }
  11004. else
  11005. {
  11006. fprintf(outfile,"%s\n",buf);
  11007. }
  11008. }
  11009. else
  11010. {
  11011. if(ChargingProfileAdded == FALSE)
  11012. {
  11013. fprintf(outfile,"%s\n",buf);
  11014. fprintf(outfile,"%s\n",payload);
  11015. ChargingProfileAdded = TRUE;
  11016. }
  11017. else
  11018. {
  11019. fprintf(outfile,"%s\n",buf);
  11020. }
  11021. }
  11022. }
  11023. }
  11024. else
  11025. {
  11026. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11027. {
  11028. if(ChargingProfileAdded == FALSE)
  11029. {
  11030. fprintf(outfile,"%s\n",buf);
  11031. fprintf(outfile,"%s\n",payload);
  11032. ChargingProfileAdded = TRUE;
  11033. }
  11034. else
  11035. {
  11036. fprintf(outfile,"%s\n",buf);
  11037. }
  11038. }
  11039. else if(tempstackLevelInt < stackLevelInt)
  11040. {
  11041. if(ChargingProfileAdded == FALSE)
  11042. {
  11043. fprintf(outfile,"%s\n",buf);
  11044. fprintf(outfile,"%s\n",payload);
  11045. ChargingProfileAdded = TRUE;
  11046. }
  11047. else
  11048. {
  11049. fprintf(outfile,"%s\n",buf);
  11050. }
  11051. }
  11052. else
  11053. {
  11054. if(ChargingProfileAdded == FALSE)
  11055. {
  11056. fprintf(outfile,"%s\n",buf);
  11057. fprintf(outfile,"%s\n",payload);
  11058. ChargingProfileAdded = TRUE;
  11059. }
  11060. else
  11061. {
  11062. fprintf(outfile,"%s\n",buf);
  11063. }
  11064. }
  11065. }
  11066. } // end of while loop
  11067. fclose(infile);
  11068. fclose(outfile);
  11069. sprintf(rmFileCmd,"rm -f %s",filename);
  11070. system(rmFileCmd);
  11071. rename(tempfile, filename);
  11072. }
  11073. sleep(1);
  11074. result = TRUE;
  11075. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11076. end:
  11077. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11078. {
  11079. if(connectorIdInt == 0)
  11080. {
  11081. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11082. {
  11083. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11084. }
  11085. }
  11086. else
  11087. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  11088. }
  11089. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11090. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11091. return result;
  11092. }
  11093. int handleTriggerMessageRequest(char *uuid, char *payload)
  11094. {
  11095. mtrace();
  11096. int result = FAIL;
  11097. int connectorIdIsNULL = FALSE;
  11098. int connectorIdInt =0;
  11099. char sstr[40]={0},sstrtemp[100]={ 0 };
  11100. char requestedMessagestr[40]={0};
  11101. char comfirmstr[20]={0};
  11102. int c = 0;
  11103. char *loc;
  11104. DEBUG_INFO("handleTriggerMessageRequest\n");
  11105. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11106. strcpy(sstrtemp, stringtrimspace(payload));
  11107. c = 0;
  11108. loc = strstr(sstrtemp, "requestedMessage");
  11109. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11110. {
  11111. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11112. c++;
  11113. }
  11114. sstr[c] = '\0';
  11115. strcpy(requestedMessagestr, sstr);
  11116. c = 0;
  11117. loc = strstr(sstrtemp, "connectorId");
  11118. if(loc == NULL)
  11119. {
  11120. connectorIdIsNULL = TRUE;
  11121. }
  11122. else
  11123. {
  11124. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11125. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11126. {
  11127. sstr[c] = loc[strlen("connectorId")+2+c];
  11128. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11129. c++;
  11130. }
  11131. sstr[c] = '\0';
  11132. connectorIdInt = atoi(sstr);
  11133. }
  11134. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11135. {
  11136. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11137. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11138. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11139. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11140. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11141. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11142. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11143. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11144. {
  11145. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11146. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11147. return TRUE;
  11148. }
  11149. else
  11150. {
  11151. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11152. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11153. }
  11154. }
  11155. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11156. {
  11157. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11158. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11159. return TRUE;
  11160. }
  11161. //==========================
  11162. // Trigger message
  11163. //==========================
  11164. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11165. {
  11166. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11167. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11168. {
  11169. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11170. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11171. }
  11172. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11173. }
  11174. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11175. {
  11176. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11177. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11178. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11179. }
  11180. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11181. {
  11182. //sendBootNotificationRequest();
  11183. server_sign = FALSE;
  11184. }
  11185. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11186. {
  11187. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11188. }
  11189. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11190. {
  11191. if(connectorIdIsNULL == FALSE)
  11192. {
  11193. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11194. {
  11195. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11196. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11197. }
  11198. }
  11199. else
  11200. {
  11201. for(int idx=0;idx< gunTotalNumber;idx++)
  11202. {
  11203. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11204. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11205. }
  11206. }
  11207. }
  11208. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11209. {
  11210. if(connectorIdIsNULL == FALSE)
  11211. {
  11212. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11213. {
  11214. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11215. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11216. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11217. }
  11218. }
  11219. else
  11220. {
  11221. for(int idx=0;idx< gunTotalNumber;idx++)
  11222. {
  11223. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11224. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11225. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11226. }
  11227. }
  11228. }
  11229. return result;
  11230. }
  11231. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11232. {
  11233. mtrace();
  11234. int result = FAIL;
  11235. int connectorIdInt =0;
  11236. char comfirmstr[20]={0};
  11237. int tempIndex = 0;
  11238. json_object *UnlockConnector;
  11239. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11240. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11241. UnlockConnector = json_tokener_parse(payload);
  11242. if(!is_error(UnlockConnector))
  11243. {
  11244. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11245. {
  11246. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11247. }
  11248. }
  11249. json_object_put(UnlockConnector);
  11250. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11251. if(gunTotalNumber == 0)
  11252. {
  11253. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11254. goto end;
  11255. }
  11256. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11257. {
  11258. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11259. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11260. goto end;
  11261. }
  11262. else
  11263. {
  11264. //check Transaction active
  11265. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11266. {
  11267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11268. {
  11269. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11270. }
  11271. else
  11272. {
  11273. tempIndex = connectorIdInt -1;
  11274. }
  11275. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11276. {
  11277. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11278. {
  11279. //stop Transaction
  11280. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11281. }
  11282. }
  11283. }
  11284. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11285. {
  11286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11287. {
  11288. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11289. }
  11290. else
  11291. {
  11292. tempIndex = connectorIdInt -1;
  11293. }
  11294. for (int index = 0; index < CCS_QUANTITY; index++)
  11295. {
  11296. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11297. {
  11298. //stop Transaction
  11299. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11300. }
  11301. }
  11302. }
  11303. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11304. {
  11305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11306. {
  11307. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11308. }
  11309. else
  11310. {
  11311. tempIndex = connectorIdInt -1;
  11312. }
  11313. for (int index = 0; index < GB_QUANTITY; index++)
  11314. {
  11315. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11316. {
  11317. //stop Transaction
  11318. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11319. }
  11320. }
  11321. }
  11322. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11323. {
  11324. tempIndex = connectorIdInt -1;
  11325. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11326. {
  11327. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11328. {
  11329. //stop Transaction
  11330. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11331. }
  11332. }
  11333. }
  11334. else
  11335. {
  11336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11337. {
  11338. tempIndex = 2;
  11339. }
  11340. else
  11341. {
  11342. tempIndex = connectorIdInt-1;
  11343. }
  11344. for (int index = 0; index < AC_QUANTITY; index++)
  11345. {
  11346. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11347. {
  11348. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11349. }
  11350. }
  11351. }
  11352. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11353. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11354. result = TRUE;
  11355. return result;
  11356. }
  11357. end:
  11358. //json_object_put(obj); --- remove temporally
  11359. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11360. return result;
  11361. }
  11362. static char UpdateFirmwarepayloadData[300]={0};
  11363. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11364. {
  11365. mtrace();
  11366. int result = FAIL;
  11367. pthread_t t;
  11368. sendUpdateFirmwareConfirmation(uuid);
  11369. memset(UpdateFirmwarepayloadData, 0, 300);
  11370. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11371. if(!interLock.isUpdateFirmwareGoing)
  11372. {
  11373. interLock.isUpdateFirmwareGoing = 1;
  11374. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11375. sleep(1);
  11376. }
  11377. else
  11378. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11379. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11380. return result;
  11381. }
  11382. void *UpdateFirmwareProcess(void *data)
  11383. {
  11384. pthread_detach(pthread_self());
  11385. mtrace();
  11386. int retriesInt =0, retryIntervalInt=0;
  11387. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11388. int port=0;
  11389. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11390. int isSuccess = 0;
  11391. char ftpbuf[512];
  11392. char temp[100];
  11393. char * pch;
  11394. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11395. json_object *UpdateFirmware;
  11396. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11397. if(!is_error(UpdateFirmware))
  11398. {
  11399. // Required data
  11400. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11401. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11402. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11403. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11404. // Optional data
  11405. if(json_object_object_get(UpdateFirmware, "retries"))
  11406. {
  11407. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11408. }
  11409. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11410. {
  11411. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11412. }
  11413. }
  11414. json_object_put(UpdateFirmware);
  11415. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11416. memset(path, 0, ARRAY_SIZE(path));
  11417. // Wait retrieveData
  11418. if(strlen(retrieveDatestr) > 10)
  11419. {
  11420. do
  11421. {
  11422. sleep(1);
  11423. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11424. }
  11425. // Ready to download
  11426. system("rm -f /mnt/*");
  11427. if(strncmp(locationstr,"http", 4) == 0)
  11428. {
  11429. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11430. sprintf(ftppath,"/%s", path);
  11431. DEBUG_INFO("locationstr: %s\n", locationstr);
  11432. DEBUG_INFO("protocol: %s\n",protocol);
  11433. DEBUG_INFO("host: %s\n",host);
  11434. DEBUG_INFO("path: %s\n",path);
  11435. DEBUG_INFO("ftppath: %s\n",ftppath);
  11436. int ftppathlen=strlen(ftppath);
  11437. int i=1;
  11438. char filenametemp[50];
  11439. while(i < ftppathlen)
  11440. {
  11441. int len=ftppathlen-i;
  11442. if(ftppath[len]== 47) // '/' ascll code: 47
  11443. {
  11444. DEBUG_INFO("compare '/' all right\n");
  11445. break;
  11446. }
  11447. i=i+1;
  11448. }
  11449. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11450. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11451. filenametemp[i+1] = 0;
  11452. do
  11453. {
  11454. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11455. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11456. sleep(1);
  11457. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11458. if(!isSuccess)
  11459. {
  11460. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11461. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11462. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11463. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11464. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11465. }
  11466. else
  11467. {
  11468. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11469. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11470. }
  11471. retriesInt--;
  11472. }while((isSuccess == 0)&&(retriesInt >= 0));
  11473. }
  11474. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11475. {
  11476. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11477. memset(temp, 0, ARRAY_SIZE(temp));
  11478. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11479. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11480. int ftppathlen=strlen(ftpbuf);
  11481. int i=1;
  11482. char filenametemp[50];
  11483. while(i < ftppathlen)
  11484. {
  11485. int len=ftppathlen-i;
  11486. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11487. {
  11488. DEBUG_INFO(" compare '/' all right\n");
  11489. break;
  11490. }
  11491. i=i+1;
  11492. }
  11493. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11494. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11495. filenametemp[i+1] = 0;
  11496. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11497. pch=strchr(temp,'@');
  11498. if(pch==NULL)
  11499. {
  11500. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11501. protocol, host, &port, path);
  11502. strcpy(user,"anonymous");
  11503. strcpy(password,"");
  11504. }
  11505. else
  11506. {
  11507. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11508. protocol, user, password, host, &port, path);
  11509. }
  11510. sscanf(host,"%[^/]%s",host1, path1);
  11511. sprintf(ftppath,"%s", path1);
  11512. //DEBUG_INFO("protocol =%s\n",protocol);
  11513. //DEBUG_INFO("user =%s\n",user);
  11514. //DEBUG_INFO("password =%s\n",password);
  11515. //DEBUG_INFO("host1 =%s\n",host1);
  11516. //DEBUG_INFO("port =%d\n",port);
  11517. //DEBUG_INFO("path1 =%s\n",path1);
  11518. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11519. //ftpFile(host, user, password, port, ftppath, fname);
  11520. //download firmware pthred
  11521. if(port == 0)
  11522. {
  11523. port = 21;
  11524. }
  11525. do
  11526. {
  11527. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11528. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11529. sleep(1);
  11530. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11531. if(!isSuccess)
  11532. {
  11533. //BulldogUtil.sleepMs(interval*1000);
  11534. DEBUG_INFO("Update firmware request and download file fail.\n");
  11535. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11536. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11537. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11538. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11539. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11540. }
  11541. else
  11542. {
  11543. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11544. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11545. }
  11546. retriesInt--;
  11547. }while((!isSuccess)&&(retriesInt >= 0));
  11548. }
  11549. else
  11550. {
  11551. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11552. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11553. sleep(1);
  11554. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11555. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11556. }
  11557. // OCPPPH only, must announce CSU upgrade firmware
  11558. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11559. interLock.isUpdateFirmwareGoing = 0;
  11560. pthread_exit(NULL);
  11561. }
  11562. int handleCertificateSignedRequest(char *uuid, char *payload)
  11563. {
  11564. mtrace();
  11565. int result = PASS;
  11566. json_object *CertificateSigned;
  11567. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11568. CertificateSigned = json_tokener_parse(payload);
  11569. if(!is_error(CertificateSigned))
  11570. {
  11571. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11572. }
  11573. json_object_put(CertificateSigned);
  11574. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11575. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11576. fclose(fp);
  11577. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11578. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11579. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11580. sendCertificateSignedConfirmation(uuid);
  11581. return result;
  11582. }
  11583. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11584. {
  11585. mtrace();
  11586. int result = PASS;
  11587. json_object *DeleteCertificate;
  11588. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11589. DeleteCertificate = json_tokener_parse(payload);
  11590. if(!is_error(DeleteCertificate))
  11591. {
  11592. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11593. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11594. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11595. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11596. }
  11597. json_object_put(DeleteCertificate);
  11598. /*
  11599. * TODO: Delete certificateSigned process
  11600. */
  11601. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11602. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11603. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11604. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11605. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11606. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11607. sendDeleteCertificateConfirmation(uuid);
  11608. return result;
  11609. }
  11610. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11611. {
  11612. mtrace();
  11613. int result = PASS;
  11614. json_object *ExtendedTriggerMessage;
  11615. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11616. ExtendedTriggerMessage = json_tokener_parse(payload);
  11617. if(!is_error(ExtendedTriggerMessage))
  11618. {
  11619. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11620. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11621. {
  11622. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11623. }
  11624. else
  11625. {
  11626. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11627. }
  11628. }
  11629. json_object_put(ExtendedTriggerMessage);
  11630. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11631. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11632. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11633. {
  11634. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11635. }
  11636. else
  11637. {
  11638. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11639. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11640. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11641. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11642. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11643. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11644. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11645. {
  11646. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11647. }
  11648. else
  11649. {
  11650. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11651. }
  11652. }
  11653. sendExtendedTriggerMessageConfirmation(uuid);
  11654. //==========================
  11655. // Trigger message
  11656. //==========================
  11657. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11658. {
  11659. //sendBootNotificationRequest();
  11660. server_sign = FALSE;
  11661. }
  11662. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11663. {
  11664. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11665. }
  11666. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11667. {
  11668. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11669. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11670. {
  11671. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11672. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11673. }
  11674. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11675. }
  11676. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11677. {
  11678. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11679. }
  11680. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11681. {
  11682. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11683. {
  11684. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11685. }
  11686. else
  11687. {
  11688. for(int idx=0;idx< gunTotalNumber;idx++)
  11689. {
  11690. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11691. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11692. }
  11693. }
  11694. }
  11695. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11696. {
  11697. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11698. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11699. {
  11700. 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\" &");
  11701. }
  11702. }
  11703. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11704. {
  11705. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11706. {
  11707. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11708. }
  11709. else
  11710. {
  11711. for(int idx=0;idx< gunTotalNumber;idx++)
  11712. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11713. }
  11714. }
  11715. return result;
  11716. }
  11717. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11718. {
  11719. mtrace();
  11720. int result = PASS;
  11721. json_object *GetInstalledCertificateIds;
  11722. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11723. GetInstalledCertificateIds = json_tokener_parse(payload);
  11724. if(!is_error(GetInstalledCertificateIds))
  11725. {
  11726. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11727. }
  11728. json_object_put(GetInstalledCertificateIds);
  11729. /*
  11730. * TODO: Return installed certificate process
  11731. */
  11732. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11733. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11734. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11735. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11736. sendGetInstalledCertificateIdsConfirmation(uuid);
  11737. return result;
  11738. }
  11739. int handleGetLogRequest(char *uuid, char *payload)
  11740. {
  11741. mtrace();
  11742. int result = PASS;
  11743. json_object *GetLog;
  11744. DEBUG_INFO("handleGetLogRequest...\n");
  11745. GetLog = json_tokener_parse(payload);
  11746. if(!is_error(GetLog))
  11747. {
  11748. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11749. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11750. if(json_object_object_get(GetLog, "retries") != NULL)
  11751. {
  11752. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11753. }
  11754. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11755. {
  11756. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11757. }
  11758. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11759. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11760. {
  11761. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11762. }
  11763. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11764. {
  11765. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11766. }
  11767. }
  11768. json_object_put(GetLog);
  11769. /*
  11770. * TODO: Upload log process
  11771. */
  11772. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11773. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11774. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11775. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11776. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11777. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11778. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11779. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11780. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11781. sendGetLogConfirmation(uuid);
  11782. return result;
  11783. }
  11784. int handleInstallCertificateRequest(char *uuid, char *payload)
  11785. {
  11786. mtrace();
  11787. int result = PASS;
  11788. json_object *InstallCertificate;
  11789. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11790. InstallCertificate = json_tokener_parse(payload);
  11791. if(!is_error(InstallCertificate))
  11792. {
  11793. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11794. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11795. /*
  11796. * TODO: Install certificate process
  11797. */
  11798. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11799. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11800. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11801. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11802. sendInstallCertificateConfirmation(uuid);
  11803. }
  11804. json_object_put(InstallCertificate);
  11805. return result;
  11806. }
  11807. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11808. {
  11809. mtrace();
  11810. int result = PASS;
  11811. json_object *SignedUpdateFirmware;
  11812. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11813. SignedUpdateFirmware = json_tokener_parse(payload);
  11814. if(!is_error(SignedUpdateFirmware))
  11815. {
  11816. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11817. {
  11818. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11819. }
  11820. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11821. {
  11822. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11823. }
  11824. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11825. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11826. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11827. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11828. {
  11829. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11830. }
  11831. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11832. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11833. }
  11834. json_object_put(SignedUpdateFirmware);
  11835. /*
  11836. * TODO: Upgrade firmware process
  11837. */
  11838. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11839. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11840. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11841. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11842. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11843. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11844. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11845. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11846. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11847. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11848. sendInstallCertificateConfirmation(uuid);
  11849. return result;
  11850. }
  11851. int handleUnknownRequest(char *uuid, char *payload)
  11852. {
  11853. mtrace();
  11854. int result = PASS;
  11855. DEBUG_INFO("handleUnknownRequest...\n");
  11856. sendUnknownConfirmation(uuid);
  11857. result = PASS;
  11858. return result;
  11859. }
  11860. //==========================================
  11861. // Handle server response routine
  11862. //==========================================
  11863. void handleAuthorizeResponse(char *payload, int gun_index)
  11864. {
  11865. mtrace();
  11866. char expiryDatestr[30]={0};
  11867. char parentIdTagstr[20]={0};
  11868. char statusstr[20]={0};
  11869. int expiryDateISNULL=FALSE;
  11870. int parentIdTagISNULL=FALSE;
  11871. DEBUG_INFO("handleAuthorizeResponse...\n");
  11872. json_object *Authorize;
  11873. Authorize = json_tokener_parse(payload);
  11874. if(!is_error(Authorize))
  11875. {
  11876. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11877. {
  11878. // Required data
  11879. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11880. // Optional data
  11881. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11882. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11883. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11884. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11885. }
  11886. }
  11887. json_object_put(Authorize);
  11888. if(expiryDateISNULL == FALSE)
  11889. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11890. if(parentIdTagISNULL == FALSE)
  11891. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11892. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11893. //Update idTag information to authorization cache if supproted
  11894. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11895. {
  11896. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11897. }
  11898. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11899. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11900. authorizeRetryTimes = 0;
  11901. }
  11902. void handleBootNotificationResponse(char *payload, int gun_index)
  11903. {
  11904. mtrace();
  11905. char statusStr[12]={0};
  11906. char currentTimeStr[30]={0};
  11907. int intervalInt = 0;
  11908. DEBUG_INFO("handleBootNotificationResponse...\n");
  11909. json_object *BootNotification;
  11910. BootNotification = json_tokener_parse(payload);
  11911. if(!is_error(BootNotification))
  11912. {
  11913. // Required data
  11914. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11915. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11916. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11917. }
  11918. json_object_put(BootNotification);
  11919. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11920. BootNotificationInterval = intervalInt;
  11921. HeartBeatWaitTime = intervalInt;
  11922. //write back to ShmOCPP16DataPH->BootNotification
  11923. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11924. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11925. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11926. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11927. {
  11928. server_sign = TRUE;
  11929. server_pending =FALSE;
  11930. }
  11931. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11932. {
  11933. server_pending = TRUE;
  11934. }
  11935. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11936. srand(time(NULL));
  11937. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11938. SetOcppConnStatus(TRUE);
  11939. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11940. }
  11941. void handleDataTransferResponse(char *payload, int gun_index)
  11942. {
  11943. char sstr[160]={0};//sstr[200]={ 0 };
  11944. int c = 0;
  11945. char *loc;
  11946. DEBUG_INFO("handleDataTransferResponse ...\n");
  11947. loc = strstr(payload, "status");
  11948. c = 0;
  11949. while (loc[3+strlen("status")+c] != '\"')
  11950. {
  11951. sstr[c] = loc[3+strlen("status")+c];
  11952. c++;
  11953. }
  11954. sstr[c] = '\0';
  11955. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11956. }
  11957. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11958. {
  11959. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11960. //struct json_object *obj;
  11961. // obj = json_tokener_parse(payload);
  11962. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11963. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11964. //No fields are defined.
  11965. }
  11966. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11967. {
  11968. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11969. //struct json_object *obj;
  11970. // obj = json_tokener_parse(payload);
  11971. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11972. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11973. //No fields are defined.
  11974. }
  11975. void handleHeartbeatResponse(char *payload, int gun_index)
  11976. {
  11977. mtrace();
  11978. DEBUG_INFO("handleHeartbeatResponse...\n");
  11979. json_object *Heartbeat;
  11980. Heartbeat = json_tokener_parse(payload);
  11981. if(!is_error(Heartbeat))
  11982. {
  11983. // Required data
  11984. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11985. }
  11986. json_object_put(Heartbeat);
  11987. if(FirstHeartBeat == 0)
  11988. {
  11989. FirstHeartBeat = 1;
  11990. DEBUG_INFO("FirstHeartBeat \n");
  11991. }
  11992. HeartBeatWithNOResponse = 0;
  11993. clientTime.Heartbeat=time((time_t*)NULL);
  11994. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11995. }
  11996. void handleMeterValuesResponse(char *payload, int gun_index)
  11997. {
  11998. mtrace();
  11999. DEBUG_INFO("handleMeterValuesResponse...\n");
  12000. }
  12001. void handleStartTransactionResponse(char *payload, int gun_index)
  12002. {
  12003. mtrace();
  12004. //int transactionIdInt = 0;
  12005. FILE *outfile;
  12006. char data[100]={0};
  12007. DEBUG_INFO("handleStartTransactionResponse...\n");
  12008. json_object *StartTransaction;
  12009. StartTransaction = json_tokener_parse(payload);
  12010. if(!is_error(StartTransaction))
  12011. {
  12012. // Required data
  12013. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12014. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12015. // Optional data
  12016. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12017. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12018. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12019. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12020. }
  12021. json_object_put(StartTransaction);
  12022. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12023. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12024. //-----------Start : write to the Queue TransactionId file -----------------//
  12025. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12026. {}
  12027. else
  12028. {
  12029. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12030. if(log == NULL)
  12031. {
  12032. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12033. return ;
  12034. }
  12035. else
  12036. {
  12037. fclose(log);
  12038. }
  12039. }
  12040. // open file for writing
  12041. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12042. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12043. {
  12044. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12045. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12046. fputs(data, outfile);
  12047. fclose (outfile);
  12048. }
  12049. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12050. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12051. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12052. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12053. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12054. }
  12055. void handleStatusNotificationResponse(char *payload, int gun_index)
  12056. {
  12057. mtrace();
  12058. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12059. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12060. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12061. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12062. }
  12063. void handleStopTransactionnResponse(char *payload, int gun_index)
  12064. {
  12065. mtrace();
  12066. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12067. json_object *StopTransaction;
  12068. StopTransaction = json_tokener_parse(payload);
  12069. if(!is_error(StopTransaction))
  12070. {
  12071. // Optional data
  12072. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12073. {
  12074. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12075. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12076. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12077. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12078. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12079. }
  12080. }
  12081. json_object_put(StopTransaction);
  12082. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12083. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12084. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12085. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12086. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12087. }
  12088. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12089. {
  12090. mtrace();
  12091. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12092. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12093. }
  12094. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12095. {
  12096. mtrace();
  12097. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12098. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12099. }
  12100. void handleSignCertificateResponse(char *payload, int gun_index)
  12101. {
  12102. mtrace();
  12103. DEBUG_INFO("handleSignCertificateResponse...\n");
  12104. json_object *SignCertificate;
  12105. SignCertificate = json_tokener_parse(payload);
  12106. if(!is_error(SignCertificate))
  12107. {
  12108. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12109. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12110. }
  12111. json_object_put(SignCertificate);
  12112. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12113. }
  12114. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12115. {
  12116. mtrace();
  12117. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12118. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12119. }
  12120. //==========================================
  12121. // Handle Error routine
  12122. //==========================================
  12123. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12124. {
  12125. mtrace();
  12126. #ifdef SystemLogMessage
  12127. DEBUG_INFO("errorCode: %s\n", errorCode);
  12128. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12129. DEBUG_INFO("errorDetails: %s\n", payload);
  12130. #endif
  12131. }
  12132. //===============================================
  12133. // Common routine
  12134. //===============================================
  12135. int initialConfigurationTable(void)
  12136. {
  12137. //clock_t start_t, end_t, total_t;
  12138. FILE *fp;
  12139. FILE *outfile;
  12140. char str[512]={0};
  12141. char sstr[256]={0};
  12142. int c = 0;
  12143. char *loc;
  12144. int confVersion = 8;
  12145. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12146. //start_t = clock();
  12147. //printf("Starting of the program, start_t = %ld\n", start_t);
  12148. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12149. // Check configuration file size is correct
  12150. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12151. {
  12152. struct stat st;
  12153. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12154. if(st.st_size < 3100)
  12155. {
  12156. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12157. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12158. }
  12159. }
  12160. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12161. {
  12162. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12163. if(outfile == NULL)
  12164. {
  12165. DEBUG_INFO("Error opening file\n");
  12166. return FALSE;
  12167. }
  12168. /*Core Profile*/
  12169. //AllowOfflineTxForUnknownId
  12170. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12174. //AuthorizationCacheEnabled
  12175. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12179. //AuthorizeRemoteTxRequests
  12180. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12184. //BlinkRepeat
  12185. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12189. //ClockAlignedDataInterval
  12190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12194. //ConnectionTimeOut
  12195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12199. //GetConfigurationMaxKeys
  12200. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12202. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12204. // HeartbeatInterval
  12205. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12209. // LightIntensity
  12210. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12214. // LocalAuthorizeOffline
  12215. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12219. // LocalPreAuthorize
  12220. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12224. // MaxEnergyOnInvalidId
  12225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12229. // MeterValuesAlignedData
  12230. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12233. 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" );
  12234. else
  12235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12237. // MeterValuesAlignedDataMaxLength
  12238. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12242. else
  12243. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12245. // MeterValuesSampledData
  12246. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12249. 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" );
  12250. else
  12251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12253. // MeterValuesSampledDataMaxLength
  12254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12256. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12257. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12258. else
  12259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12261. // MeterValueSampleInterval
  12262. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12266. // MinimumStatusDuration
  12267. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12270. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12272. // NumberOfConnectors
  12273. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12276. {
  12277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12278. }
  12279. else
  12280. {
  12281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12282. }
  12283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12284. // ResetRetries
  12285. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12286. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12289. // ConnectorPhaseRotation
  12290. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12294. // ConnectorPhaseRotationMaxLength
  12295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12299. // StopTransactionOnEVSideDisconnect
  12300. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12304. // StopTransactionOnInvalidId
  12305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12309. // StopTxnAlignedData
  12310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12314. // StopTxnAlignedDataMaxLength
  12315. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12319. // StopTxnSampledData
  12320. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12324. else
  12325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12327. // StopTxnSampledDataMaxLength
  12328. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12329. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12331. {
  12332. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12333. }
  12334. else
  12335. {
  12336. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12337. }
  12338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12339. // SupportedFeatureProfiles
  12340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12344. // SupportedFeatureProfilesMaxLength
  12345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12349. // TransactionMessageAttempts
  12350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12353. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12355. // TransactionMessageRetryInterval
  12356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12359. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12361. // UnlockConnectorOnEVSideDisconnect
  12362. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12366. // WebSocketPingInterval
  12367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12371. // QueueOffLineMeterValues
  12372. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12376. // AuthorizationKey
  12377. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12381. // SecurityProfile
  12382. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12384. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12386. // DefaultPrice
  12387. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12391. // CustomDisplayCostAndPrice
  12392. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12396. // CustomIdleFeeAfterStop
  12397. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12401. // Configuration Version
  12402. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12404. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12406. //* Local Auth List Management Profile*/
  12407. #if 0
  12408. //For OCTT Test Case
  12409. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12410. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12412. #endif
  12413. #if 1
  12414. //LocalAuthListEnabled
  12415. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12419. #endif
  12420. //LocalAuthListMaxLength
  12421. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12425. //SendLocalListMaxLength
  12426. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12430. //ReserveConnectorZeroSupported
  12431. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12435. //* Smart Charging Profile */
  12436. //ChargeProfileMaxStackLevel
  12437. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12439. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12441. // ChargingScheduleAllowedChargingRateUnit
  12442. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12444. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12446. // ChargingScheduleMaxPeriods
  12447. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12449. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12451. // ConnectorSwitch3to1PhaseSupported
  12452. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12453. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12454. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12456. // MaxChargingProfilesInstalled
  12457. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12459. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12461. fclose(outfile);
  12462. }
  12463. else
  12464. {
  12465. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12466. char keystr[60]={0};
  12467. char readonlystr[10]={0};
  12468. char valuestr[256]={0};
  12469. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12470. if(fp == NULL) {
  12471. DEBUG_INFO("Error opening file");
  12472. return FALSE;
  12473. }
  12474. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12475. {
  12476. //DEBUG_INFO("Get Configuration \n");
  12477. if(strlen(str) > 0)
  12478. {
  12479. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12480. //*************************key*********************************/
  12481. if(strstr(str, "key") != NULL)
  12482. {
  12483. loc = strstr(str, "key");
  12484. c = 0;
  12485. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12486. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12487. {
  12488. sstr[c] = loc[strlen("key")+3+c];
  12489. c++;
  12490. }
  12491. sstr[c] = '\0';
  12492. strcpy(keystr,sstr);
  12493. }
  12494. //*************************readonly*********************************/
  12495. if(strstr(str, "readonly") != NULL)
  12496. {
  12497. loc = strstr(str, "readonly");
  12498. c = 0;
  12499. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12500. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12501. {
  12502. sstr[c] = loc[strlen("readonly")+2+c];
  12503. c++;
  12504. }
  12505. sstr[c] = '\0';
  12506. strcpy(readonlystr,sstr);
  12507. }
  12508. //*************************value*********************************/
  12509. if(strstr(str, "value") != NULL)
  12510. {
  12511. loc = strstr(str, "value");
  12512. c = 0;
  12513. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12514. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12515. {
  12516. sstr[c] = loc[strlen("value")+3+c];
  12517. c++;
  12518. }
  12519. sstr[c] = '\0';
  12520. strcpy(valuestr,sstr);
  12521. }
  12522. // DEBUG_INFO("keystr=%s\n",keystr);
  12523. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12524. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12525. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12526. {
  12527. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12530. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12531. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12532. }
  12533. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12534. {
  12535. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12536. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12538. }
  12539. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12540. {
  12541. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12543. }
  12544. if(strcmp(keystr, "BlinkRepeat") == 0)
  12545. {
  12546. //Charger.BlinkRepeat = Integer.parseInt(value);
  12547. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12548. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12549. }
  12550. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12551. {
  12552. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12553. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12554. }
  12555. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12556. {
  12557. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12559. }
  12560. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12561. {
  12562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12563. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12564. }
  12565. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12566. {
  12567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12569. HeartBeatWaitTime = atoi(valuestr);
  12570. }
  12571. if(strcmp(keystr, "LightIntensity") == 0)
  12572. {
  12573. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12574. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12575. }
  12576. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12577. {
  12578. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12579. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12580. }
  12581. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12582. {
  12583. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12584. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12585. }
  12586. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12587. {
  12588. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12589. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12590. }
  12591. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12592. {
  12593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12594. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12595. }
  12596. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12597. {
  12598. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12599. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12600. }
  12601. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12602. {
  12603. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12604. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12605. }
  12606. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12607. {
  12608. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12609. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12610. }
  12611. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12612. {
  12613. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12614. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12615. }
  12616. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12617. {
  12618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12620. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12621. }
  12622. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12623. {
  12624. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12625. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12626. }
  12627. if(strcmp(keystr, "ResetRetries") == 0)
  12628. {
  12629. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12630. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12631. }
  12632. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12633. {
  12634. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12635. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12636. }
  12637. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12638. {
  12639. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12641. }
  12642. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12643. {
  12644. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12645. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12646. }
  12647. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12648. {
  12649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12650. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12651. }
  12652. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12653. {
  12654. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12655. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12656. }
  12657. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12658. {
  12659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12661. }
  12662. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12663. {
  12664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12665. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12666. }
  12667. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12668. {
  12669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12671. }
  12672. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12673. {
  12674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12676. }
  12677. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12678. {
  12679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12681. }
  12682. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12683. {
  12684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12686. TransactionMessageAttemptsValue = atoi(valuestr);
  12687. }
  12688. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12689. {
  12690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12691. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12692. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12693. }
  12694. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12695. {
  12696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12697. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12698. }
  12699. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12700. {
  12701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12703. }
  12704. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12705. {
  12706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12707. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12708. }
  12709. if(strcmp(keystr, "AuthorizationKey") == 0)
  12710. {
  12711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12712. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12713. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12714. }
  12715. if(strcmp(keystr, "SecurityProfile") == 0)
  12716. {
  12717. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12718. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12720. }
  12721. if(strcmp(keystr, "DefaultPrice") == 0)
  12722. {
  12723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12725. }
  12726. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12727. {
  12728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12729. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12730. }
  12731. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12732. {
  12733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12735. }
  12736. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12737. {
  12738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12739. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12740. }
  12741. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12742. {
  12743. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12745. }
  12746. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12747. {
  12748. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12750. }
  12751. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12752. {
  12753. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12755. }
  12756. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12757. {
  12758. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12759. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12760. }
  12761. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12762. {
  12763. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12765. }
  12766. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12767. {
  12768. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12769. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12770. }
  12771. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12772. {
  12773. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12775. }
  12776. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12777. {
  12778. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12780. }
  12781. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12782. {
  12783. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12785. }
  12786. }
  12787. }
  12788. fclose(fp);
  12789. }
  12790. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12791. {
  12792. return PASS;
  12793. }
  12794. else
  12795. {
  12796. return FAIL;
  12797. }
  12798. }
  12799. void StoreConfigurationTable(void)
  12800. {
  12801. FILE *outfile;
  12802. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12803. if(outfile == NULL)
  12804. {
  12805. DEBUG_INFO("Error opening file");
  12806. return ;
  12807. }
  12808. /*Core Profile*/
  12809. //AllowOfflineTxForUnknownId
  12810. /*
  12811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12812. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12815. */
  12816. //DEBUG_INFO("data=%s\n",data);
  12817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12818. //AuthorizationCacheEnabled
  12819. /*
  12820. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12823. */
  12824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12825. //AuthorizeRemoteTxRequests
  12826. /*
  12827. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12828. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12830. */
  12831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12832. //BlinkRepeat
  12833. /*
  12834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12837. */
  12838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12839. //ClockAlignedDataInterval
  12840. /*
  12841. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12842. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12843. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12844. */
  12845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12846. //ConnectionTimeOut
  12847. /*
  12848. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12849. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12851. */
  12852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12853. //GetConfigurationMaxKeys
  12854. /*
  12855. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12858. */
  12859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12860. // HeartbeatInterval
  12861. /*
  12862. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12863. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12865. */
  12866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12867. // LightIntensity
  12868. /*
  12869. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12872. */
  12873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12874. // LocalAuthorizeOffline
  12875. /*
  12876. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12878. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12879. */
  12880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12881. // LocalPreAuthorize
  12882. /*
  12883. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12886. */
  12887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12888. // MaxEnergyOnInvalidId
  12889. /*
  12890. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12893. */
  12894. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12896. // MeterValuesAlignedData
  12897. /*
  12898. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12899. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12901. */
  12902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12903. // MeterValuesAlignedDataMaxLength
  12904. /*
  12905. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12908. */
  12909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12910. // MeterValuesSampledData
  12911. /*
  12912. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12915. */
  12916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12917. // MeterValuesSampledDataMaxLength
  12918. /*
  12919. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12922. */
  12923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12924. // MeterValueSampleInterval
  12925. /*
  12926. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12929. */
  12930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12931. // MinimumStatusDuration
  12932. /*
  12933. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12934. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12936. */
  12937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12938. // NumberOfConnectors
  12939. /*
  12940. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12943. {
  12944. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12945. }
  12946. else
  12947. {
  12948. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12949. }
  12950. */
  12951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12952. // ResetRetries
  12953. /*
  12954. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12957. */
  12958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12959. // ConnectorPhaseRotation
  12960. /*
  12961. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12964. */
  12965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12966. // ConnectorPhaseRotationMaxLength
  12967. /*
  12968. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12971. */
  12972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12973. // StopTransactionOnEVSideDisconnect
  12974. /*
  12975. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12978. */
  12979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12980. // StopTransactionOnInvalidId
  12981. /*
  12982. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12985. */
  12986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12987. // StopTxnAlignedData
  12988. /*
  12989. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12992. */
  12993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12994. // StopTxnAlignedDataMaxLength
  12995. /*
  12996. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12999. */
  13000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13001. // StopTxnSampledData
  13002. /*
  13003. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13004. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13006. */
  13007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13008. // StopTxnSampledDataMaxLength
  13009. /*
  13010. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13013. */
  13014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13015. // SupportedFeatureProfiles
  13016. /*
  13017. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13018. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13020. */
  13021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13022. // SupportedFeatureProfilesMaxLength
  13023. /*
  13024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13027. */
  13028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13029. // TransactionMessageAttempts
  13030. /*
  13031. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13032. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13034. */
  13035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13036. // TransactionMessageRetryInterval
  13037. /*
  13038. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13041. */
  13042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13043. // UnlockConnectorOnEVSideDisconnect
  13044. /*
  13045. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13046. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13048. */
  13049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13050. // WebSocketPingInterval
  13051. /*
  13052. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13055. */
  13056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13057. // QueueOffLineMeterValues
  13058. /*
  13059. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13060. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13062. */
  13063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13064. // AuthorizationKey
  13065. /*
  13066. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13069. */
  13070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13071. // SecurityProfile
  13072. /*
  13073. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13074. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13075. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13076. */
  13077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13078. // DefaultPrice
  13079. /*
  13080. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13081. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13083. */
  13084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13085. // CustomDisplayCostAndPrice
  13086. /*
  13087. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13090. */
  13091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13092. // CustomIdleFeeAfterStop
  13093. /*
  13094. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13097. */
  13098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13099. // ConfigurationVersion
  13100. /*
  13101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13104. */
  13105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13106. //* Local Auth List Management Profile*/
  13107. //LocalAuthListEnabled
  13108. /*
  13109. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13112. */
  13113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13114. //LocalAuthListMaxLength
  13115. /*
  13116. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13119. */
  13120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13121. //SendLocalListMaxLength
  13122. /*
  13123. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13126. */
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13128. //ReserveConnectorZeroSupported
  13129. /*
  13130. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13133. */
  13134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13135. //* Smart Charging Profile */
  13136. //ChargeProfileMaxStackLevel
  13137. /*
  13138. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13141. */
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13143. // ChargingScheduleAllowedChargingRateUnit
  13144. /*
  13145. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13148. */
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13150. // ChargingScheduleMaxPeriods
  13151. /*
  13152. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13155. */
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13157. // ConnectorSwitch3to1PhaseSupported
  13158. /*
  13159. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13162. */
  13163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13164. // MaxChargingProfilesInstalled
  13165. /*
  13166. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13169. */
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13171. fclose(outfile);
  13172. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13173. }
  13174. void getKeyValue(char *keyReq)
  13175. {
  13176. int isEmpty = FALSE;
  13177. int isKnowKey = FALSE;
  13178. DEBUG_INFO("keyReq = %s\n", keyReq);
  13179. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13180. isEmpty = TRUE;
  13181. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13182. {
  13183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13185. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13186. {
  13187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13188. }
  13189. else
  13190. {
  13191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13192. }
  13193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13194. isKnowKey = TRUE;
  13195. }
  13196. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13197. {
  13198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13200. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13201. {
  13202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13203. }
  13204. else
  13205. {
  13206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13207. }
  13208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13209. isKnowKey = TRUE;
  13210. }
  13211. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13212. {
  13213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13215. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13216. {
  13217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13218. }
  13219. else
  13220. {
  13221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13222. }
  13223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13224. isKnowKey = TRUE;
  13225. }
  13226. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13227. {
  13228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13230. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13231. {
  13232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13233. }
  13234. else
  13235. {
  13236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13237. }
  13238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13239. isKnowKey = TRUE;
  13240. }
  13241. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13242. {
  13243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13245. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13246. {
  13247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13248. }
  13249. else
  13250. {
  13251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13252. }
  13253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13254. isKnowKey = TRUE;
  13255. }
  13256. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13257. {
  13258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13260. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13261. {
  13262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13263. }
  13264. else
  13265. {
  13266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13267. }
  13268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13269. isKnowKey = TRUE;
  13270. }
  13271. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13272. {
  13273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13275. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13276. {
  13277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13278. }
  13279. else
  13280. {
  13281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13282. }
  13283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13284. isKnowKey = TRUE;
  13285. }
  13286. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13287. {
  13288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13290. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13291. {
  13292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13293. }
  13294. else
  13295. {
  13296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13297. }
  13298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13299. isKnowKey = TRUE;
  13300. }
  13301. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13302. {
  13303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13305. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13306. {
  13307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13308. }
  13309. else
  13310. {
  13311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13312. }
  13313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13314. isKnowKey = TRUE;
  13315. }
  13316. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13317. {
  13318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13320. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13321. {
  13322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13323. }
  13324. else
  13325. {
  13326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13327. }
  13328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13329. isKnowKey = TRUE;
  13330. }
  13331. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13332. {
  13333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13335. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13336. {
  13337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13338. }
  13339. else
  13340. {
  13341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13342. }
  13343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13344. isKnowKey = TRUE;
  13345. }
  13346. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13347. {
  13348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13350. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13351. {
  13352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13353. }
  13354. else
  13355. {
  13356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13357. }
  13358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13359. isKnowKey = TRUE;
  13360. }
  13361. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13362. {
  13363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13365. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13366. {
  13367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13368. }
  13369. else
  13370. {
  13371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13372. }
  13373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13374. isKnowKey = TRUE;
  13375. }
  13376. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13377. {
  13378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13380. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13381. {
  13382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13383. }
  13384. else
  13385. {
  13386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13387. }
  13388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13389. isKnowKey = TRUE;
  13390. }
  13391. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13392. {
  13393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13395. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13396. {
  13397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13398. }
  13399. else
  13400. {
  13401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13402. }
  13403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13404. isKnowKey = TRUE;
  13405. }
  13406. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13407. {
  13408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13410. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13411. {
  13412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13413. }
  13414. else
  13415. {
  13416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13417. }
  13418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13419. isKnowKey = TRUE;
  13420. }
  13421. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13422. {
  13423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13425. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13426. {
  13427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13428. }
  13429. else
  13430. {
  13431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13432. }
  13433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13434. isKnowKey = TRUE;
  13435. }
  13436. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13437. {
  13438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13440. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13441. {
  13442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13443. }
  13444. else
  13445. {
  13446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13447. }
  13448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13449. isKnowKey = TRUE;
  13450. }
  13451. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13452. {
  13453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13455. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13456. {
  13457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13458. }
  13459. else
  13460. {
  13461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13462. }
  13463. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13465. isKnowKey = TRUE;
  13466. }
  13467. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13468. {
  13469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13471. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13472. {
  13473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13474. }
  13475. else
  13476. {
  13477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13478. }
  13479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13480. isKnowKey = TRUE;
  13481. }
  13482. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13483. {
  13484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13486. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13487. {
  13488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13489. }
  13490. else
  13491. {
  13492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13493. }
  13494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13495. isKnowKey = TRUE;
  13496. }
  13497. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13498. {
  13499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13501. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13502. {
  13503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13504. }
  13505. else
  13506. {
  13507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13508. }
  13509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13510. isKnowKey = TRUE;
  13511. }
  13512. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13513. {
  13514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13516. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13517. {
  13518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13519. }
  13520. else
  13521. {
  13522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13523. }
  13524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13525. isKnowKey = TRUE;
  13526. }
  13527. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13528. {
  13529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13531. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13532. {
  13533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13534. }
  13535. else
  13536. {
  13537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13538. }
  13539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13540. isKnowKey = TRUE;
  13541. }
  13542. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13543. {
  13544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13546. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13547. {
  13548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13549. }
  13550. else
  13551. {
  13552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13553. }
  13554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13555. isKnowKey = TRUE;
  13556. }
  13557. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13558. {
  13559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13561. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13562. {
  13563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13564. }
  13565. else
  13566. {
  13567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13568. }
  13569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13570. isKnowKey = TRUE;
  13571. }
  13572. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13573. {
  13574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13576. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13577. {
  13578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13579. }
  13580. else
  13581. {
  13582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13583. }
  13584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13585. isKnowKey = TRUE;
  13586. }
  13587. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13588. {
  13589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13591. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13592. {
  13593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13594. }
  13595. else
  13596. {
  13597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13598. }
  13599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13600. isKnowKey = TRUE;
  13601. }
  13602. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13603. {
  13604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13606. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13607. {
  13608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13609. }
  13610. else
  13611. {
  13612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13613. }
  13614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13615. isKnowKey = TRUE;
  13616. }
  13617. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13618. {
  13619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13621. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13622. {
  13623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13624. }
  13625. else
  13626. {
  13627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13628. }
  13629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13630. isKnowKey = TRUE;
  13631. }
  13632. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13633. {
  13634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13636. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13637. {
  13638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13639. }
  13640. else
  13641. {
  13642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13643. }
  13644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13645. isKnowKey = TRUE;
  13646. }
  13647. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13648. {
  13649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13651. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13652. {
  13653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13654. }
  13655. else
  13656. {
  13657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13658. }
  13659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13660. isKnowKey = TRUE;
  13661. }
  13662. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13663. {
  13664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13666. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13667. {
  13668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13669. }
  13670. else
  13671. {
  13672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13673. }
  13674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13675. isKnowKey = TRUE;
  13676. }
  13677. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13678. {
  13679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13681. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13682. {
  13683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13684. }
  13685. else
  13686. {
  13687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13688. }
  13689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13690. isKnowKey = TRUE;
  13691. }
  13692. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13693. {
  13694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13697. {
  13698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13699. }
  13700. else
  13701. {
  13702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13703. }
  13704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13705. isKnowKey = TRUE;
  13706. }
  13707. /*
  13708. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13709. {
  13710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13712. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13713. {
  13714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13715. }
  13716. else
  13717. {
  13718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13719. }
  13720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13721. isKnowKey = TRUE;
  13722. }*/
  13723. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13724. {
  13725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13727. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13728. {
  13729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13730. }
  13731. else
  13732. {
  13733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13734. }
  13735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13736. isKnowKey = TRUE;
  13737. }
  13738. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13739. {
  13740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13742. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13743. {
  13744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13745. }
  13746. else
  13747. {
  13748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13749. }
  13750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13751. isKnowKey = TRUE;
  13752. }
  13753. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13754. {
  13755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13757. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13758. {
  13759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13760. }
  13761. else
  13762. {
  13763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13764. }
  13765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13766. isKnowKey = TRUE;
  13767. }
  13768. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13769. {
  13770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13772. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13773. {
  13774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13775. }
  13776. else
  13777. {
  13778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13779. }
  13780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13781. isKnowKey = TRUE;
  13782. }
  13783. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13784. {
  13785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13787. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13788. {
  13789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13790. }
  13791. else
  13792. {
  13793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13794. }
  13795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13796. isKnowKey = TRUE;
  13797. }
  13798. #if 1
  13799. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13800. {
  13801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13803. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13804. {
  13805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13806. }
  13807. else
  13808. {
  13809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13810. }
  13811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13812. isKnowKey = TRUE;
  13813. }
  13814. #endif
  13815. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13816. {
  13817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13819. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13820. {
  13821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13822. }
  13823. else
  13824. {
  13825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13826. }
  13827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13828. isKnowKey = TRUE;
  13829. }
  13830. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13831. {
  13832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13834. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13835. {
  13836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13837. }
  13838. else
  13839. {
  13840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13841. }
  13842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13843. isKnowKey = TRUE;
  13844. }
  13845. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13846. {
  13847. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13849. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13850. {
  13851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13852. }
  13853. else
  13854. {
  13855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13856. }
  13857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13858. isKnowKey = TRUE;
  13859. }
  13860. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13861. {
  13862. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13864. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13865. {
  13866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13867. }
  13868. else
  13869. {
  13870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13871. }
  13872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13873. isKnowKey = TRUE;
  13874. }
  13875. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13876. {
  13877. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13879. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13880. {
  13881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13882. }
  13883. else
  13884. {
  13885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13886. }
  13887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13888. isKnowKey = TRUE;
  13889. }
  13890. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13891. {
  13892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13894. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13895. {
  13896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13897. }
  13898. else
  13899. {
  13900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13901. }
  13902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13903. isKnowKey = TRUE;
  13904. }
  13905. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13906. {
  13907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13909. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13910. {
  13911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13912. }
  13913. else
  13914. {
  13915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13916. }
  13917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13918. isKnowKey = TRUE;
  13919. }
  13920. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13921. {
  13922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13924. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13925. {
  13926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13927. }
  13928. else
  13929. {
  13930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13931. }
  13932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13933. isKnowKey = TRUE;
  13934. }
  13935. //=========================================================
  13936. if(!isEmpty && !isKnowKey)
  13937. {
  13938. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13939. strcpy(unknownkey[UnknownKeynum], keyReq);
  13940. UnknownKeynum = UnknownKeynum + 1;
  13941. }
  13942. }
  13943. void processUnkownKey(void)
  13944. {
  13945. DEBUG_INFO("processUnkownKey...\n");
  13946. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13947. for(int index=0; index < UnknownKeynum; index++)
  13948. {
  13949. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13950. {
  13951. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13952. }
  13953. }
  13954. }
  13955. int setKeyValue(char *key, char *value)
  13956. {
  13957. int isSuccess = NotSupported;
  13958. int check_ascii=0;
  13959. char str[256]={0};
  13960. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13961. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13962. {
  13963. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13964. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13965. {
  13966. strcpy(str, (const char*)value);
  13967. for(int i = 0; str[i]; i++){
  13968. str[i] = tolower(str[i]);
  13969. }
  13970. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13971. isSuccess = ConfigurationStatus_Accepted;
  13972. }
  13973. else
  13974. {
  13975. isSuccess = ConfigurationStatus_Rejected;
  13976. }
  13977. }
  13978. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13979. {
  13980. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13981. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13982. {
  13983. strcpy(str, (const char*)value);
  13984. for(int i = 0; str[i]; i++){
  13985. str[i] = tolower(str[i]);
  13986. }
  13987. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13988. isSuccess = ConfigurationStatus_Accepted;
  13989. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13990. }
  13991. else
  13992. {
  13993. isSuccess = ConfigurationStatus_Rejected;
  13994. }
  13995. }
  13996. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13997. {
  13998. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13999. {
  14000. strcpy(str, (const char*)value);
  14001. for(int i = 0; str[i]; i++)
  14002. {
  14003. str[i] = tolower(str[i]);
  14004. }
  14005. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14006. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14007. isSuccess = ConfigurationStatus_Accepted;
  14008. }
  14009. else
  14010. {
  14011. isSuccess = ConfigurationStatus_Rejected;
  14012. }
  14013. }
  14014. if(strcmp(key, "BlinkRepeat") == 0)
  14015. {
  14016. //Charger.BlinkRepeat = Integer.parseInt(value);
  14017. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14018. {
  14019. check_ascii = value[0];
  14020. if( (check_ascii < 48) || (check_ascii > 57) )
  14021. {
  14022. isSuccess = ConfigurationStatus_Rejected;
  14023. }
  14024. else
  14025. {
  14026. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14027. isSuccess = ConfigurationStatus_Accepted;
  14028. }
  14029. }
  14030. else
  14031. {
  14032. isSuccess = ConfigurationStatus_Rejected;
  14033. }
  14034. }
  14035. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14036. {
  14037. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14038. {
  14039. check_ascii = value[0];
  14040. if( (check_ascii < 48) || (check_ascii > 57) )
  14041. {
  14042. isSuccess = ConfigurationStatus_Rejected;
  14043. }
  14044. else
  14045. {
  14046. if((atoi(value) == 0) || (atoi(value) >= 10))
  14047. {
  14048. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14049. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14050. isSuccess = ConfigurationStatus_Accepted;
  14051. }
  14052. else
  14053. isSuccess = ConfigurationStatus_Rejected;
  14054. }
  14055. }
  14056. else
  14057. {
  14058. isSuccess = ConfigurationStatus_Rejected;
  14059. }
  14060. }
  14061. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14062. {
  14063. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14064. {
  14065. check_ascii = value[0];
  14066. if( (check_ascii < 48) || (check_ascii > 57) )
  14067. {
  14068. isSuccess = ConfigurationStatus_Rejected;
  14069. }
  14070. else
  14071. {
  14072. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14073. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14074. isSuccess = ConfigurationStatus_Accepted;
  14075. }
  14076. }
  14077. else
  14078. {
  14079. isSuccess = ConfigurationStatus_Rejected;
  14080. }
  14081. }
  14082. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14083. {
  14084. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14085. {
  14086. check_ascii = value[0];
  14087. if( (check_ascii < 48) || (check_ascii > 57) )
  14088. {
  14089. isSuccess = ConfigurationStatus_Rejected;
  14090. }
  14091. else
  14092. {
  14093. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14094. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14095. isSuccess = ConfigurationStatus_Accepted;
  14096. }
  14097. }
  14098. else
  14099. {
  14100. isSuccess = ConfigurationStatus_Rejected;
  14101. }
  14102. }
  14103. if(strcmp(key, "HeartbeatInterval") == 0)
  14104. {
  14105. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14106. {
  14107. check_ascii = value[0];
  14108. if( (check_ascii < 48) || (check_ascii > 57) )
  14109. {
  14110. isSuccess = ConfigurationStatus_Rejected;
  14111. }
  14112. else
  14113. {
  14114. if((atoi(value) == 0) || (atoi(value) >= 10))
  14115. {
  14116. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14117. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14118. HeartBeatWaitTime = atoi(value);
  14119. isSuccess = ConfigurationStatus_Accepted;
  14120. }
  14121. else
  14122. {
  14123. isSuccess = ConfigurationStatus_Rejected;
  14124. }
  14125. }
  14126. }
  14127. else
  14128. {
  14129. isSuccess = ConfigurationStatus_Rejected;
  14130. }
  14131. }
  14132. if(strcmp(key, "LightIntensity") == 0)
  14133. {
  14134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14135. {
  14136. check_ascii = value[0];
  14137. if( (check_ascii < 48) || (check_ascii > 57) )
  14138. {
  14139. isSuccess = ConfigurationStatus_Rejected;
  14140. }
  14141. else
  14142. {
  14143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14144. isSuccess = ConfigurationStatus_Accepted;
  14145. }
  14146. }
  14147. else
  14148. {
  14149. isSuccess = ConfigurationStatus_Rejected;
  14150. }
  14151. }
  14152. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14153. {
  14154. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14155. {
  14156. strcpy(str, (const char*)value);
  14157. for(int i = 0; str[i]; i++)
  14158. {
  14159. str[i] = tolower(str[i]);
  14160. }
  14161. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14162. isSuccess = ConfigurationStatus_Accepted;
  14163. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14164. }
  14165. else
  14166. {
  14167. isSuccess = ConfigurationStatus_Rejected;
  14168. }
  14169. }
  14170. if(strcmp(key, "LocalPreAuthorize") == 0)
  14171. {
  14172. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14173. {
  14174. strcpy(str, (const char*)value);
  14175. for(int i = 0; str[i]; i++)
  14176. {
  14177. str[i] = tolower(str[i]);
  14178. }
  14179. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14180. isSuccess = ConfigurationStatus_Accepted;
  14181. }
  14182. else
  14183. {
  14184. isSuccess = ConfigurationStatus_Rejected;
  14185. }
  14186. }
  14187. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14188. {
  14189. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14190. {
  14191. check_ascii = value[0];
  14192. if( (check_ascii < 48) || (check_ascii > 57) )
  14193. {
  14194. isSuccess = ConfigurationStatus_Rejected;
  14195. }
  14196. else
  14197. {
  14198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14199. isSuccess = ConfigurationStatus_Accepted;
  14200. }
  14201. }
  14202. else
  14203. {
  14204. isSuccess = ConfigurationStatus_Rejected;
  14205. }
  14206. }
  14207. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14208. {
  14209. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14210. {
  14211. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14212. isSuccess = ConfigurationStatus_Accepted;
  14213. }
  14214. else
  14215. {
  14216. isSuccess = ConfigurationStatus_Rejected;
  14217. }
  14218. }
  14219. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14220. {
  14221. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14222. {
  14223. check_ascii = value[0];
  14224. if( (check_ascii < 48) || (check_ascii > 57) )
  14225. {
  14226. isSuccess = ConfigurationStatus_Rejected;
  14227. }
  14228. else
  14229. {
  14230. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14231. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14232. isSuccess = ConfigurationStatus_Accepted;
  14233. }
  14234. }
  14235. else
  14236. {
  14237. isSuccess = ConfigurationStatus_Rejected;
  14238. }
  14239. }
  14240. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14241. {
  14242. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14243. {
  14244. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14245. isSuccess = ConfigurationStatus_Accepted;
  14246. }
  14247. else
  14248. {
  14249. isSuccess = ConfigurationStatus_Rejected;
  14250. }
  14251. }
  14252. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14253. {
  14254. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14255. {
  14256. check_ascii = value[0];
  14257. if( (check_ascii < 48) || (check_ascii > 57) )
  14258. {
  14259. isSuccess = ConfigurationStatus_Rejected;
  14260. }
  14261. else
  14262. {
  14263. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14264. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14265. isSuccess = ConfigurationStatus_Accepted;
  14266. }
  14267. }
  14268. else
  14269. {
  14270. isSuccess = ConfigurationStatus_Rejected;
  14271. }
  14272. }
  14273. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14274. {
  14275. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14276. {
  14277. check_ascii = value[0];
  14278. if( (check_ascii < 48) || (check_ascii > 57) )
  14279. {
  14280. isSuccess = ConfigurationStatus_Rejected;
  14281. }
  14282. else
  14283. {
  14284. if((atoi(value) == 0) || (atoi(value) >= 10))
  14285. {
  14286. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14288. isSuccess = ConfigurationStatus_Accepted;
  14289. }
  14290. else
  14291. {
  14292. isSuccess = ConfigurationStatus_Rejected;
  14293. }
  14294. }
  14295. }
  14296. else
  14297. {
  14298. isSuccess = ConfigurationStatus_Rejected;
  14299. }
  14300. }
  14301. if(strcmp(key, "MinimumStatusDuration") == 0)
  14302. {
  14303. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14304. {
  14305. check_ascii = value[0];
  14306. if( (check_ascii < 48) || (check_ascii > 57) )
  14307. {
  14308. isSuccess = ConfigurationStatus_Rejected;
  14309. }
  14310. else
  14311. {
  14312. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14313. {
  14314. isSuccess = ConfigurationStatus_Rejected;
  14315. }
  14316. else
  14317. {
  14318. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14319. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14320. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14321. isSuccess = ConfigurationStatus_Accepted;
  14322. }
  14323. }
  14324. }
  14325. else
  14326. {
  14327. isSuccess = ConfigurationStatus_Rejected;
  14328. }
  14329. }
  14330. if(strcmp(key, "NumberOfConnectors") == 0)
  14331. {
  14332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14333. {
  14334. check_ascii = value[0];
  14335. if( (check_ascii < 48) || (check_ascii > 57) )
  14336. {
  14337. isSuccess = ConfigurationStatus_Rejected;
  14338. }
  14339. else
  14340. {
  14341. //Charger.ResetRetries = Integer.parseInt(value);
  14342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14343. isSuccess = ConfigurationStatus_Accepted;
  14344. }
  14345. }
  14346. else
  14347. {
  14348. isSuccess = ConfigurationStatus_Rejected;
  14349. }
  14350. }
  14351. if(strcmp(key, "ResetRetries") == 0)
  14352. {
  14353. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14354. {
  14355. check_ascii = value[0];
  14356. if( (check_ascii < 48) || (check_ascii > 57) )
  14357. {
  14358. isSuccess = ConfigurationStatus_Rejected;
  14359. }
  14360. else
  14361. {
  14362. //Charger.ResetRetries = Integer.parseInt(value);
  14363. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14364. isSuccess = ConfigurationStatus_Accepted;
  14365. }
  14366. }
  14367. else
  14368. {
  14369. isSuccess = ConfigurationStatus_Rejected;
  14370. }
  14371. }
  14372. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14373. {
  14374. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14375. {
  14376. strcpy(str, (const char*)value);
  14377. for(int i = 0; str[i]; i++)
  14378. {
  14379. str[i] = tolower(str[i]);
  14380. }
  14381. if(strcmp(str, "notapplicable")== 0)
  14382. {
  14383. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14384. isSuccess = ConfigurationStatus_Accepted;
  14385. }
  14386. else if(strcmp(str, "unknown")== 0)
  14387. {
  14388. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14389. isSuccess = ConfigurationStatus_Accepted;
  14390. }
  14391. else if(strcmp(str, "rst")== 0)
  14392. {
  14393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14394. isSuccess = ConfigurationStatus_Accepted;
  14395. }
  14396. else if(strcmp(str, "rts")== 0)
  14397. {
  14398. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14399. isSuccess = ConfigurationStatus_Accepted;
  14400. }
  14401. else if(strcmp(str, "srt")== 0)
  14402. {
  14403. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14404. isSuccess = ConfigurationStatus_Accepted;
  14405. }
  14406. else if(strcmp(str, "str")== 0)
  14407. {
  14408. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14409. isSuccess = ConfigurationStatus_Accepted;
  14410. }
  14411. else if(strcmp(str, "trs")== 0)
  14412. {
  14413. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14414. isSuccess = ConfigurationStatus_Accepted;
  14415. }
  14416. else if(strcmp(str, "tsr")== 0)
  14417. {
  14418. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14419. isSuccess = ConfigurationStatus_Accepted;
  14420. }
  14421. else
  14422. {
  14423. isSuccess = ConfigurationStatus_Rejected;
  14424. }
  14425. }
  14426. else
  14427. {
  14428. isSuccess = ConfigurationStatus_Rejected;
  14429. }
  14430. }
  14431. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14432. {
  14433. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14434. {
  14435. check_ascii = value[0];
  14436. if( (check_ascii < 48) || (check_ascii > 57) )
  14437. {
  14438. isSuccess = ConfigurationStatus_Rejected;
  14439. }
  14440. else
  14441. {
  14442. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14443. isSuccess = ConfigurationStatus_Accepted;
  14444. }
  14445. }
  14446. else
  14447. {
  14448. isSuccess = ConfigurationStatus_Rejected;
  14449. }
  14450. }
  14451. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14452. {
  14453. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14454. {
  14455. strcpy(str, (const char*)value);
  14456. for(int i = 0; str[i]; i++)
  14457. {
  14458. str[i] = tolower(str[i]);
  14459. }
  14460. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14462. isSuccess = ConfigurationStatus_Accepted;
  14463. }
  14464. else
  14465. {
  14466. isSuccess = ConfigurationStatus_Rejected;
  14467. }
  14468. }
  14469. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14470. {
  14471. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14472. {
  14473. strcpy(str, (const char*)value);
  14474. for(int i = 0; str[i]; i++)
  14475. {
  14476. str[i] = tolower(str[i]);
  14477. }
  14478. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14479. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14480. isSuccess = ConfigurationStatus_Accepted;
  14481. }
  14482. else
  14483. {
  14484. isSuccess = ConfigurationStatus_Rejected;
  14485. }
  14486. }
  14487. if(strcmp(key, "StopTxnAlignedData") == 0)
  14488. {
  14489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14490. {
  14491. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14492. isSuccess = ConfigurationStatus_Accepted;
  14493. }
  14494. else
  14495. {
  14496. isSuccess = ConfigurationStatus_Rejected;
  14497. }
  14498. }
  14499. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14500. {
  14501. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14502. {
  14503. check_ascii = value[0];
  14504. if( (check_ascii < 48) || (check_ascii > 57) )
  14505. {
  14506. isSuccess = ConfigurationStatus_Rejected;
  14507. }
  14508. else
  14509. {
  14510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14511. isSuccess = ConfigurationStatus_Accepted;
  14512. }
  14513. }
  14514. else
  14515. {
  14516. isSuccess = ConfigurationStatus_Rejected;
  14517. }
  14518. }
  14519. if(strcmp(key, "StopTxnSampledData") == 0)
  14520. {
  14521. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14522. {
  14523. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14524. isSuccess = ConfigurationStatus_Accepted;
  14525. }
  14526. else
  14527. {
  14528. isSuccess = ConfigurationStatus_Rejected;
  14529. }
  14530. }
  14531. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14532. {
  14533. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14534. {
  14535. check_ascii = value[0];
  14536. if( (check_ascii < 48) || (check_ascii > 57) )
  14537. {
  14538. isSuccess = ConfigurationStatus_Rejected;
  14539. }
  14540. else
  14541. {
  14542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14543. isSuccess = ConfigurationStatus_Accepted;
  14544. }
  14545. }
  14546. else
  14547. {
  14548. isSuccess = ConfigurationStatus_Rejected;
  14549. }
  14550. }
  14551. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14552. {
  14553. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14554. {
  14555. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14556. isSuccess = ConfigurationStatus_Accepted;
  14557. }
  14558. else
  14559. {
  14560. isSuccess = ConfigurationStatus_Rejected;
  14561. }
  14562. }
  14563. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14564. {
  14565. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14566. {
  14567. check_ascii = value[0];
  14568. if( (check_ascii < 48) || (check_ascii > 57) )
  14569. {
  14570. isSuccess = ConfigurationStatus_Rejected;
  14571. }
  14572. else
  14573. {
  14574. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14575. isSuccess = ConfigurationStatus_Accepted;
  14576. }
  14577. }
  14578. else
  14579. {
  14580. isSuccess = ConfigurationStatus_Rejected;
  14581. }
  14582. }
  14583. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14584. {
  14585. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14586. {
  14587. check_ascii = value[0];
  14588. if( (check_ascii < 48) || (check_ascii > 57) )
  14589. {
  14590. isSuccess = ConfigurationStatus_Rejected;
  14591. }
  14592. else
  14593. {
  14594. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14595. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14596. TransactionMessageAttemptsValue = atoi(value);
  14597. isSuccess = ConfigurationStatus_Accepted;
  14598. }
  14599. }
  14600. else
  14601. {
  14602. isSuccess = ConfigurationStatus_Rejected;
  14603. }
  14604. }
  14605. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14606. {
  14607. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14608. {
  14609. check_ascii = value[0];
  14610. if( (check_ascii < 48) || (check_ascii > 57) )
  14611. {
  14612. isSuccess = ConfigurationStatus_Rejected;
  14613. }
  14614. else
  14615. {
  14616. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14617. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14618. TransactionMessageRetryIntervalValue = atoi(value);
  14619. isSuccess = ConfigurationStatus_Accepted;
  14620. }
  14621. }
  14622. else
  14623. {
  14624. isSuccess = ConfigurationStatus_Rejected;
  14625. }
  14626. }
  14627. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14628. {
  14629. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14630. {
  14631. strcpy(str, (const char*)value);
  14632. for(int i = 0; str[i]; i++)
  14633. {
  14634. str[i] = tolower(str[i]);
  14635. }
  14636. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14638. isSuccess = ConfigurationStatus_Accepted;
  14639. }
  14640. else
  14641. {
  14642. isSuccess = ConfigurationStatus_Rejected;
  14643. }
  14644. }
  14645. if(strcmp(key, "WebSocketPingInterval") == 0)
  14646. {
  14647. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14648. {
  14649. check_ascii = value[0];
  14650. if( (check_ascii < 48) || (check_ascii > 57) )
  14651. {
  14652. isSuccess = ConfigurationStatus_Rejected;
  14653. }
  14654. else
  14655. {
  14656. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14657. isSuccess = ConfigurationStatus_Accepted;
  14658. }
  14659. }
  14660. else
  14661. {
  14662. isSuccess = ConfigurationStatus_Rejected;
  14663. }
  14664. }
  14665. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14666. {
  14667. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14668. {
  14669. strcpy(str, (const char*)value);
  14670. for(int i = 0; str[i]; i++)
  14671. {
  14672. str[i] = tolower(str[i]);
  14673. }
  14674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14675. isSuccess = ConfigurationStatus_Accepted;
  14676. }
  14677. else
  14678. {
  14679. isSuccess = ConfigurationStatus_Rejected;
  14680. }
  14681. }
  14682. if(strcmp(key, "AuthorizationKey") == 0)
  14683. {
  14684. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14685. {
  14686. strcpy(str, (const char*)value);
  14687. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14688. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14689. isSuccess = ConfigurationStatus_Accepted;
  14690. }
  14691. else
  14692. {
  14693. isSuccess = ConfigurationStatus_Rejected;
  14694. }
  14695. }
  14696. if(strcmp(key, "SecurityProfile") == 0)
  14697. {
  14698. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14699. {
  14700. check_ascii = value[0];
  14701. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14702. {
  14703. isSuccess = ConfigurationStatus_Rejected;
  14704. }
  14705. else if(check_ascii == 0x33)
  14706. {
  14707. isSuccess = NotSupported;
  14708. }
  14709. else
  14710. {
  14711. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14712. {
  14713. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14714. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14715. isSuccess = ConfigurationStatus_Accepted;
  14716. }
  14717. else
  14718. isSuccess = ConfigurationStatus_Rejected;
  14719. }
  14720. }
  14721. else
  14722. {
  14723. isSuccess = ConfigurationStatus_Rejected;
  14724. }
  14725. }
  14726. if(strcmp(key, "DefaultPrice") == 0)
  14727. {
  14728. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14729. {
  14730. strcpy(str, (const char*)value);
  14731. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14732. isSuccess = ConfigurationStatus_Accepted;
  14733. }
  14734. else
  14735. {
  14736. isSuccess = ConfigurationStatus_Rejected;
  14737. }
  14738. }
  14739. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14740. {
  14741. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14742. {
  14743. strcpy(str, (const char*)value);
  14744. for(int i = 0; str[i]; i++)
  14745. {
  14746. str[i] = tolower(str[i]);
  14747. }
  14748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14749. isSuccess = ConfigurationStatus_Accepted;
  14750. }
  14751. else
  14752. {
  14753. isSuccess = ConfigurationStatus_Rejected;
  14754. }
  14755. }
  14756. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14757. {
  14758. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14759. {
  14760. strcpy(str, (const char*)value);
  14761. for(int i = 0; str[i]; i++)
  14762. {
  14763. str[i] = tolower(str[i]);
  14764. }
  14765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14766. isSuccess = ConfigurationStatus_Accepted;
  14767. }
  14768. else
  14769. {
  14770. isSuccess = ConfigurationStatus_Rejected;
  14771. }
  14772. }
  14773. #if 0
  14774. //For OCPP Test Case
  14775. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14776. {
  14777. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14778. {
  14779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14780. isSuccess = ConfigurationStatus_Accepted;
  14781. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14782. }
  14783. else
  14784. {
  14785. isSuccess = ConfigurationStatus_Rejected;
  14786. }
  14787. }
  14788. #endif
  14789. #if 1
  14790. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14791. {
  14792. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14793. {
  14794. strcpy(str, (const char*)value);
  14795. for(int i = 0; str[i]; i++)
  14796. {
  14797. str[i] = tolower(str[i]);
  14798. }
  14799. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14800. isSuccess = ConfigurationStatus_Accepted;
  14801. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14802. }
  14803. else
  14804. {
  14805. isSuccess = ConfigurationStatus_Rejected;
  14806. }
  14807. }
  14808. #endif
  14809. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14810. {
  14811. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14812. {
  14813. check_ascii = value[0];
  14814. if( (check_ascii < 48) || (check_ascii > 57) )
  14815. {
  14816. isSuccess = ConfigurationStatus_Rejected;
  14817. }
  14818. else
  14819. {
  14820. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14821. isSuccess = ConfigurationStatus_Accepted;
  14822. }
  14823. }
  14824. else
  14825. {
  14826. isSuccess = ConfigurationStatus_Rejected;
  14827. }
  14828. }
  14829. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14830. {
  14831. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14832. {
  14833. check_ascii = value[0];
  14834. if( (check_ascii < 48) || (check_ascii > 57) )
  14835. {
  14836. isSuccess = ConfigurationStatus_Rejected;
  14837. }
  14838. else
  14839. {
  14840. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14841. isSuccess = ConfigurationStatus_Accepted;
  14842. }
  14843. }
  14844. else
  14845. {
  14846. isSuccess = ConfigurationStatus_Rejected;
  14847. }
  14848. }
  14849. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14850. {
  14851. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14852. {
  14853. strcpy(str, (const char*)value);
  14854. for(int i = 0; str[i]; i++)
  14855. {
  14856. str[i] = tolower(str[i]);
  14857. }
  14858. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14859. isSuccess = ConfigurationStatus_Accepted;
  14860. }
  14861. else
  14862. {
  14863. isSuccess = ConfigurationStatus_Rejected;
  14864. }
  14865. }
  14866. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14867. {
  14868. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14869. {
  14870. check_ascii = value[0];
  14871. if( (check_ascii < 48) || (check_ascii > 57) )
  14872. {
  14873. isSuccess = ConfigurationStatus_Rejected;
  14874. }
  14875. else
  14876. {
  14877. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14878. isSuccess = ConfigurationStatus_Accepted;
  14879. }
  14880. }
  14881. else
  14882. {
  14883. isSuccess = ConfigurationStatus_Rejected;
  14884. }
  14885. }
  14886. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14887. {
  14888. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14889. {
  14890. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14891. isSuccess = ConfigurationStatus_Accepted;
  14892. }
  14893. else
  14894. {
  14895. isSuccess = ConfigurationStatus_Rejected;
  14896. }
  14897. }
  14898. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14899. {
  14900. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14901. {
  14902. check_ascii = value[0];
  14903. if( (check_ascii < 48) || (check_ascii > 57) )
  14904. {
  14905. isSuccess = ConfigurationStatus_Rejected;
  14906. }
  14907. else
  14908. {
  14909. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14910. isSuccess = ConfigurationStatus_Accepted;
  14911. }
  14912. }
  14913. else
  14914. {
  14915. isSuccess = ConfigurationStatus_Rejected;
  14916. }
  14917. }
  14918. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14919. {
  14920. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14921. {
  14922. strcpy(str, (const char*)value);
  14923. for(int i = 0; str[i]; i++)
  14924. {
  14925. str[i] = tolower(str[i]);
  14926. }
  14927. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14928. isSuccess = ConfigurationStatus_Accepted;
  14929. }
  14930. else
  14931. {
  14932. isSuccess = ConfigurationStatus_Rejected;
  14933. }
  14934. }
  14935. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14936. {
  14937. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14938. {
  14939. check_ascii = value[0];
  14940. if( (check_ascii < 48) || (check_ascii > 57) )
  14941. {
  14942. isSuccess = ConfigurationStatus_Rejected;
  14943. }
  14944. else
  14945. {
  14946. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14947. isSuccess = ConfigurationStatus_Accepted;
  14948. }
  14949. }
  14950. else
  14951. {
  14952. isSuccess = ConfigurationStatus_Rejected;
  14953. }
  14954. }
  14955. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14956. return isSuccess;
  14957. }
  14958. int TransactionMessageAttemptsGet(void)
  14959. {
  14960. return TransactionMessageAttemptsValue;
  14961. }
  14962. int FirstHeartBeatResponse(void)
  14963. {
  14964. return FirstHeartBeat;
  14965. }
  14966. int TransactionMessageRetryIntervalGet(void)
  14967. {
  14968. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14969. }
  14970. int ReadHttpStatus(int sock)
  14971. {
  14972. //char c;
  14973. char buff[1024]="",*ptr=buff+1;
  14974. int bytes_received, status;
  14975. DEBUG_INFO("Begin Response ..\n");
  14976. while((bytes_received = recv(sock, ptr, 1, 0))){
  14977. if(bytes_received==-1){
  14978. perror("ReadHttpStatus");
  14979. exit(1);
  14980. }
  14981. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14982. ptr++;
  14983. }
  14984. *ptr=0;
  14985. ptr=buff+1;
  14986. sscanf(ptr,"%*s %d ", &status);
  14987. DEBUG_INFO("%s\n",ptr);
  14988. DEBUG_INFO("status=%d\n",status);
  14989. DEBUG_INFO("End Response ..\n");
  14990. return (bytes_received>0)?status:0;
  14991. }
  14992. //the only filed that it parsed is 'Content-Length'
  14993. int ParseHeader(int sock)
  14994. {
  14995. //char c;
  14996. char buff[1024]="",*ptr=buff+4;
  14997. int bytes_received;
  14998. DEBUG_INFO("Begin HEADER ..\n");
  14999. while((bytes_received = recv(sock, ptr, 1, 0))){
  15000. if(bytes_received==-1){
  15001. perror("Parse Header");
  15002. exit(1);
  15003. }
  15004. if(
  15005. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15006. (ptr[-1]=='\r') && (*ptr=='\n' )
  15007. ) break;
  15008. ptr++;
  15009. }
  15010. *ptr=0;
  15011. ptr=buff+4;
  15012. //printf("%s",ptr);
  15013. if(bytes_received){
  15014. ptr=strstr(ptr,"Content-Length:");
  15015. if(ptr){
  15016. sscanf(ptr,"%*s %d",&bytes_received);
  15017. }else
  15018. bytes_received=-1; //unknown size
  15019. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15020. }
  15021. DEBUG_INFO("End HEADER ..\n");
  15022. return bytes_received ;
  15023. }
  15024. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15025. {
  15026. int result = TRUE;
  15027. char rmFileCmd[100]={0};
  15028. char FilePath[100]={0};
  15029. char ftpbuf[200];
  15030. int systemresult;
  15031. sprintf(FilePath,"/mnt/%s",filename);
  15032. system("ping 8.8.8.8 &");
  15033. if((access(FilePath,F_OK))!=-1)
  15034. {
  15035. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15036. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15037. system(rmFileCmd);
  15038. }
  15039. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15040. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15041. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15042. systemresult = system(ftpbuf);
  15043. if(systemresult != 0)
  15044. {
  15045. DEBUG_INFO("http DownLoad error!\n");
  15046. result = FALSE;
  15047. }
  15048. system("pkill ping");
  15049. return result;
  15050. }
  15051. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15052. {
  15053. int result = TRUE;
  15054. char rmFileCmd[100]={0};
  15055. char FilePath[100]={0};
  15056. char ftpbuf[200];
  15057. int systemresult;
  15058. sprintf(FilePath,"/mnt/%s",filename);
  15059. system("ping 8.8.8.8 &");
  15060. if((access(FilePath,F_OK))!=-1)
  15061. {
  15062. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15063. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15064. system(rmFileCmd);
  15065. }
  15066. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15067. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15068. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15069. systemresult = system(ftpbuf);
  15070. if(systemresult != 0)
  15071. {
  15072. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15073. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15074. systemresult = system(ftpbuf);
  15075. if(systemresult != 0)
  15076. {
  15077. DEBUG_WARN("wget error!\n");
  15078. result = FALSE;
  15079. }
  15080. }
  15081. system("pkill ping");
  15082. return result;
  15083. }
  15084. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15085. {
  15086. char rmFileCmd[100]={0};
  15087. char FilePath[100]={0};
  15088. char buf[512];
  15089. int systemresult = 0;
  15090. //DEBUG_INFO("filename=%s\n",filename);
  15091. //DEBUG_INFO("url=%s\n",url);
  15092. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15093. if((access(FilePath,F_OK))!=-1)
  15094. {
  15095. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15096. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15097. system(rmFileCmd);
  15098. }
  15099. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15100. if(fp == NULL)
  15101. {
  15102. DEBUG_INFO("log is NULL\n");
  15103. return FALSE;
  15104. }
  15105. else
  15106. {
  15107. fprintf(fp, "%s\n", url);
  15108. fprintf(fp, "%s\n", filename);
  15109. fclose(fp);
  15110. }
  15111. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15112. if(phpFP == NULL)
  15113. {
  15114. DEBUG_INFO("PHP upload fail.\n");
  15115. return FALSE;
  15116. }
  15117. else
  15118. {
  15119. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15120. {
  15121. if(strstr(buf, "result") != NULL)
  15122. {
  15123. sscanf(buf, "result: %d", &systemresult);
  15124. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15125. }
  15126. }
  15127. pclose(phpFP);
  15128. }
  15129. if(systemresult != 1)
  15130. {
  15131. DEBUG_INFO("HTTP upload error!\n");
  15132. return FALSE;
  15133. }
  15134. return TRUE;
  15135. }
  15136. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15137. {
  15138. struct hostent* server;
  15139. char *IPbuffer;
  15140. char ftpbuf[200];
  15141. int systemresult;
  15142. // To retrieve host information
  15143. server = gethostbyname(location);
  15144. // To convert an Internet network
  15145. // address into ASCII string
  15146. IPbuffer = inet_ntoa(*((struct in_addr*)
  15147. server->h_addr_list[0]));
  15148. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15149. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15150. /* format : ftpput -u username -p passwd IP target source*/
  15151. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15152. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15153. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15154. systemresult = system(ftpbuf);
  15155. DEBUG_INFO("systemresult=%d\n",systemresult);
  15156. if(systemresult != 0)
  15157. {
  15158. DEBUG_INFO("ftpput error!\n");
  15159. return FALSE;
  15160. }
  15161. return TRUE;
  15162. }
  15163. int GetOcppServerURL()
  15164. {
  15165. int result = FALSE;
  15166. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15167. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15168. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15169. struct yuarel url;
  15170. char urlStr[512];
  15171. // OCPPPH only
  15172. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  15173. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  15174. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  15175. {
  15176. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  15177. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15178. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15179. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  15180. if(yuarel_parse(&url, urlStr) != -1)
  15181. {
  15182. sprintf(OcppProtocol, "%s", url.scheme);
  15183. sprintf(OcppHost, "%s", url.host);
  15184. if(url.path == NULL)
  15185. OcppTempPath[0] = '\0';
  15186. else
  15187. sprintf(OcppTempPath, "%s", url.path);
  15188. if(url.port == 0)
  15189. {
  15190. if(strcmp(OcppProtocol, "wss") == 0)
  15191. OcppPort = 443;
  15192. else
  15193. OcppPort = 80;
  15194. }
  15195. else
  15196. OcppPort = url.port;
  15197. result = TRUE;
  15198. }
  15199. }
  15200. else
  15201. {
  15202. strcpy(OcppHost,"");
  15203. }
  15204. return result;
  15205. }
  15206. int GetOcppPath()
  15207. {
  15208. int result = FALSE;
  15209. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  15210. {
  15211. if(OcppTempPath == NULL)
  15212. {
  15213. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  15214. }
  15215. else
  15216. {
  15217. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  15218. }
  15219. result = TRUE;
  15220. goto End;
  15221. }
  15222. else
  15223. {
  15224. strcpy(OcppPath,"");
  15225. }
  15226. End:
  15227. return result;
  15228. }
  15229. int GetOcppPort()
  15230. {
  15231. return OcppPort;
  15232. }
  15233. int GetOcppConnStatus(void)
  15234. {
  15235. return ShmOCPP16DataPH->OcppConnStatus;
  15236. }
  15237. void SetOcppConnStatus(uint8_t status)
  15238. {
  15239. ShmOCPP16DataPH->OcppConnStatus = status;
  15240. }
  15241. int GetHeartBeatWithNOResponse(void)
  15242. {
  15243. return HeartBeatWithNOResponse;
  15244. }
  15245. void SetHeartBeatWithNOResponse(void)
  15246. {
  15247. HeartBeatWithNOResponse = 0;
  15248. }
  15249. void GetStartTransactionIdTag(int gun_index)
  15250. {
  15251. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15252. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15253. }
  15254. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15255. {
  15256. char ch;
  15257. FILE *fptr1;
  15258. int temptransactionId;
  15259. char str[100]={0};
  15260. temptransactionId = 0;
  15261. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15262. {
  15263. DEBUG_INFO("IdTag is empty.\n");
  15264. return temptransactionId;
  15265. }
  15266. /*------ Read the file ----------------*/
  15267. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  15268. if (!fptr1)
  15269. {
  15270. DEBUG_INFO("QueueTransactionId file open error.\n");
  15271. //printf(" File not found or unable to open the input file!!\n");
  15272. return temptransactionId;
  15273. }
  15274. ch=fgetc(fptr1);
  15275. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  15276. rewind(fptr1);
  15277. if(ch!=EOF)
  15278. {
  15279. // printf("%c",ch);
  15280. while (fgets(str, 100, fptr1) != NULL)
  15281. {
  15282. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15283. if(str[0]=='\0')
  15284. {
  15285. break;
  15286. }
  15287. char *revbuf[8] = {0}; // Variable store string split
  15288. int num = 0;// Quantity after string split
  15289. DEBUG_INFO("Transaction queue data= %s\n", str);
  15290. splitstring(str,",",revbuf,&num); // String split
  15291. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15292. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15293. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15294. DEBUG_INFO("------------------------------\n");
  15295. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15296. {
  15297. if(isStopTransaction)
  15298. {
  15299. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15300. {
  15301. temptransactionId = atoi(revbuf[2]);
  15302. //break;
  15303. }
  15304. }
  15305. else
  15306. {
  15307. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15308. {
  15309. temptransactionId = atoi(revbuf[2]);
  15310. //break;
  15311. }
  15312. }
  15313. }
  15314. }
  15315. }
  15316. else
  15317. DEBUG_INFO("EOF\n");
  15318. fclose(fptr1);
  15319. /*------- End of reading ---------------*/
  15320. return temptransactionId;
  15321. }
  15322. void SetTransactionIdZero(int transactionId)
  15323. {
  15324. char ch;
  15325. FILE *fptr1, *fptr2;
  15326. int temptransactionId = 0;
  15327. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15328. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15329. if (!fptr1)
  15330. {
  15331. //printf(" File not found or unable to open the input file!!\n");
  15332. return ;
  15333. }
  15334. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15335. if (!fptr2)
  15336. {
  15337. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15338. fclose(fptr1);
  15339. return ;
  15340. }
  15341. ch=fgetc(fptr1);
  15342. rewind(fptr1);
  15343. if(ch!=EOF)
  15344. {
  15345. // copy all contents to the temporary file except the specific line
  15346. while (fgets(str, 100, fptr1) != NULL)
  15347. {
  15348. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15349. if(str[0]=='\0')
  15350. {
  15351. break;
  15352. }
  15353. char *revbuf[8] = {0};
  15354. int num = 0;
  15355. strcpy(strtemp, str);
  15356. splitstring(str,",",revbuf,&num);
  15357. if(revbuf[2][0] != '\0')
  15358. {
  15359. temptransactionId = atoi(revbuf[2]);
  15360. if(transactionId != temptransactionId)
  15361. {
  15362. fprintf(fptr2, "%s\n", strtemp);
  15363. }
  15364. }
  15365. }
  15366. }
  15367. fclose(fptr1);
  15368. fclose(fptr2);
  15369. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15370. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15371. /*------ Read the file ----------------*/
  15372. }
  15373. int InternetDisconnect(void)
  15374. {
  15375. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15376. }
  15377. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15378. void storeTempStopTransaction(int gun_index)
  15379. {
  15380. char guid[37]={0};
  15381. int tempIndex = 0;
  15382. char TempStopTransaction[256];
  15383. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15384. DEBUG_INFO("storeTempStopTransaction...\n");
  15385. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15386. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15387. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15388. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15389. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15390. {
  15391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15392. {
  15393. tempIndex = ((gun_index==2) ? 1: 0);
  15394. }
  15395. else
  15396. {
  15397. tempIndex = gun_index;
  15398. }
  15399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15400. {
  15401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15402. {
  15403. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15404. }
  15405. }// END OF CHAdeMO_QUANTITY
  15406. }
  15407. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15408. {
  15409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15410. {
  15411. tempIndex = ((gun_index==2) ? 1: 0);
  15412. }
  15413. else
  15414. {
  15415. tempIndex = gun_index;
  15416. }
  15417. for (int index = 0; index < CCS_QUANTITY; index++)
  15418. {
  15419. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15420. {
  15421. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15422. }
  15423. }// END OF CCS_QUANTITY
  15424. }
  15425. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15426. {
  15427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15428. {
  15429. tempIndex = ((gun_index==2) ? 1: 0);
  15430. }
  15431. else
  15432. {
  15433. tempIndex = gun_index;
  15434. }
  15435. for (int index = 0; index < GB_QUANTITY; index++)
  15436. {
  15437. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15438. {
  15439. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15440. }
  15441. }// END OF GB_QUANTITY
  15442. }
  15443. else if(gunType[gun_index] == GUN_TYPE_DO)
  15444. {
  15445. tempIndex = gun_index;
  15446. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15447. {
  15448. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15449. {
  15450. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15451. }
  15452. }
  15453. }
  15454. else
  15455. {
  15456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15457. {
  15458. tempIndex = 2;
  15459. }
  15460. else
  15461. {
  15462. tempIndex = gun_index;
  15463. }
  15464. for (int index = 0; index < AC_QUANTITY; index++)
  15465. {
  15466. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15467. {
  15468. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15469. }
  15470. }// END OF AC_QUANTITY
  15471. }
  15472. //Stop Transaction Time
  15473. struct timeval tmnow;
  15474. struct tm *tm;
  15475. char buf[28];//, usec_buf[6];
  15476. gettimeofday(&tmnow, NULL);
  15477. time_t t;
  15478. t = time(NULL);
  15479. /*UTC time and date*/
  15480. tm = gmtime(&t);
  15481. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15483. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15485. random_uuid(guid);
  15486. /***********************************transactionData******************************************************/
  15487. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15489. //=================================
  15490. //1. Transaction_Begin
  15491. //=================================
  15492. //============================== Energy.Active.Import.Interval ===========================================
  15493. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15494. {
  15495. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15497. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15498. 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*/]);
  15499. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15500. 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))
  15501. {
  15502. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15503. }
  15504. else
  15505. {
  15506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15507. }
  15508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15510. }
  15511. //=================================
  15512. //2. Transaction_End
  15513. //=================================
  15514. //2.1====================================== Current.Import L1 ==============================================
  15515. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15516. {
  15517. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15518. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15519. {
  15520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15521. {
  15522. tempIndex = ((gun_index==2) ? 1: 0);
  15523. }
  15524. else
  15525. {
  15526. tempIndex = gun_index;
  15527. }
  15528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15529. {
  15530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15531. {
  15532. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15533. }
  15534. }// End of for CHAdeMO_QUANTITY
  15535. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15536. }
  15537. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15538. {
  15539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15540. {
  15541. tempIndex = ((gun_index==2) ? 1: 0);
  15542. }
  15543. else
  15544. {
  15545. tempIndex = gun_index;
  15546. }
  15547. for (int index = 0; index < CCS_QUANTITY; index++)
  15548. {
  15549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15550. {
  15551. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15552. }
  15553. }// End of for CCS_QUANTITY
  15554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15555. }
  15556. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15557. {
  15558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15559. {
  15560. tempIndex = ((gun_index==2) ? 1: 0);
  15561. }
  15562. else
  15563. {
  15564. tempIndex = gun_index;
  15565. }
  15566. for (int index = 0; index < GB_QUANTITY; index++)
  15567. {
  15568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15569. {
  15570. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15571. }
  15572. }// End of for GB_QUANTITY
  15573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15574. }
  15575. else if(gunType[gun_index] == GUN_TYPE_DO)
  15576. {
  15577. tempIndex = gun_index;
  15578. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15579. {
  15580. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15581. {
  15582. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15583. }
  15584. }
  15585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15586. }
  15587. else
  15588. {
  15589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15590. {
  15591. tempIndex = 2;
  15592. }
  15593. else
  15594. {
  15595. tempIndex = gun_index;
  15596. }
  15597. for (int index = 0; index < AC_QUANTITY; index++)
  15598. {
  15599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15600. {
  15601. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15602. }
  15603. }// End of for AC_QUANTITY
  15604. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15605. }
  15606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15609. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15610. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15611. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15612. }
  15613. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15614. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15615. {
  15616. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15617. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15618. {
  15619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15620. {
  15621. tempIndex = ((gun_index==2) ? 1: 0);
  15622. }
  15623. else
  15624. {
  15625. tempIndex = gun_index;
  15626. }
  15627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15628. {
  15629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15630. {
  15631. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15632. }
  15633. }// END OF CHAdeMO_QUANTITY
  15634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15635. }
  15636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15637. {
  15638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15639. {
  15640. tempIndex = ((gun_index==2) ? 1: 0);
  15641. }
  15642. else
  15643. {
  15644. tempIndex = gun_index;
  15645. }
  15646. for (int index = 0; index < CCS_QUANTITY; index++)
  15647. {
  15648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15649. {
  15650. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15651. }
  15652. }// END OF CCS_QUANTITY
  15653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15654. }
  15655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15656. {
  15657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15658. {
  15659. tempIndex = ((gun_index==2) ? 1: 0);
  15660. }
  15661. else
  15662. {
  15663. tempIndex = gun_index;
  15664. }
  15665. for (int index = 0; index < GB_QUANTITY; index++)
  15666. {
  15667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15668. {
  15669. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15670. }
  15671. }// END OF GB_QUANTITY
  15672. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15673. }
  15674. else if(gunType[gun_index] == GUN_TYPE_DO)
  15675. {
  15676. tempIndex = gun_index;
  15677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15678. {
  15679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15680. {
  15681. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15682. }
  15683. }
  15684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15685. }
  15686. else
  15687. {
  15688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15689. {
  15690. tempIndex = 2;
  15691. }
  15692. else
  15693. {
  15694. tempIndex = gun_index;
  15695. }
  15696. for (int index = 0; index < AC_QUANTITY; index++)
  15697. {
  15698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15699. {
  15700. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15701. }
  15702. }// END OF AC_QUANTITY
  15703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15704. }
  15705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15708. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15711. }
  15712. //2.3====================================== Power.Active.Import =========================================
  15713. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15714. {
  15715. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15716. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15717. {
  15718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15719. {
  15720. tempIndex = ((gun_index==2) ? 1: 0);
  15721. }
  15722. else
  15723. {
  15724. tempIndex = gun_index;
  15725. }
  15726. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15727. {
  15728. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15729. {
  15730. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15731. }
  15732. } // End for CHAdeMO_QUANTITY
  15733. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15734. }
  15735. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15736. {
  15737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15738. {
  15739. tempIndex = ((gun_index==2) ? 1: 0);
  15740. }
  15741. else
  15742. {
  15743. tempIndex = gun_index;
  15744. }
  15745. for (int index = 0; index < CCS_QUANTITY; index++)
  15746. {
  15747. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15748. {
  15749. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15750. }
  15751. } // END for CCS_QUANTITY
  15752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15753. }
  15754. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15755. {
  15756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15757. {
  15758. tempIndex = ((gun_index==2) ? 1: 0);
  15759. }
  15760. else
  15761. {
  15762. tempIndex = gun_index;
  15763. }
  15764. for (int index = 0; index < GB_QUANTITY; index++)
  15765. {
  15766. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15767. {
  15768. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15769. }
  15770. }// END for GB_QUANTITY
  15771. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15772. }
  15773. else if(gunType[gun_index] == GUN_TYPE_DO)
  15774. {
  15775. tempIndex = gun_index;
  15776. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15777. {
  15778. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15779. {
  15780. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15781. }
  15782. }
  15783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15784. }
  15785. else
  15786. {
  15787. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15788. {
  15789. tempIndex = 2;
  15790. }
  15791. else
  15792. {
  15793. tempIndex = gun_index;
  15794. }
  15795. for (int index = 0; index < AC_QUANTITY; index++)
  15796. {
  15797. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15798. {
  15799. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15800. }
  15801. } // END for AC_QUANTITY
  15802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15803. }
  15804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15807. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15810. }
  15811. //2.4====================================== Voltage L1 ====================================================
  15812. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15813. {
  15814. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15815. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15816. {
  15817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15818. {
  15819. tempIndex = ((gun_index==2) ? 1: 0);
  15820. }
  15821. else
  15822. {
  15823. tempIndex = gun_index;
  15824. }
  15825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15826. {
  15827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15828. {
  15829. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15830. }
  15831. } // END OF FOR CHAdeMO_QUANTITY
  15832. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15833. }
  15834. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15835. {
  15836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15837. {
  15838. tempIndex = ((gun_index==2) ? 1: 0);
  15839. }
  15840. else
  15841. {
  15842. tempIndex = gun_index;
  15843. }
  15844. for (int index = 0; index < CCS_QUANTITY; index++)
  15845. {
  15846. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15847. {
  15848. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15849. }
  15850. } // END OF FOR CCS_QUANTITY
  15851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15852. }
  15853. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15854. {
  15855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15856. {
  15857. tempIndex = ((gun_index==2) ? 1: 0);
  15858. }
  15859. else
  15860. {
  15861. tempIndex = gun_index;
  15862. }
  15863. for (int index = 0; index < GB_QUANTITY; index++)
  15864. {
  15865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15866. {
  15867. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15868. }
  15869. } // END OF FOR GB_QUANTITY
  15870. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15871. }
  15872. else if(gunType[gun_index] == GUN_TYPE_DO)
  15873. {
  15874. tempIndex = gun_index;
  15875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15876. {
  15877. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15878. {
  15879. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15880. }
  15881. }
  15882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15883. }
  15884. else
  15885. {
  15886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15887. {
  15888. tempIndex = 2;
  15889. }
  15890. else
  15891. {
  15892. tempIndex = gun_index;
  15893. }
  15894. for (int index = 0; index < AC_QUANTITY; index++)
  15895. {
  15896. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15897. {
  15898. 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
  15899. }
  15900. } // END OF FOR AC_QUANTITY
  15901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15902. }
  15903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15906. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15909. }
  15910. //2.5============================================== End SoC =========================================================
  15911. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  15912. {
  15913. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15914. 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))
  15915. {
  15916. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15917. {
  15918. tempIndex = ((gun_index==2) ? 1: 0);
  15919. }
  15920. else
  15921. {
  15922. tempIndex = gun_index;
  15923. }
  15924. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15925. {
  15926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15927. {
  15928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15929. {
  15930. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15931. }
  15932. }
  15933. }
  15934. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15935. {
  15936. for (int index = 0; index < CCS_QUANTITY; index++)
  15937. {
  15938. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15939. {
  15940. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15941. }
  15942. }
  15943. }
  15944. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15945. {
  15946. for (int index = 0; index < GB_QUANTITY; index++)
  15947. {
  15948. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15949. {
  15950. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15951. }
  15952. }
  15953. }
  15954. else if(gunType[gun_index] == GUN_TYPE_DO)
  15955. {
  15956. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15957. {
  15958. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15959. {
  15960. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15961. }
  15962. }
  15963. }
  15964. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15965. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15966. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15970. } // END FOR DC CASE
  15971. }
  15972. //2.6====================================== Current.Import L2 ==============================================
  15973. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15974. {
  15975. // AC 3 phase L2 current
  15976. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15977. {
  15978. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15979. {
  15980. tempIndex = 2;
  15981. }
  15982. else
  15983. {
  15984. tempIndex = gun_index;
  15985. }
  15986. for (int index = 0; index < AC_QUANTITY; index++)
  15987. {
  15988. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15989. {
  15990. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15991. }
  15992. }// End of for AC_QUANTITY
  15993. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15994. }
  15995. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16000. }
  16001. //2.7====================================== Current.Import L3 ==============================================
  16002. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16003. {
  16004. // AC 3 phase L3 current
  16005. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16006. {
  16007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16008. {
  16009. tempIndex = 2;
  16010. }
  16011. else
  16012. {
  16013. tempIndex = gun_index;
  16014. }
  16015. for (int index = 0; index < AC_QUANTITY; index++)
  16016. {
  16017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16018. {
  16019. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16020. }
  16021. }// End of for AC_QUANTITY
  16022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16023. }
  16024. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16029. }
  16030. //2.9====================================== Voltage L2 ====================================================
  16031. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16032. {
  16033. // AC 3 phase L2 volatge
  16034. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16035. {
  16036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16037. {
  16038. tempIndex = 2;
  16039. }
  16040. else
  16041. {
  16042. tempIndex = gun_index;
  16043. }
  16044. for (int index = 0; index < AC_QUANTITY; index++)
  16045. {
  16046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16047. {
  16048. 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
  16049. }
  16050. } // END OF FOR AC_QUANTITY
  16051. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16052. }
  16053. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16058. }
  16059. //2.10====================================== Voltage L3 ====================================================
  16060. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16061. {
  16062. // AC 3 phase L3 volatge
  16063. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16064. {
  16065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16066. {
  16067. tempIndex = 2;
  16068. }
  16069. else
  16070. {
  16071. tempIndex = gun_index;
  16072. }
  16073. for (int index = 0; index < AC_QUANTITY; index++)
  16074. {
  16075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16076. {
  16077. 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
  16078. }
  16079. } // END OF FOR AC_QUANTITY
  16080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16081. }
  16082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16084. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16087. }
  16088. //====================== Start SoC ================================
  16089. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16090. {
  16091. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16092. 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))
  16093. {
  16094. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16095. {
  16096. tempIndex = ((gun_index==2) ? 1: 0);
  16097. }
  16098. else
  16099. {
  16100. tempIndex = gun_index;
  16101. }
  16102. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16103. {
  16104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16105. {
  16106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16107. {
  16108. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16109. }
  16110. }
  16111. }
  16112. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16113. {
  16114. for (int index = 0; index < CCS_QUANTITY; index++)
  16115. {
  16116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16117. {
  16118. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16119. }
  16120. }
  16121. }
  16122. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16123. {
  16124. for (int index = 0; index < GB_QUANTITY; index++)
  16125. {
  16126. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16127. {
  16128. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16129. }
  16130. }
  16131. }
  16132. else if(gunType[gun_index] == GUN_TYPE_DO)
  16133. {
  16134. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16135. {
  16136. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16137. {
  16138. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16139. }
  16140. }
  16141. }
  16142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16144. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16148. } // END FOR DC CASE
  16149. }
  16150. //======================================== Message create ==============================================
  16151. json_object *StopTransaction = json_object_new_object();
  16152. json_object *transactionDatas = json_object_new_array();
  16153. json_object *sampledValues = json_object_new_array();
  16154. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  16155. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16156. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16157. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16158. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16159. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16160. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16161. {
  16162. json_object *transactionData = json_object_new_object();
  16163. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16164. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16165. {
  16166. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16167. {
  16168. json_object *sampledValue = json_object_new_object();
  16169. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16170. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16171. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16172. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16173. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16174. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16175. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16176. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16177. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16178. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16179. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16180. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16181. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16182. json_object_array_add(sampledValues, sampledValue);
  16183. }
  16184. }
  16185. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16186. json_object_array_add(transactionDatas, transactionData);
  16187. }
  16188. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16189. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16190. ,MESSAGE_TYPE_CALL
  16191. ,guid
  16192. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16193. json_object_put(StopTransaction);
  16194. // Check File "TempStopTransaction" Exist
  16195. if((access(TempStopTransaction,F_OK))!=-1)
  16196. {
  16197. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16198. fclose(fopen(TempStopTransaction, "w"));
  16199. }
  16200. else
  16201. {
  16202. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16203. FILE *log = fopen(TempStopTransaction, "w+");
  16204. if(log == NULL)
  16205. {
  16206. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16207. return ;
  16208. }
  16209. else
  16210. {
  16211. fclose(log);
  16212. }
  16213. }
  16214. //Add TempStopTransaction | Update TempStopTransaction
  16215. // open file for writing
  16216. FILE *outfile;
  16217. outfile = fopen (TempStopTransaction, "a");
  16218. //DEBUG_INFO("data = %s\n", queuedata);
  16219. fputs(queuedata, outfile);
  16220. fputs("\n", outfile);
  16221. fclose (outfile);
  16222. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16223. }
  16224. void checkTempStopTransaction(int gun_index)
  16225. {
  16226. FILE *fptr1;
  16227. char ch;
  16228. char str[QUEUE_MESSAGE_LENGTH]={0};
  16229. char guid[37]={0};
  16230. char tempdata[65]={0};
  16231. char connectorStr[2]={0};
  16232. char TempStopTransaction[256];
  16233. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16234. fptr1 = fopen(TempStopTransaction, "r");
  16235. //TempStopTransaction格式: 槍號,StopTransaction封包
  16236. if (!fptr1)
  16237. {
  16238. //printf(" File not found or unable to open the input file!!\n");
  16239. return ;
  16240. }
  16241. ch=fgetc(fptr1);
  16242. //printf(" Now the content of the file %s is : \n",fname);
  16243. rewind(fptr1);
  16244. if(ch!=EOF)
  16245. {
  16246. // copy all contents to the temporary file except the specific line
  16247. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16248. {
  16249. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16250. if(str[0]=='\0')
  16251. {
  16252. break;
  16253. }
  16254. //TempStopTransaction格式: 槍號,StopTransaction封包
  16255. strncpy(connectorStr, str, 1);
  16256. if(atoi(connectorStr) != (gun_index+1))
  16257. {
  16258. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16259. fclose(fptr1);
  16260. return ;
  16261. }
  16262. //random_uuid(guid);
  16263. strncpy(guid, str+6, 36); //copy guid
  16264. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16265. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16266. {
  16267. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16268. }
  16269. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16270. OCPP_insert_transaction_msg(NO, str);
  16271. memset(str,0,ARRAY_SIZE(str));
  16272. }
  16273. }
  16274. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16275. fclose(fptr1);
  16276. remove(TempStopTransaction); // remove the original file
  16277. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16278. }
  16279. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16280. {
  16281. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16282. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16283. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16284. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16285. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16286. }
  16287. int GetWebSocketPingInterval(void)
  16288. {
  16289. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16290. }
  16291. int GetServerSign(void)
  16292. {
  16293. return server_sign;
  16294. }
  16295. uint8_t GetOcppSecurityProfile()
  16296. {
  16297. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16298. }
  16299. void GetOcppChargerBoxId(uint8_t *data)
  16300. {
  16301. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16302. }
  16303. void GetOcppSecurityPassword(uint8_t *data)
  16304. {
  16305. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16306. }
  16307. void SetOcppVersion(uint8_t *version)
  16308. {
  16309. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16310. DEBUG_INFO("ocpp version: %s\n", version);
  16311. if(strstr((char*)version, "ocpp1.6") != NULL)
  16312. {
  16313. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16314. }
  16315. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16316. {
  16317. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16318. system("pkill OcppBackend");
  16319. }
  16320. }
  16321. void SetServerSign(int value)
  16322. {
  16323. server_sign = value;
  16324. }
  16325. int GetBootNotificationInterval(void)
  16326. {
  16327. return BootNotificationInterval;
  16328. }
  16329. int GetInternetConn(void)
  16330. {
  16331. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16332. }
  16333. int GetBackendConnectionTimeout(void)
  16334. {
  16335. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16336. }
  16337. int isConnectorInitMode(int gun_index)
  16338. {
  16339. int tempIndex = 0;
  16340. int result = TRUE;
  16341. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16342. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16343. {
  16344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16345. {
  16346. tempIndex = ((gun_index==2) ? 1: 0);
  16347. }
  16348. else
  16349. {
  16350. tempIndex = gun_index;
  16351. }
  16352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16353. {
  16354. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16355. {
  16356. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16357. } //end of the same index
  16358. }//end of for CHAdeMO_QUANTITY
  16359. }
  16360. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16361. {
  16362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16363. {
  16364. tempIndex = ((gun_index==2) ? 1: 0);
  16365. }
  16366. else
  16367. {
  16368. tempIndex = gun_index;
  16369. }
  16370. for (int index = 0; index < CCS_QUANTITY; index++)
  16371. {
  16372. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16373. {
  16374. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16375. } //end of the same index
  16376. } // end of for CCS_QUANTITY
  16377. }
  16378. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16379. {
  16380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16381. {
  16382. tempIndex = ((gun_index==2) ? 1: 0);
  16383. }
  16384. else
  16385. {
  16386. tempIndex = gun_index;
  16387. }
  16388. for (int index = 0; index < GB_QUANTITY; index++)
  16389. {
  16390. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16391. {
  16392. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16393. } //end of the same index
  16394. } // end of for GB_QUANTITY
  16395. }
  16396. else if(gunType[gun_index] == GUN_TYPE_DO)
  16397. {
  16398. tempIndex = gun_index;
  16399. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16400. {
  16401. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16402. {
  16403. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16404. } //end of the same index
  16405. }
  16406. }
  16407. else
  16408. {
  16409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16410. {
  16411. tempIndex = 2;
  16412. }
  16413. else
  16414. {
  16415. tempIndex = gun_index;
  16416. }
  16417. for (int index = 0; index < AC_QUANTITY; index++)
  16418. {
  16419. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16420. {
  16421. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16422. }//end of the same index
  16423. }//end of for AC_QUANTITY
  16424. }
  16425. return result;
  16426. }
  16427. void refreshProcDogTimer()
  16428. {
  16429. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16430. }
  16431. void InitialSystemValue(void)
  16432. {
  16433. int connectorIndex = 0;
  16434. //int valueASCII = 0;
  16435. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16436. gunTotalNumber=0;
  16437. SystemInitial = 0;
  16438. locallistVersion=0;
  16439. BootNotificationInterval = 0;
  16440. authorizeRetryTimes = 0;
  16441. GunStatusInterval = 10;
  16442. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16443. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16444. //Hear Beat
  16445. HeartBeatWithNOResponse = 0;
  16446. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16447. FirstHeartBeat = 0;
  16448. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16449. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16450. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16451. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16452. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16453. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16454. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16455. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16456. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16457. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16458. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16459. memset(gunType, 0, ARRAY_SIZE(gunType));
  16460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16461. {
  16462. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16463. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16464. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16465. {
  16466. // DO series
  16467. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16468. {
  16469. SystemInitial = SystemInitial + 1;
  16470. gunTotalNumber = gunTotalNumber + 1;
  16471. gunType[connectorIndex] = GUN_TYPE_DO;
  16472. connectorIndex = connectorIndex + 1;
  16473. }
  16474. }
  16475. else
  16476. {
  16477. // DM, DW, DS series
  16478. //check connector / socket type (index: 8, 9, 10)
  16479. for(int index=7; index <10 ; index++)
  16480. {
  16481. if(index != 8)
  16482. {
  16483. // DC Connector
  16484. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16485. {
  16486. SystemInitial = SystemInitial + 1;
  16487. gunTotalNumber = gunTotalNumber + 1;
  16488. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16489. connectorIndex = connectorIndex + 1;
  16490. }
  16491. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16492. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16493. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16494. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16495. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16496. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16497. {
  16498. SystemInitial = SystemInitial + 1;
  16499. gunTotalNumber = gunTotalNumber + 1;
  16500. gunType[connectorIndex] = GUN_TYPE_CCS;
  16501. connectorIndex = connectorIndex + 1;
  16502. }
  16503. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16504. {
  16505. SystemInitial = SystemInitial + 1;
  16506. gunTotalNumber = gunTotalNumber + 1;
  16507. gunType[connectorIndex] = GUN_TYPE_GBT;
  16508. connectorIndex = connectorIndex + 1;
  16509. }
  16510. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16511. {
  16512. SystemInitial = SystemInitial + 1;
  16513. gunTotalNumber = gunTotalNumber + 1;
  16514. gunType[connectorIndex] = GUN_TYPE_DO;
  16515. connectorIndex = connectorIndex + 1;
  16516. }
  16517. }
  16518. else
  16519. {
  16520. // AC Connector
  16521. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16522. {
  16523. SystemInitial = SystemInitial + 1;
  16524. gunTotalNumber = gunTotalNumber + 1;
  16525. gunType[connectorIndex] = GUN_TYPE_AC;
  16526. connectorIndex = connectorIndex + 1;
  16527. }
  16528. }
  16529. }
  16530. }
  16531. //DEBUG_INFO("DC ...\n");
  16532. }
  16533. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16534. {
  16535. //check connector / socket type (index: 8, 9, 10)
  16536. for(int index=7; index <10 ; index++)
  16537. {
  16538. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16539. {
  16540. SystemInitial = SystemInitial + 1;
  16541. gunTotalNumber = gunTotalNumber + 1;
  16542. gunType[connectorIndex] = GUN_TYPE_AC;
  16543. connectorIndex = connectorIndex + 1;
  16544. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16545. }
  16546. }
  16547. }
  16548. //Status && ConnectorPlugIn Setting
  16549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16550. {
  16551. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16552. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16553. }
  16554. for (int index = 0; index < CCS_QUANTITY; index++)
  16555. {
  16556. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16557. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16558. }
  16559. for (int index = 0; index < GB_QUANTITY; index++)
  16560. {
  16561. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16562. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16563. }
  16564. for (int index = 0; index < AC_QUANTITY; index++)
  16565. {
  16566. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16567. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16568. }
  16569. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16570. {
  16571. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16572. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16573. }
  16574. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16575. {
  16576. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16577. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16578. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16579. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16580. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16581. }
  16582. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16583. clientTime.Heartbeat=time((time_t*)NULL);
  16584. sleep(1);
  16585. }
  16586. void LWS_Send(char *str)
  16587. {
  16588. //=====================================================
  16589. // Check InternetConn 0: disconnected, 1: connected
  16590. //====================================================
  16591. if(GetOcppConnStatus() == 0)
  16592. {
  16593. DEBUG_INFO("offline now !!!\n");
  16594. return;
  16595. }
  16596. // Only disable isWebsocketSendable operation initiated by charger
  16597. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16598. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16599. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16600. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16601. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16602. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16603. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16604. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16605. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16606. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16607. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16608. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16609. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16610. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16611. {
  16612. isWebsocketSendable = 0;
  16613. }
  16614. pthread_mutex_lock(&lock_send);
  16615. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16616. sprintf((char *)SendBuffer, "%s", str);
  16617. SendBufLen = strlen(str);
  16618. pthread_mutex_unlock(&lock_send);
  16619. lws_callback_on_writable(wsi_client);
  16620. //lws_service(context, 0);
  16621. //sleep(1);
  16622. }
  16623. void LWS_SendNow(char *str)
  16624. {
  16625. //=====================================================
  16626. // Check InternetConn 0: disconnected, 1: connected
  16627. //====================================================
  16628. if(GetOcppConnStatus() == 0)
  16629. {
  16630. DEBUG_INFO("offline now !!!\n");
  16631. return;
  16632. }
  16633. // Only disable isWebsocketSendable operation initiated by charger
  16634. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16635. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16636. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16637. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16638. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16639. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16640. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16641. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16642. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16643. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16644. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16645. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16646. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16647. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16648. {
  16649. isWebsocketSendable = 0;
  16650. }
  16651. pthread_mutex_lock(&lock_send);
  16652. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16653. sprintf((char *)SendBuffer, "%s", str);
  16654. SendBufLen = strlen(str);
  16655. pthread_mutex_unlock(&lock_send);
  16656. lws_callback_on_writable(wsi_client);
  16657. lws_service(context, 0);
  16658. //sleep(1);
  16659. }