MessageHandler.c 834 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089
  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))
  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(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8579. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8580. }
  8581. else
  8582. {
  8583. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8584. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8585. }
  8586. json_object_put(data);
  8587. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8588. json_object_put(response);
  8589. }
  8590. else
  8591. {
  8592. // Can not find valid message id
  8593. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8594. }
  8595. }
  8596. else
  8597. {
  8598. // Payload is null
  8599. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8600. }
  8601. LWS_Send(message);
  8602. return result;
  8603. }
  8604. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8605. {
  8606. mtrace();
  8607. int result = FAIL;
  8608. int connectorIdInt, durationInt;
  8609. char chargingRateUnitStr[4]={0};
  8610. char comfirmstr[20];
  8611. int confirmPeriods = 0;
  8612. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8613. json_object *GetCompositeSchedule;
  8614. GetCompositeSchedule = json_tokener_parse(payload);
  8615. if(!is_error(GetCompositeSchedule))
  8616. {
  8617. // Required data
  8618. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8619. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8620. else
  8621. connectorIdInt = -1;
  8622. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8623. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8624. else
  8625. durationInt = 86400;
  8626. // Optional data
  8627. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8628. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8629. }
  8630. json_object_put(GetCompositeSchedule);
  8631. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8632. if((connectorIdInt == 0) ||
  8633. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8634. {
  8635. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8636. struct StructChargingProfile tmpProfile[1];
  8637. if(strstr(chargingRateUnitStr, "W") != NULL)
  8638. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8639. else
  8640. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8641. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8642. {
  8643. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8644. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8645. }
  8646. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8647. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8648. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8649. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8650. {
  8651. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8652. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8653. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8654. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8655. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8656. {
  8657. confirmPeriods = idx;
  8658. break;
  8659. }
  8660. }
  8661. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8662. {
  8663. confirmPeriods += 1;
  8664. }
  8665. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8666. }
  8667. else
  8668. {
  8669. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8670. }
  8671. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8672. return result;
  8673. }
  8674. int handleGetConfigurationRequest(char *uuid, char *payload)
  8675. {
  8676. mtrace();
  8677. int result = FAIL;
  8678. int MaxKeySupported = 0;
  8679. int n_keys = 0;
  8680. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8681. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8682. json_object *GetConfiguration;
  8683. GetConfiguration = json_tokener_parse(payload);
  8684. if(!is_error(GetConfiguration))
  8685. {
  8686. // Optional data
  8687. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8688. {
  8689. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8690. {
  8691. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8692. n_keys = idx + 1;
  8693. }
  8694. }
  8695. }
  8696. json_object_put(GetConfiguration);
  8697. UnknownKeynum = 0;
  8698. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8699. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8700. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8701. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8702. if(n_keys != 0)
  8703. {
  8704. for(int i=0;i<n_keys;i++)
  8705. {
  8706. getKeyValue(requestKey[i]);
  8707. }
  8708. }
  8709. else
  8710. {
  8711. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8712. getKeyValue("");
  8713. }
  8714. processUnkownKey();
  8715. sendGetConfigurationConfirmation(uuid);
  8716. return result;
  8717. }
  8718. static char fnamePlusPath[100]={0};
  8719. static char fnamePWithNoPath[60]={0};
  8720. void checkUploadLog(void)
  8721. {
  8722. FILE *fp;
  8723. /* Open the command for reading. */
  8724. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8725. if (fp == NULL) {
  8726. DEBUG_WARN("Failed to run command\n" );
  8727. exit(1);
  8728. }
  8729. int ftppathlen = 0;
  8730. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8731. int i = 0;
  8732. /* Read the output a line at a time - output it. */
  8733. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8734. if(i==0)
  8735. {
  8736. ftppathlen = strlen(fnamePlusPath);
  8737. DEBUG_INFO("%s\n", fnamePlusPath);
  8738. fnamePlusPath[ftppathlen]='\0';
  8739. break;
  8740. }
  8741. i= i+1;
  8742. }
  8743. /* close */
  8744. pclose(fp);
  8745. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8746. {
  8747. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8748. {
  8749. fnamePlusPath[k]='\0';
  8750. }
  8751. }
  8752. i=1;
  8753. //char fname[60]={0};
  8754. while(i < ftppathlen)
  8755. {
  8756. int len=ftppathlen-i;
  8757. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8758. {
  8759. DEBUG_INFO("compare '/' all right\n");
  8760. break;
  8761. }
  8762. i=i+1;
  8763. }
  8764. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8765. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8766. fnamePWithNoPath[i+1] = '\0';
  8767. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8768. {
  8769. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8770. {
  8771. fnamePWithNoPath[j]='\0';
  8772. }
  8773. }
  8774. FILE* fp1 = fopen(fnamePlusPath, "r");
  8775. if (fp1)
  8776. {
  8777. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8778. // file exists
  8779. fclose(fp1);
  8780. }
  8781. else
  8782. {
  8783. // file doesn't exist
  8784. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8785. }
  8786. }
  8787. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8788. {
  8789. mtrace();
  8790. int result = FAIL;
  8791. time_t CurrentTime;
  8792. struct tm *tm;
  8793. pthread_t th_Status;
  8794. CurrentTime = time(NULL);
  8795. tm = localtime(&CurrentTime);
  8796. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  8797. 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);
  8798. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8799. if(!interLock.isGetDiagnosticGoing)
  8800. {
  8801. interLock.isGetDiagnosticGoing = 1;
  8802. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8803. }
  8804. else
  8805. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  8806. return result;
  8807. }
  8808. void* GetDiagnosticsProcess(void* data)
  8809. {
  8810. pthread_detach(pthread_self());
  8811. mtrace();
  8812. int retriesInt=0, retryIntervalInt=0;
  8813. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8814. 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};
  8815. int port=0;
  8816. int isSuccess = FALSE;
  8817. char ftpbuf[200]={0};
  8818. char cmdBuf[2048];
  8819. struct tm *tmNow;
  8820. time_t CurrentTime;
  8821. struct tm tmStart;
  8822. struct tm tmStop;
  8823. CurrentTime = time(NULL);
  8824. tmNow=localtime(&CurrentTime);
  8825. uint16_t targetYear, targetMonth;
  8826. json_object *GetDiagnostics;
  8827. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8828. GetDiagnostics = json_tokener_parse(data);
  8829. if(!is_error(GetDiagnostics))
  8830. {
  8831. // Required data
  8832. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8833. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8834. // Optional data
  8835. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8836. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8837. else
  8838. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8839. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8840. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8841. else
  8842. retryIntervalInt = 30;
  8843. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8844. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8845. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8846. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8847. }
  8848. json_object_put(GetDiagnostics);
  8849. // Pack log to compress file
  8850. 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) &&
  8851. (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))
  8852. {
  8853. // Pack system log
  8854. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8855. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8856. targetYear = tmStart.tm_year;
  8857. targetMonth = tmStart.tm_mon;
  8858. do
  8859. {
  8860. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8861. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8862. if(targetMonth+1>=13)
  8863. {
  8864. targetYear += 1;
  8865. targetMonth = 1;
  8866. }
  8867. else
  8868. {
  8869. targetMonth += 1;
  8870. }
  8871. }while((targetYear < (tmNow->tm_year+1900)) ||
  8872. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8873. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8874. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8875. system(cmdBuf);
  8876. // Pack charging & event log
  8877. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8878. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8879. targetYear = tmStart.tm_year;
  8880. targetMonth = tmStart.tm_mon;
  8881. do
  8882. {
  8883. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8884. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8885. if(targetMonth+1>=13)
  8886. {
  8887. targetYear += 1;
  8888. targetMonth = 1;
  8889. }
  8890. else
  8891. {
  8892. targetMonth += 1;
  8893. }
  8894. }while((targetYear < (tmNow->tm_year+1900)) ||
  8895. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8896. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8897. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8898. system(cmdBuf);
  8899. // Combine log file
  8900. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8901. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8902. }
  8903. else
  8904. {
  8905. system("exec /root/logPackTools 'log' 6");
  8906. }
  8907. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8908. system(cmdBuf);
  8909. checkUploadLog();
  8910. //****************location*******************/
  8911. if(strcmp(locationstr,"")==0)
  8912. {
  8913. DEBUG_INFO("location is <Empty>!\n");
  8914. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8915. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8916. goto end;
  8917. }
  8918. memset(protocol, 0, ARRAY_SIZE(protocol));
  8919. memset(user, 0, ARRAY_SIZE(user) );
  8920. memset(password, 0, ARRAY_SIZE(password));
  8921. memset(host, 0, ARRAY_SIZE(host));
  8922. memset(path, 0, ARRAY_SIZE(path));
  8923. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8924. memset(host1, 0, ARRAY_SIZE(host1));
  8925. memset(path1, 0, ARRAY_SIZE(path1));
  8926. /*location: ftp://user:password@host:port/path*/
  8927. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8928. if((access(fnamePlusPath,F_OK))!=-1)
  8929. {
  8930. DEBUG_INFO("fnamePlusPath exist.\n");
  8931. }
  8932. else
  8933. {
  8934. DEBUG_INFO("fnamePlusPath not exist!\n");
  8935. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8936. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8937. goto end;
  8938. }
  8939. if(strchr(locationstr,'@')==NULL)
  8940. {
  8941. sscanf(locationstr,
  8942. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8943. protocol, host, &port, path);
  8944. strcpy(user,"anonymous");
  8945. strcpy(password,"");
  8946. }
  8947. else
  8948. {
  8949. //DEBUG_INFO("pch=%s\n", pch);
  8950. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8951. protocol, user, password, host, &port, path);
  8952. }
  8953. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8954. {
  8955. DEBUG_INFO("protocol is not ftp/http ! \n");
  8956. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8957. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8958. goto end;
  8959. }
  8960. if(strncmp(locationstr,"http", 4) == 0)
  8961. {
  8962. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8963. sprintf(ftppath,"/%s", path);
  8964. do
  8965. {
  8966. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8967. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8968. sleep(3);
  8969. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8970. if(!isSuccess)
  8971. {
  8972. DEBUG_INFO("Diagnostics fail.\n");
  8973. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8974. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8975. sleep(retryIntervalInt);
  8976. }
  8977. else
  8978. {
  8979. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8980. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8981. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8982. }
  8983. retriesInt--;
  8984. }while((isSuccess == 0)&&(retriesInt >= 0));
  8985. }
  8986. else
  8987. {
  8988. sscanf(host,"%[^/]%s",host1, path1);
  8989. if(strlen(path) > 0)
  8990. sprintf(ftppath,"/%s", path);
  8991. else
  8992. sprintf(ftppath,"/%s", path1);
  8993. int ftppathlen=strlen(ftppath);
  8994. int i=1;
  8995. char filenametemp[50];
  8996. while(i < ftppathlen)
  8997. {
  8998. int len=ftppathlen-i;
  8999. if(ftppath[len]== 47) // '/' ascll code: 47
  9000. {
  9001. DEBUG_INFO("find '/' all right\n");
  9002. break;
  9003. }
  9004. i=i+1;
  9005. }
  9006. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9007. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9008. filenametemp[i+1] = 0;
  9009. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9010. if(port == 0)
  9011. port = 21;
  9012. do
  9013. {
  9014. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9015. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9016. sleep(3);
  9017. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9018. if(!isSuccess)
  9019. {
  9020. DEBUG_INFO("Diagnostics fail.\n");
  9021. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9022. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9023. sleep(retryIntervalInt);
  9024. }
  9025. else
  9026. {
  9027. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9028. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9029. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9030. }
  9031. retriesInt--;
  9032. }while((!isSuccess)&&(retriesInt >= 0));
  9033. }
  9034. end:
  9035. system("rm -f /mnt/*");
  9036. sleep(5);
  9037. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9038. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9039. interLock.isGetDiagnosticGoing = 0;
  9040. pthread_exit(NULL);
  9041. }
  9042. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9043. {
  9044. mtrace();
  9045. int result = FAIL;
  9046. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9047. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9048. {
  9049. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9050. locallistVersion = -1;
  9051. }
  9052. else
  9053. {
  9054. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9055. OCPP_getListVerion();
  9056. }
  9057. //from db.OCPP_getListVerion
  9058. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9059. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9060. sendGetLocalListVersionConfirmation(uuid,"");
  9061. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9062. return result;
  9063. }
  9064. int handleRemoteStartRequest(char *uuid, char *payload)
  9065. {
  9066. mtrace();
  9067. int result = FAIL;
  9068. int connectorIdInt=-1;
  9069. int tempIndex = 0;
  9070. int connectorIdIsNULL, chargingProfileIsNULL;
  9071. char comfirmstr[20]={0};
  9072. char cmdBuf[512];
  9073. json_object *RemoteStartTransaction;
  9074. FILE *fp;
  9075. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9076. if(server_pending == TRUE)
  9077. {
  9078. return 0;
  9079. }
  9080. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9081. RemoteStartTransaction = json_tokener_parse(payload);
  9082. if(!is_error(RemoteStartTransaction))
  9083. {
  9084. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9085. {
  9086. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9087. }
  9088. else
  9089. {
  9090. connectorIdIsNULL = TRUE;
  9091. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9092. {
  9093. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9094. {
  9095. connectorIdIsNULL = FALSE;
  9096. connectorIdInt = (gun_index+1);
  9097. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9098. break;
  9099. }
  9100. }
  9101. }
  9102. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9103. {
  9104. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9105. // Required data
  9106. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9107. // Optional data
  9108. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9109. {
  9110. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9111. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9112. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9113. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9114. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9115. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9116. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9117. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9118. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9119. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9120. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9121. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9122. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9123. {
  9124. 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")));
  9125. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9126. 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"));
  9127. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9128. 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"));
  9129. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9130. 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")));
  9131. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9132. {
  9133. 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++)
  9134. {
  9135. 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"));
  9136. 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"));
  9137. 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)
  9138. 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"));
  9139. }
  9140. }
  9141. }
  9142. }
  9143. else
  9144. {
  9145. chargingProfileIsNULL = TRUE;
  9146. }
  9147. }
  9148. }
  9149. else
  9150. {
  9151. connectorIdIsNULL = TRUE;
  9152. }
  9153. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9154. {
  9155. DEBUG_WARN("Connector id is NULL\n.");
  9156. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9157. goto end;
  9158. }
  9159. /*
  9160. enum _SYSTEM_STATUS
  9161. {
  9162. S_BOOTING = 0,
  9163. S_IDLE, = 1
  9164. S_AUTHORIZING, = 2
  9165. S_REASSIGN_CHECK, = 3
  9166. S_REASSIGN, = 4
  9167. S_PRECHARGE, = 5
  9168. S_PREPARING_FOR_EV, = 6
  9169. S_PREPARING_FOR_EVSE, = 7
  9170. S_CHARGING, = 8
  9171. S_TERMINATING, = 9
  9172. S_COMPLETE, = 10
  9173. S_ALARM, = 11
  9174. S_FAULT = 12
  9175. }
  9176. */
  9177. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9178. {
  9179. //check Transaction active
  9180. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9181. {
  9182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9183. {
  9184. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9185. }
  9186. else
  9187. {
  9188. tempIndex = connectorIdInt -1;
  9189. }
  9190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9191. {
  9192. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9193. {
  9194. 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))
  9195. {
  9196. //Reserved
  9197. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9198. }
  9199. 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))
  9200. {
  9201. //Reserved
  9202. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9204. goto end;
  9205. }
  9206. else
  9207. {
  9208. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9209. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9210. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9211. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9212. {
  9213. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9214. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9215. goto end;
  9216. }
  9217. }//END FOR ELSE
  9218. }
  9219. }// END FOR CHAdeMO_QUANTITY
  9220. }
  9221. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9222. {
  9223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9224. {
  9225. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9226. }
  9227. else
  9228. {
  9229. tempIndex = connectorIdInt -1;
  9230. }
  9231. for (int index = 0; index < CCS_QUANTITY; index++)
  9232. {
  9233. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9234. {
  9235. 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))
  9236. {
  9237. //Reserved
  9238. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9239. }
  9240. 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))
  9241. {
  9242. //Reserved
  9243. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9244. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9245. goto end;
  9246. }
  9247. else
  9248. {
  9249. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9250. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9251. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9252. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9253. {
  9254. DEBUG_WARN("CCS connector not allow start\n.");
  9255. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9256. goto end;
  9257. }
  9258. }// END FOR ELSE
  9259. }
  9260. }// END FOR CCS_QUANTITY
  9261. }
  9262. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9263. {
  9264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9265. {
  9266. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9267. }
  9268. else
  9269. {
  9270. tempIndex = connectorIdInt -1;
  9271. }
  9272. for (int index = 0; index < GB_QUANTITY; index++)
  9273. {
  9274. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9275. {
  9276. 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))
  9277. {
  9278. //Reserved
  9279. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9280. }
  9281. 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))
  9282. {
  9283. //Reserved
  9284. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9285. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9286. goto end;
  9287. }
  9288. else
  9289. {
  9290. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9291. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9292. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9293. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9294. {
  9295. DEBUG_WARN("GB connector not allow start\n.");
  9296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9297. goto end;
  9298. }
  9299. }// END FOR ELSE
  9300. }
  9301. } // END FOR GB_QUANTITY
  9302. }
  9303. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9304. {
  9305. tempIndex = connectorIdInt -1;
  9306. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9307. {
  9308. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9309. {
  9310. 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))
  9311. {
  9312. //Reserved
  9313. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9314. }
  9315. 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))
  9316. {
  9317. //Reserved
  9318. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9319. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9320. goto end;
  9321. }
  9322. else
  9323. {
  9324. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9325. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9326. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9327. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9328. {
  9329. DEBUG_WARN("GB connector not allow start\n.");
  9330. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9331. goto end;
  9332. }
  9333. }// END FOR ELSE
  9334. }
  9335. } // END FOR GB_QUANTITY
  9336. }
  9337. else
  9338. {
  9339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9340. {
  9341. tempIndex = 2;
  9342. }
  9343. else
  9344. {
  9345. tempIndex = connectorIdInt -1;
  9346. }
  9347. for (int index = 0; index < AC_QUANTITY; index++)
  9348. {
  9349. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9350. {
  9351. 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))
  9352. {
  9353. //Reserved
  9354. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9355. }
  9356. 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))
  9357. {
  9358. //Reserved
  9359. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9360. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9361. goto end;
  9362. }
  9363. else
  9364. {
  9365. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9366. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9367. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9368. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9369. {
  9370. DEBUG_WARN("AC connector not allow start\n.");
  9371. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9372. goto end;
  9373. }
  9374. }//END FOR ELSE
  9375. }
  9376. }// END FOR AC_QUANTITY
  9377. }
  9378. if(chargingProfileIsNULL == FALSE)
  9379. {
  9380. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9381. {
  9382. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9383. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9384. //memset idTag
  9385. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9386. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9387. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9388. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9389. // Save profile to file
  9390. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9391. system(cmdBuf);
  9392. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9393. fp = fopen(cmdBuf, "w");
  9394. 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));
  9395. fclose(fp);
  9396. }
  9397. else
  9398. {
  9399. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9400. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9401. }
  9402. }
  9403. else
  9404. {
  9405. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9406. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9407. //memset idTag
  9408. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9409. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9410. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9412. }
  9413. }
  9414. else
  9415. {
  9416. DEBUG_WARN("Connector id over\n.");
  9417. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9418. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9419. }
  9420. end:
  9421. json_object_put(RemoteStartTransaction);
  9422. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9423. {
  9424. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9425. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9426. }
  9427. //OCPP send RemoteStartConfirmation by first.
  9428. sendRemoteStartConfirmation(uuid, comfirmstr);
  9429. return result;
  9430. }
  9431. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9432. {
  9433. mtrace();
  9434. int result = FAIL;
  9435. int match = FALSE;
  9436. int GunNO = 0;
  9437. int tempIndex = 0;
  9438. int transactionIdInt=0;
  9439. int transactionIdIsNULL= TRUE;
  9440. char comfirmstr[20];
  9441. json_object *RemoteStopTransaction;
  9442. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9443. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9444. if(server_pending == TRUE)
  9445. {
  9446. return 0;
  9447. }
  9448. RemoteStopTransaction = json_tokener_parse(payload);
  9449. if(!is_error(RemoteStopTransaction))
  9450. {
  9451. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9452. {
  9453. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9454. transactionIdIsNULL = FALSE;
  9455. }
  9456. }
  9457. json_object_put(RemoteStopTransaction);
  9458. if(transactionIdIsNULL == FALSE)
  9459. {
  9460. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9461. {
  9462. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9463. {
  9464. //check Transaction active
  9465. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9466. {
  9467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9468. {
  9469. tempIndex = ((gun_index==2) ? 1: 0);
  9470. }
  9471. else
  9472. {
  9473. tempIndex = gun_index;
  9474. }
  9475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9476. {
  9477. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9478. {
  9479. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9480. {
  9481. match = TRUE;
  9482. GunNO = gun_index;
  9483. }
  9484. }
  9485. }// END FOR CHAdeMO_QUANTITY
  9486. }
  9487. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9488. {
  9489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9490. {
  9491. tempIndex = ((gun_index==2) ? 1: 0);
  9492. }
  9493. else
  9494. {
  9495. tempIndex = gun_index;
  9496. }
  9497. for (int index = 0; index < CCS_QUANTITY; index++)
  9498. {
  9499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9500. {
  9501. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9502. {
  9503. match = TRUE;
  9504. GunNO = gun_index;
  9505. }
  9506. }
  9507. }// END FOR CCS_QUANTITY
  9508. }
  9509. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9510. {
  9511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9512. {
  9513. tempIndex = ((gun_index==2) ? 1: 0);
  9514. }
  9515. else
  9516. {
  9517. tempIndex = gun_index;
  9518. }
  9519. for (int index = 0; index < GB_QUANTITY; index++)
  9520. {
  9521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9522. {
  9523. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9524. {
  9525. match = TRUE;
  9526. GunNO = gun_index;
  9527. }
  9528. }
  9529. }// END FOR GB_QUANTITY
  9530. }
  9531. else if(gunType[gun_index] == GUN_TYPE_DO)
  9532. {
  9533. tempIndex = gun_index;
  9534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9535. {
  9536. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9537. {
  9538. 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
  9539. {
  9540. match = TRUE;
  9541. GunNO = gun_index;
  9542. }
  9543. }
  9544. }// END FOR GB_QUANTITY
  9545. }
  9546. else
  9547. {
  9548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9549. {
  9550. tempIndex = 2;
  9551. }
  9552. else
  9553. {
  9554. tempIndex = gun_index;
  9555. }
  9556. for (int index = 0; index < AC_QUANTITY; index++)
  9557. {
  9558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9559. {
  9560. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9561. {
  9562. match = TRUE;
  9563. GunNO = gun_index;
  9564. }
  9565. }
  9566. }// END FOR CHAdeMO_QUANTITY
  9567. } // END FOR AC ELSE
  9568. }// CHECK IF ResponseTransactionId == transactionIdInt
  9569. }//END FOR
  9570. if( match == TRUE)
  9571. {
  9572. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9573. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9574. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9575. }
  9576. else
  9577. {
  9578. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9579. }
  9580. }
  9581. else
  9582. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9583. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9584. return result;
  9585. }
  9586. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9587. {
  9588. mtrace();
  9589. int result = FAIL;
  9590. int connectorIdInt=0, reservationIdInt=0;
  9591. int tempIndex = 0;
  9592. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9593. char comfirmstr[20]={0};
  9594. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9595. int c = 0;
  9596. char *loc;
  9597. //char *ptr;
  9598. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9599. strcpy(sstrtemp, stringtrimspace(payload));
  9600. //***(1)connectorId ****/
  9601. c=0;
  9602. loc = strstr(sstrtemp, "connectorId");
  9603. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9604. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9605. {
  9606. sstr[c] = loc[strlen("connectorId")+2+c];
  9607. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9608. c++;
  9609. }
  9610. sstr[c] = '\0';
  9611. connectorIdInt = atoi(sstr);
  9612. //***(2)expiryDate ****/
  9613. loc = strstr(sstrtemp, "expiryDate");
  9614. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9615. c = 0;
  9616. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9617. {
  9618. sstr[c] = loc[3+strlen("expiryDate")+c];
  9619. c++;
  9620. }
  9621. sstr[c] = '\0';
  9622. strcpy(expiryDatestr, sstr);
  9623. //***(3)idTag ****/
  9624. loc = strstr(sstrtemp, "idTag");
  9625. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9626. c = 0;
  9627. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9628. {
  9629. sstr[c] = loc[3+strlen("idTag")+c];
  9630. c++;
  9631. }
  9632. sstr[c] = '\0';
  9633. strcpy(idTagstr, sstr);
  9634. //***(4)parentIdTag ****/
  9635. loc = strstr(sstrtemp, "parentIdTag");
  9636. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9637. c = 0;
  9638. if(loc == NULL)
  9639. {
  9640. strcpy(parentIdTagstr, "");
  9641. }
  9642. else
  9643. {
  9644. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9645. {
  9646. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9647. c++;
  9648. }
  9649. sstr[c] = '\0';
  9650. strcpy(parentIdTagstr, sstr);
  9651. }
  9652. //***(5)reservationId ****/
  9653. c=0;
  9654. loc = strstr(sstrtemp, "reservationId");
  9655. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9656. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9657. {
  9658. sstr[c] = loc[strlen("reservationId")+2+c];
  9659. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9660. c++;
  9661. }
  9662. sstr[c] = '\0';
  9663. reservationIdInt = atoi(sstr);
  9664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9665. /*
  9666. enum SYSTEM_STATUS
  9667. {
  9668. SYS_MODE_BOOTING = 0,
  9669. SYS_MODE_IDLE = 1,
  9670. SYS_MODE_AUTHORIZING = 2,
  9671. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9672. SYS_MODE_REASSIGN = 4,
  9673. SYS_MODE_PREPARING = 5,
  9674. SYS_MODE_PREPARE_FOR_EV = 6,
  9675. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9676. SYS_MODE_CHARGING = 8,
  9677. SYS_MODE_TERMINATING = 9,
  9678. SYS_MODE_COMPLETE = 10,
  9679. SYS_MODE_ALARM = 11,
  9680. SYS_MODE_FAULT = 12,
  9681. SYS_MODE_RESERVATION = 13,
  9682. SYS_MODE_BOOKING = 14,
  9683. SYS_MODE_MAINTAIN = 15,
  9684. SYS_MODE_DEBUG = 16,
  9685. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9686. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9687. SYS_MODE_UPDATE = 19
  9688. };
  9689. */
  9690. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9691. {
  9692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9693. goto end;
  9694. }
  9695. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9696. {
  9697. //check Transaction active
  9698. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9699. {
  9700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9701. {
  9702. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9703. }
  9704. else
  9705. {
  9706. tempIndex = connectorIdInt -1;
  9707. }
  9708. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9709. {
  9710. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9711. {
  9712. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9713. {
  9714. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9715. {
  9716. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9717. {
  9718. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9720. }
  9721. 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'))
  9722. {
  9723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9724. }
  9725. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9726. {
  9727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9728. }
  9729. else
  9730. {
  9731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9732. }
  9733. }
  9734. 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
  9735. {
  9736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9737. }
  9738. }
  9739. else
  9740. {
  9741. //replace reservation
  9742. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9744. }
  9745. }
  9746. } // END FOR CHAdeMO_QUANTITY
  9747. }
  9748. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9749. {
  9750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9751. {
  9752. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9753. }
  9754. else
  9755. {
  9756. tempIndex = connectorIdInt -1;
  9757. }
  9758. for (int index = 0; index < CCS_QUANTITY; index++)
  9759. {
  9760. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9761. {
  9762. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9763. {
  9764. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9765. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9766. {
  9767. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9768. {
  9769. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9771. }
  9772. 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'))
  9773. {
  9774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9775. }
  9776. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9777. {
  9778. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9779. }
  9780. else
  9781. {
  9782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9783. }
  9784. }
  9785. 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
  9786. {
  9787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9788. }
  9789. }
  9790. else
  9791. {
  9792. //replace reservation
  9793. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9795. }
  9796. }
  9797. } // END FOR CCS_QUANTITY
  9798. }
  9799. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9800. {
  9801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9802. {
  9803. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9804. }
  9805. else
  9806. {
  9807. tempIndex = connectorIdInt -1;
  9808. }
  9809. for (int index = 0; index < GB_QUANTITY; index++)
  9810. {
  9811. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9812. {
  9813. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9814. {
  9815. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9816. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9817. {
  9818. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9819. {
  9820. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9822. }
  9823. 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'))
  9824. {
  9825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9826. }
  9827. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9828. {
  9829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9830. }
  9831. else
  9832. {
  9833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9834. }
  9835. }
  9836. 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
  9837. {
  9838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9839. }
  9840. }
  9841. else
  9842. {
  9843. //replace reservation
  9844. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9846. }
  9847. }
  9848. }// END FOR GB_QUANTITY
  9849. }
  9850. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9851. {
  9852. tempIndex = connectorIdInt -1;
  9853. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9854. {
  9855. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9856. {
  9857. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9858. {
  9859. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9860. 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
  9861. {
  9862. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9863. {
  9864. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9866. }
  9867. 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'))
  9868. {
  9869. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9870. }
  9871. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9872. {
  9873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9874. }
  9875. else
  9876. {
  9877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9878. }
  9879. }
  9880. 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
  9881. {
  9882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9883. }
  9884. }
  9885. else
  9886. {
  9887. //replace reservation
  9888. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9890. }
  9891. }
  9892. }// END FOR GB_QUANTITY
  9893. }
  9894. else
  9895. {
  9896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9897. {
  9898. tempIndex = 2;
  9899. }
  9900. else
  9901. {
  9902. tempIndex = (connectorIdInt -1);
  9903. }
  9904. for (int index = 0; index < AC_QUANTITY; index++)
  9905. {
  9906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9907. {
  9908. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9909. {
  9910. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9911. {
  9912. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9913. {
  9914. 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))
  9915. {
  9916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9917. }
  9918. else
  9919. {
  9920. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9922. }
  9923. }
  9924. 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'))
  9925. {
  9926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9927. }
  9928. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9929. {
  9930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9931. }
  9932. else
  9933. {
  9934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9935. }
  9936. }
  9937. 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
  9938. {
  9939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9940. }
  9941. }
  9942. else
  9943. {
  9944. //replace reservation
  9945. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9947. }
  9948. }
  9949. } // END FOR AC_QUANTITY
  9950. }
  9951. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9952. }
  9953. else if(connectorIdInt == 0)
  9954. {
  9955. //check Transaction active
  9956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9957. {
  9958. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9959. {
  9960. 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'))
  9961. {
  9962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9963. goto end;
  9964. }
  9965. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9966. {
  9967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9968. goto end;
  9969. }
  9970. 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
  9971. {
  9972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9973. goto end;
  9974. }
  9975. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9976. {
  9977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9978. goto end;
  9979. }
  9980. }
  9981. }// END FOR CHAdeMO_QUANTITY
  9982. for (int index = 0; index < CCS_QUANTITY; index++)
  9983. {
  9984. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9985. {
  9986. 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'))
  9987. {
  9988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9989. goto end;
  9990. }
  9991. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9992. {
  9993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9994. goto end;
  9995. }
  9996. 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
  9997. {
  9998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9999. goto end;
  10000. }
  10001. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10002. {
  10003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10004. goto end;
  10005. }
  10006. }
  10007. } // END FOR CCS_QUANTITY
  10008. for (int index = 0; index < GB_QUANTITY; index++)
  10009. {
  10010. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10011. {
  10012. 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'))
  10013. {
  10014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10015. goto end;
  10016. }
  10017. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10018. {
  10019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10020. goto end;
  10021. }
  10022. 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
  10023. {
  10024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10025. goto end;
  10026. }
  10027. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10028. {
  10029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10030. goto end;
  10031. }
  10032. }
  10033. } // END FOR GB_QUANTITY
  10034. for (int index = 0; index < AC_QUANTITY; index++)
  10035. {
  10036. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10037. {
  10038. 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'))
  10039. {
  10040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10041. goto end;
  10042. }
  10043. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10044. {
  10045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10046. goto end;
  10047. }
  10048. 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
  10049. {
  10050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10051. goto end;
  10052. }
  10053. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10054. {
  10055. 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))
  10056. {
  10057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10058. goto end;
  10059. }
  10060. }
  10061. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10062. {
  10063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10064. goto end;
  10065. }
  10066. }
  10067. }// END FOR AC_QUANTITY
  10068. //The connectorId is 0
  10069. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10071. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10072. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10073. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10074. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10075. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10076. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10077. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10078. result = TRUE;
  10079. return result;
  10080. }
  10081. else
  10082. {
  10083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10084. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10085. }
  10086. if(strcmp(comfirmstr,"Accepted") == 0)
  10087. {
  10088. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10089. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10090. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10091. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10092. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10093. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  10094. result = TRUE;
  10095. return result;
  10096. }
  10097. end:
  10098. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10099. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10100. return result;
  10101. }
  10102. int handleResetRequest(char *uuid, char *payload)
  10103. {
  10104. mtrace();
  10105. int result = FAIL;
  10106. char sstr[10]={0},sstrtemp[30]={ 0 };
  10107. char typestr[10]={0};
  10108. char comfirmstr[20]={0};
  10109. int c = 0;
  10110. char *loc;
  10111. DEBUG_INFO("handleResetRequest...\n");
  10112. strcpy(sstrtemp, stringtrimspace(payload));
  10113. loc = strstr(sstrtemp, "type");
  10114. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10115. c = 0;
  10116. while (loc[3+strlen("type")+c] != '\"')
  10117. {
  10118. sstr[c] = loc[3+strlen("type")+c];
  10119. c++;
  10120. }
  10121. sstr[c] = '\0';
  10122. strcpy(typestr,sstr);
  10123. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  10124. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10125. {
  10126. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  10127. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  10128. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10129. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10130. }
  10131. else
  10132. {
  10133. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10134. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10135. result = PASS;
  10136. }
  10137. sendResetConfirmation(uuid, comfirmstr);
  10138. return result;
  10139. }
  10140. int handleSendLocalListRequest(char *uuid, char *payload)
  10141. {
  10142. mtrace();
  10143. int result = FAIL;
  10144. char comfirmstr[20];
  10145. int checkState_Faulted = FALSE;
  10146. json_object *SendLocalList;
  10147. DEBUG_INFO("handleSendLocalListRequest...\n");
  10148. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10149. {
  10150. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10151. goto end;
  10152. }
  10153. //check Charge Point state
  10154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10155. {
  10156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10157. {
  10158. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10159. }
  10160. }
  10161. for (int index = 0; index < CCS_QUANTITY; index++)
  10162. {
  10163. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10164. {
  10165. checkState_Faulted = TRUE; //OCPP Status
  10166. }
  10167. }
  10168. for (int index = 0; index < GB_QUANTITY; index++)
  10169. {
  10170. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10171. {
  10172. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10173. }
  10174. }
  10175. //check Charge Point state
  10176. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10177. {
  10178. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10179. {
  10180. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10181. }
  10182. }
  10183. //check Charge Point state
  10184. for (int index = 0; index < AC_QUANTITY; index++)
  10185. {
  10186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10187. {
  10188. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10189. }
  10190. }
  10191. if(checkState_Faulted == TRUE)
  10192. {
  10193. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10194. goto end;
  10195. }
  10196. // Parsing payload
  10197. SendLocalList = json_tokener_parse(payload);
  10198. if(!is_error(SendLocalList))
  10199. {
  10200. // Required data
  10201. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10202. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10203. // Optional data
  10204. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10205. {
  10206. //Check UpdateType
  10207. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10208. {
  10209. //Local list full update
  10210. DEBUG_INFO("Local list full update.\n");
  10211. OCPP_getListVerion();
  10212. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10213. {
  10214. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10215. goto end;
  10216. }
  10217. OCPP_cleanLocalList();
  10218. }
  10219. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10220. {
  10221. //Local list different update
  10222. DEBUG_INFO("Local list different update.\n");
  10223. OCPP_getListVerion();
  10224. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10225. {
  10226. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10227. goto end;
  10228. }
  10229. }
  10230. else
  10231. {
  10232. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10233. goto end;
  10234. }
  10235. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10236. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10237. {
  10238. 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")));
  10239. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10240. {
  10241. 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")));
  10242. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10243. 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")));
  10244. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10245. 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")));
  10246. }
  10247. // Add to db
  10248. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10249. {
  10250. //Local list full update
  10251. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10252. idx,
  10253. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10254. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10255. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10256. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10257. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10258. // update list
  10259. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10260. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10261. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10262. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10263. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10264. }
  10265. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10266. {
  10267. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10268. idx,
  10269. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10270. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10271. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10272. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10273. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  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. }
  10281. }
  10282. else
  10283. {
  10284. //Check UpdateType
  10285. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10286. {
  10287. //Local list full update
  10288. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10289. OCPP_cleanLocalList();
  10290. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10291. goto end;
  10292. }
  10293. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10294. {
  10295. //Local list different update
  10296. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10297. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10298. goto end;
  10299. }
  10300. }
  10301. result = PASS;
  10302. }
  10303. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10304. end:
  10305. json_object_put(SendLocalList);
  10306. sendSendLocalListConfirmation(uuid, comfirmstr);
  10307. return result;
  10308. }
  10309. #define MAX 200
  10310. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10311. {
  10312. mtrace();
  10313. int result = FAIL;
  10314. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10315. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10316. char chargingProfilePurposeStr[30]={0};
  10317. char chargingProfileKindStr[16]={0};
  10318. char recurrencyKindStr[10]={0};
  10319. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10320. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10321. int chargingSchedulePeriodCount = 0;
  10322. char comfirmstr[20]={0};
  10323. int meet= FALSE;
  10324. FILE *fptr1;
  10325. char filename[MAX]={0};
  10326. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  10327. char rmFileCmd[50]={0};
  10328. char tempchargingProfilePurposeStr[30]={0};
  10329. char word[1600]={0};
  10330. int n_chargingProfile = 0;
  10331. json_object *SetChargingProfile;
  10332. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10333. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10334. SetChargingProfile = json_tokener_parse(payload);
  10335. if(!is_error(SetChargingProfile))
  10336. {
  10337. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10338. {
  10339. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10340. if(connectorIdInt == 0)
  10341. {
  10342. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10343. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10344. }
  10345. else
  10346. {
  10347. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10348. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10349. }
  10350. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10351. }
  10352. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10353. {
  10354. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10355. {
  10356. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10357. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10358. {
  10359. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10360. }
  10361. else
  10362. {
  10363. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10364. }
  10365. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10366. }
  10367. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10368. {
  10369. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10370. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10371. {
  10372. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10373. }
  10374. else
  10375. {
  10376. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10377. }
  10378. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10379. }
  10380. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10381. {
  10382. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10383. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10384. {
  10385. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10386. }
  10387. else
  10388. {
  10389. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10390. }
  10391. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10392. }
  10393. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10394. {
  10395. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10396. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10397. {
  10398. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10399. }
  10400. else
  10401. {
  10402. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10403. }
  10404. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10405. }
  10406. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10407. {
  10408. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10409. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10410. {
  10411. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10412. }
  10413. else
  10414. {
  10415. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10416. }
  10417. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10418. }
  10419. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10420. {
  10421. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10422. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10423. {
  10424. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10425. }
  10426. else
  10427. {
  10428. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10429. }
  10430. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10431. }
  10432. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10433. {
  10434. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10435. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10436. {
  10437. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10438. }
  10439. else
  10440. {
  10441. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10442. }
  10443. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10444. }
  10445. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10446. {
  10447. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10448. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10449. {
  10450. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10451. }
  10452. else
  10453. {
  10454. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10455. }
  10456. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10457. }
  10458. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10459. {
  10460. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10461. {
  10462. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10464. {
  10465. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10466. }
  10467. else
  10468. {
  10469. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10470. }
  10471. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10472. }
  10473. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10474. {
  10475. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10476. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10477. {
  10478. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10479. }
  10480. else
  10481. {
  10482. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10483. }
  10484. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10485. }
  10486. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10487. {
  10488. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10489. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10490. {
  10491. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10492. }
  10493. else
  10494. {
  10495. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10496. }
  10497. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10498. }
  10499. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10500. {
  10501. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10503. {
  10504. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10505. }
  10506. else
  10507. {
  10508. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10509. }
  10510. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10511. }
  10512. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10513. {
  10514. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10515. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10516. if(chargingSchedulePeriodCount <= 10)
  10517. {
  10518. 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++)
  10519. {
  10520. 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)
  10521. {
  10522. 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"));
  10523. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10524. {
  10525. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10526. }
  10527. else
  10528. {
  10529. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10530. }
  10531. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10532. }
  10533. 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)
  10534. {
  10535. 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"));
  10536. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10537. {
  10538. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10539. }
  10540. else
  10541. {
  10542. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10543. }
  10544. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10545. }
  10546. 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)
  10547. {
  10548. 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"));
  10549. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10550. {
  10551. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10552. }
  10553. else
  10554. {
  10555. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10556. }
  10557. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10558. }
  10559. }
  10560. }
  10561. }
  10562. }
  10563. }
  10564. }
  10565. json_object_put(SetChargingProfile);
  10566. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10567. {
  10568. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10569. goto end;
  10570. }
  10571. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10572. {
  10573. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10574. if(connectorIdInt != 0)
  10575. {
  10576. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10577. goto end;
  10578. }
  10579. strcpy(filename, ChargePointMaxProfile_JSON );
  10580. fptr1 = fopen(filename, "r");
  10581. if (!fptr1)
  10582. {
  10583. //file not exist
  10584. DEBUG_INFO("Unable to open the input file!!\n");
  10585. fptr1 = fopen(filename, "w+");
  10586. }
  10587. else
  10588. {
  10589. //Check Charging Profile Count
  10590. while(fscanf(fptr1, "%s", word) != EOF)
  10591. {
  10592. //DEBUG_INFO("word=%s\n",word);
  10593. if(strstr(word, "chargingProfileId")!= NULL)
  10594. {
  10595. //DEBUG_INFO("test chargingProfileId \n");
  10596. n_chargingProfile = n_chargingProfile + 1;
  10597. //DEBUG_INFO("chargingProfileId Found\n");
  10598. }
  10599. }
  10600. }
  10601. fclose(fptr1);
  10602. }
  10603. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10604. {
  10605. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10606. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10607. {
  10608. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10609. goto end;
  10610. }
  10611. memset(filename, 0, ARRAY_SIZE(filename));
  10612. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  10613. fptr1 = fopen(filename, "r");
  10614. if (!fptr1)
  10615. {
  10616. //file not exist
  10617. //DEBUG_INFO("Unable to open the input file!!\n");
  10618. fptr1 = fopen(filename, "w+");
  10619. }
  10620. else
  10621. {
  10622. //Check Charging Profile Count
  10623. while(fscanf(fptr1, "%s", word) != EOF)
  10624. {
  10625. //DEBUG_INFO("word=%s\n",word);
  10626. if(strstr(word, "chargingProfileId")!= NULL)
  10627. {
  10628. //DEBUG_INFO("test chargingProfileId \n");
  10629. n_chargingProfile = n_chargingProfile + 1;
  10630. //DEBUG_INFO("chargingProfileId Found\n");
  10631. }
  10632. }
  10633. }
  10634. fclose(fptr1);
  10635. }
  10636. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10637. {
  10638. //printf("set chargingProfile 1-4\n");
  10639. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10640. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10641. if(connectorIdInt == 0)
  10642. {
  10643. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10644. goto end;
  10645. }
  10646. int tempIndex = 0;
  10647. //check Transaction active
  10648. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10649. {
  10650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10651. {
  10652. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10653. }
  10654. else
  10655. {
  10656. tempIndex = connectorIdInt -1;
  10657. }
  10658. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10659. {
  10660. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10661. {
  10662. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10663. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10664. {
  10665. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10666. {
  10667. meet = TRUE;
  10668. break;
  10669. }
  10670. }
  10671. }
  10672. }
  10673. }
  10674. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10675. {
  10676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10677. {
  10678. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10679. }
  10680. else
  10681. {
  10682. tempIndex = connectorIdInt -1;
  10683. }
  10684. for (int index = 0; index < CCS_QUANTITY; index++)
  10685. {
  10686. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10687. {
  10688. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10689. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10690. {
  10691. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10692. {
  10693. meet = TRUE;
  10694. break;
  10695. }
  10696. }
  10697. }
  10698. }
  10699. }
  10700. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10701. {
  10702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10703. {
  10704. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10705. }
  10706. else
  10707. {
  10708. tempIndex = connectorIdInt -1;
  10709. }
  10710. for (int index = 0; index < GB_QUANTITY; index++)
  10711. {
  10712. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10713. {
  10714. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10715. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10716. {
  10717. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10718. {
  10719. meet = TRUE;
  10720. break;
  10721. }
  10722. }
  10723. }
  10724. }
  10725. }
  10726. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10727. {
  10728. tempIndex = connectorIdInt -1;
  10729. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10730. {
  10731. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10732. {
  10733. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10734. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10735. {
  10736. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10737. {
  10738. meet = TRUE;
  10739. break;
  10740. }
  10741. }
  10742. }
  10743. }
  10744. }
  10745. else
  10746. {
  10747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10748. {
  10749. tempIndex = 2;
  10750. }
  10751. else
  10752. {
  10753. tempIndex = (connectorIdInt -1);
  10754. }
  10755. for (int index = 0; index < AC_QUANTITY; index++)
  10756. {
  10757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10758. {
  10759. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10760. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10761. {
  10762. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10763. {
  10764. meet = TRUE;
  10765. break;
  10766. }
  10767. }
  10768. }
  10769. }
  10770. }
  10771. //check Transaction active
  10772. if(meet == FALSE)
  10773. {
  10774. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10775. goto end;
  10776. }
  10777. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10778. {
  10779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10780. goto end;
  10781. }
  10782. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10783. fptr1 = fopen(filename, "r");
  10784. if (!fptr1)
  10785. {
  10786. //file not exist
  10787. DEBUG_INFO("Unable to open the input file!!\n");
  10788. fptr1 = fopen(filename, "w+");
  10789. }
  10790. else
  10791. {
  10792. //Check Charging Profile Count
  10793. while(fscanf(fptr1, "%s", word) != EOF)
  10794. {
  10795. //DEBUG_INFO("word=%s\n",word);
  10796. if(strstr(word, "chargingProfileId")!= NULL)
  10797. {
  10798. //DEBUG_INFO("test chargingProfileId \n");
  10799. n_chargingProfile = n_chargingProfile + 1;
  10800. //DEBUG_INFO("chargingProfileId Found\n");
  10801. }
  10802. }
  10803. }
  10804. fclose(fptr1);
  10805. }
  10806. // Check ChargeProfileMaxStackLevel
  10807. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10808. {
  10809. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10810. goto end;
  10811. }
  10812. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10813. {
  10814. int i = 0;
  10815. char fnametemp[200]={0};
  10816. n_chargingProfile = 0;
  10817. //Check ChargePointMaxProfile.json exit
  10818. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  10819. {
  10820. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  10821. //Check Charging Profile Count
  10822. while(fscanf(fptr1, "%s", word) != EOF)
  10823. {
  10824. //DEBUG_INFO("word=%s\n",word);
  10825. if(strstr(word, "chargingProfileId")!= NULL)
  10826. {
  10827. //DEBUG_INFO("test chargingProfileId \n");
  10828. n_chargingProfile = n_chargingProfile + 1;
  10829. i = i + 1;
  10830. //DEBUG_INFO("chargingProfileId Found\n");
  10831. }
  10832. memset(word, 0, ARRAY_SIZE(word));
  10833. }
  10834. fclose(fptr1);
  10835. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10836. }
  10837. //Check TxDefaultProfile_0.json exit
  10838. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  10839. {
  10840. i = 0;
  10841. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  10842. //Check Charging Profile Count
  10843. while(fscanf(fptr1, "%s", word) != EOF)
  10844. {
  10845. //DEBUG_INFO("word=%s\n",word);
  10846. if(strstr(word, "chargingProfileId")!= NULL)
  10847. {
  10848. //DEBUG_INFO("test chargingProfileId \n");
  10849. n_chargingProfile = n_chargingProfile + 1;
  10850. i = i + 1;
  10851. //DEBUG_INFO("chargingProfileId Found\n");
  10852. }
  10853. memset(word, 0, ARRAY_SIZE(word));
  10854. }
  10855. fclose(fptr1);
  10856. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10857. }
  10858. //Check TxDefaultProfile_%d.json
  10859. for(int j=1; j <= gunTotalNumber; j++)
  10860. {
  10861. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10862. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10863. if((access(fnametemp,F_OK))!=-1)
  10864. {
  10865. i = 0;
  10866. fptr1 = fopen(fnametemp, "r");
  10867. //Check Charging Profile Count
  10868. while(fscanf(fptr1, "%s", word) != EOF)
  10869. {
  10870. //DEBUG_INFO("word=%s\n",word);
  10871. if(strstr(word, "chargingProfileId")!= NULL)
  10872. {
  10873. //DEBUG_INFO("test chargingProfileId \n");
  10874. n_chargingProfile = n_chargingProfile + 1;
  10875. i = i + 1;
  10876. //DEBUG_INFO("chargingProfileId Found\n");
  10877. }
  10878. memset(word, 0, ARRAY_SIZE(word));
  10879. }
  10880. fclose(fptr1);
  10881. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10882. }
  10883. }
  10884. //Check TxProfile_%d.json
  10885. for(int j=1; j <= gunTotalNumber; j++)
  10886. {
  10887. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10888. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10889. if((access(fnametemp,F_OK))!=-1)
  10890. {
  10891. i = 0;
  10892. fptr1 = fopen(fnametemp, "r");
  10893. //Check Charging Profile Count
  10894. while(fscanf(fptr1, "%s", word) != EOF)
  10895. {
  10896. //DEBUG_INFO("word=%s\n",word);
  10897. if(strstr(word, "chargingProfileId")!= NULL)
  10898. {
  10899. //DEBUG_INFO("test chargingProfileId \n");
  10900. n_chargingProfile = n_chargingProfile + 1;
  10901. i = i + 1;
  10902. //DEBUG_INFO("chargingProfileId Found\n");
  10903. }
  10904. memset(word, 0, ARRAY_SIZE(word));
  10905. }
  10906. fclose(fptr1);
  10907. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10908. }
  10909. }
  10910. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10911. {
  10912. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10913. goto end;
  10914. }
  10915. }
  10916. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10917. //**********************************Write to File********************************************************/
  10918. FILE *infile;
  10919. FILE *outfile;
  10920. infile = fopen (filename, "r");
  10921. outfile = fopen (tempfile, "w");
  10922. int d =0;
  10923. d = fgetc(infile);
  10924. rewind(infile);
  10925. if(d == EOF)
  10926. {
  10927. // Profile is empty
  10928. fprintf(outfile,"%s\n",payload);
  10929. fclose(infile);
  10930. fclose(outfile);
  10931. sprintf(rmFileCmd,"rm -f %s",filename);
  10932. system(rmFileCmd);
  10933. rename(tempfile, filename);
  10934. }
  10935. else
  10936. {
  10937. // Profile is not empty
  10938. char buf[2048]={0};
  10939. int ChargingProfileAdded = FALSE;
  10940. while (fgets(buf, sizeof(buf), infile) != NULL)
  10941. {
  10942. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10943. json_object *tmpChargingProfile;
  10944. tmpChargingProfile = json_tokener_parse(buf);
  10945. if(!is_error(SetChargingProfile))
  10946. {
  10947. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10948. {
  10949. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10950. }
  10951. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10952. {
  10953. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10954. {
  10955. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10956. }
  10957. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10958. {
  10959. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10960. }
  10961. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10962. {
  10963. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10964. }
  10965. }
  10966. }
  10967. json_object_put(tmpChargingProfile);
  10968. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10969. {
  10970. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10971. {
  10972. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10973. if(ChargingProfileAdded == FALSE)
  10974. {
  10975. fprintf(outfile,"%s\n",payload);
  10976. ChargingProfileAdded = TRUE;
  10977. }
  10978. }
  10979. else
  10980. {
  10981. if(tempstackLevelInt < stackLevelInt)
  10982. {
  10983. if(ChargingProfileAdded == FALSE)
  10984. {
  10985. fprintf(outfile,"%s\n",buf);
  10986. fprintf(outfile,"%s\n",payload);
  10987. ChargingProfileAdded = TRUE;
  10988. }
  10989. else
  10990. {
  10991. fprintf(outfile,"%s\n",buf);
  10992. }
  10993. }
  10994. else
  10995. {
  10996. if(ChargingProfileAdded == FALSE)
  10997. {
  10998. fprintf(outfile,"%s\n",buf);
  10999. fprintf(outfile,"%s\n",payload);
  11000. ChargingProfileAdded = TRUE;
  11001. }
  11002. else
  11003. {
  11004. fprintf(outfile,"%s\n",buf);
  11005. }
  11006. }
  11007. }
  11008. }
  11009. else
  11010. {
  11011. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11012. {
  11013. if(ChargingProfileAdded == FALSE)
  11014. {
  11015. fprintf(outfile,"%s\n",buf);
  11016. fprintf(outfile,"%s\n",payload);
  11017. ChargingProfileAdded = TRUE;
  11018. }
  11019. else
  11020. {
  11021. fprintf(outfile,"%s\n",buf);
  11022. }
  11023. }
  11024. else if(tempstackLevelInt < stackLevelInt)
  11025. {
  11026. if(ChargingProfileAdded == FALSE)
  11027. {
  11028. fprintf(outfile,"%s\n",buf);
  11029. fprintf(outfile,"%s\n",payload);
  11030. ChargingProfileAdded = TRUE;
  11031. }
  11032. else
  11033. {
  11034. fprintf(outfile,"%s\n",buf);
  11035. }
  11036. }
  11037. else
  11038. {
  11039. if(ChargingProfileAdded == FALSE)
  11040. {
  11041. fprintf(outfile,"%s\n",buf);
  11042. fprintf(outfile,"%s\n",payload);
  11043. ChargingProfileAdded = TRUE;
  11044. }
  11045. else
  11046. {
  11047. fprintf(outfile,"%s\n",buf);
  11048. }
  11049. }
  11050. }
  11051. } // end of while loop
  11052. fclose(infile);
  11053. fclose(outfile);
  11054. sprintf(rmFileCmd,"rm -f %s",filename);
  11055. system(rmFileCmd);
  11056. rename(tempfile, filename);
  11057. }
  11058. sleep(1);
  11059. result = TRUE;
  11060. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11061. end:
  11062. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11063. {
  11064. if(connectorIdInt == 0)
  11065. {
  11066. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11067. {
  11068. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11069. }
  11070. }
  11071. else
  11072. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  11073. }
  11074. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11075. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11076. return result;
  11077. }
  11078. int handleTriggerMessageRequest(char *uuid, char *payload)
  11079. {
  11080. mtrace();
  11081. int result = FAIL;
  11082. int connectorIdIsNULL = FALSE;
  11083. int connectorIdInt =0;
  11084. char sstr[40]={0},sstrtemp[100]={ 0 };
  11085. char requestedMessagestr[40]={0};
  11086. char comfirmstr[20]={0};
  11087. int c = 0;
  11088. char *loc;
  11089. DEBUG_INFO("handleTriggerMessageRequest\n");
  11090. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11091. strcpy(sstrtemp, stringtrimspace(payload));
  11092. c = 0;
  11093. loc = strstr(sstrtemp, "requestedMessage");
  11094. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11095. {
  11096. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11097. c++;
  11098. }
  11099. sstr[c] = '\0';
  11100. strcpy(requestedMessagestr, sstr);
  11101. c = 0;
  11102. loc = strstr(sstrtemp, "connectorId");
  11103. if(loc == NULL)
  11104. {
  11105. connectorIdIsNULL = TRUE;
  11106. }
  11107. else
  11108. {
  11109. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11110. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11111. {
  11112. sstr[c] = loc[strlen("connectorId")+2+c];
  11113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11114. c++;
  11115. }
  11116. sstr[c] = '\0';
  11117. connectorIdInt = atoi(sstr);
  11118. }
  11119. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11120. {
  11121. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11122. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11123. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11124. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11125. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11126. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11127. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11128. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11129. {
  11130. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11131. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11132. return TRUE;
  11133. }
  11134. else
  11135. {
  11136. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11137. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11138. }
  11139. }
  11140. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11141. {
  11142. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11143. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11144. return TRUE;
  11145. }
  11146. //==========================
  11147. // Trigger message
  11148. //==========================
  11149. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11150. {
  11151. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11152. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11153. {
  11154. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11155. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11156. }
  11157. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11158. }
  11159. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11160. {
  11161. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11162. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11163. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11164. }
  11165. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11166. {
  11167. //sendBootNotificationRequest();
  11168. server_sign = FALSE;
  11169. }
  11170. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11171. {
  11172. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11173. }
  11174. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11175. {
  11176. if(connectorIdIsNULL == FALSE)
  11177. {
  11178. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11179. {
  11180. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11181. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11182. }
  11183. }
  11184. else
  11185. {
  11186. for(int idx=0;idx< gunTotalNumber;idx++)
  11187. {
  11188. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11189. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11190. }
  11191. }
  11192. }
  11193. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11194. {
  11195. if(connectorIdIsNULL == FALSE)
  11196. {
  11197. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11198. {
  11199. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11200. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11201. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11202. }
  11203. }
  11204. else
  11205. {
  11206. for(int idx=0;idx< gunTotalNumber;idx++)
  11207. {
  11208. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11209. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11210. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11211. }
  11212. }
  11213. }
  11214. return result;
  11215. }
  11216. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11217. {
  11218. mtrace();
  11219. int result = FAIL;
  11220. int connectorIdInt =0;
  11221. char comfirmstr[20]={0};
  11222. int tempIndex = 0;
  11223. json_object *UnlockConnector;
  11224. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11225. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11226. UnlockConnector = json_tokener_parse(payload);
  11227. if(!is_error(UnlockConnector))
  11228. {
  11229. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11230. {
  11231. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11232. }
  11233. }
  11234. json_object_put(UnlockConnector);
  11235. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11236. if(gunTotalNumber == 0)
  11237. {
  11238. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11239. goto end;
  11240. }
  11241. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11242. {
  11243. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11244. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11245. goto end;
  11246. }
  11247. else
  11248. {
  11249. //check Transaction active
  11250. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11251. {
  11252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11253. {
  11254. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11255. }
  11256. else
  11257. {
  11258. tempIndex = connectorIdInt -1;
  11259. }
  11260. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11261. {
  11262. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11263. {
  11264. //stop Transaction
  11265. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11266. }
  11267. }
  11268. }
  11269. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11270. {
  11271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11272. {
  11273. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11274. }
  11275. else
  11276. {
  11277. tempIndex = connectorIdInt -1;
  11278. }
  11279. for (int index = 0; index < CCS_QUANTITY; index++)
  11280. {
  11281. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11282. {
  11283. //stop Transaction
  11284. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11285. }
  11286. }
  11287. }
  11288. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11289. {
  11290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11291. {
  11292. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11293. }
  11294. else
  11295. {
  11296. tempIndex = connectorIdInt -1;
  11297. }
  11298. for (int index = 0; index < GB_QUANTITY; index++)
  11299. {
  11300. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11301. {
  11302. //stop Transaction
  11303. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11304. }
  11305. }
  11306. }
  11307. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11308. {
  11309. tempIndex = connectorIdInt -1;
  11310. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11311. {
  11312. 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)))
  11313. {
  11314. //stop Transaction
  11315. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11316. }
  11317. }
  11318. }
  11319. else
  11320. {
  11321. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11322. {
  11323. tempIndex = 2;
  11324. }
  11325. else
  11326. {
  11327. tempIndex = connectorIdInt-1;
  11328. }
  11329. for (int index = 0; index < AC_QUANTITY; index++)
  11330. {
  11331. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11332. {
  11333. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11334. }
  11335. }
  11336. }
  11337. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11338. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11339. result = TRUE;
  11340. return result;
  11341. }
  11342. end:
  11343. //json_object_put(obj); --- remove temporally
  11344. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11345. return result;
  11346. }
  11347. static char UpdateFirmwarepayloadData[300]={0};
  11348. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11349. {
  11350. mtrace();
  11351. int result = FAIL;
  11352. pthread_t t;
  11353. sendUpdateFirmwareConfirmation(uuid);
  11354. memset(UpdateFirmwarepayloadData, 0, 300);
  11355. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11356. if(!interLock.isUpdateFirmwareGoing)
  11357. {
  11358. interLock.isUpdateFirmwareGoing = 1;
  11359. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11360. }
  11361. else
  11362. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11363. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11364. return result;
  11365. }
  11366. void *UpdateFirmwareProcess(void *data)
  11367. {
  11368. pthread_detach(pthread_self());
  11369. mtrace();
  11370. int retriesInt =0, retryIntervalInt=0;
  11371. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11372. int port=0;
  11373. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11374. int isSuccess = 0;
  11375. char ftpbuf[512];
  11376. char temp[100];
  11377. char * pch;
  11378. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11379. json_object *UpdateFirmware;
  11380. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11381. if(!is_error(UpdateFirmware))
  11382. {
  11383. // Required data
  11384. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11385. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11386. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11387. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11388. // Optional data
  11389. if(json_object_object_get(UpdateFirmware, "retries"))
  11390. {
  11391. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11392. }
  11393. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11394. {
  11395. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11396. }
  11397. }
  11398. json_object_put(UpdateFirmware);
  11399. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11400. memset(path, 0, ARRAY_SIZE(path));
  11401. // Wait retrieveData
  11402. if(strlen(retrieveDatestr) > 10)
  11403. {
  11404. do
  11405. {
  11406. sleep(1);
  11407. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11408. }
  11409. // Ready to download
  11410. system("rm -f /mnt/*");
  11411. if(strncmp(locationstr,"http", 4) == 0)
  11412. {
  11413. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11414. sprintf(ftppath,"/%s", path);
  11415. DEBUG_INFO("locationstr: %s\n", locationstr);
  11416. DEBUG_INFO("protocol: %s\n",protocol);
  11417. DEBUG_INFO("host: %s\n",host);
  11418. DEBUG_INFO("path: %s\n",path);
  11419. DEBUG_INFO("ftppath: %s\n",ftppath);
  11420. int ftppathlen=strlen(ftppath);
  11421. int i=1;
  11422. char filenametemp[50];
  11423. while(i < ftppathlen)
  11424. {
  11425. int len=ftppathlen-i;
  11426. if(ftppath[len]== 47) // '/' ascll code: 47
  11427. {
  11428. DEBUG_INFO("compare '/' all right\n");
  11429. break;
  11430. }
  11431. i=i+1;
  11432. }
  11433. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11434. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11435. filenametemp[i+1] = 0;
  11436. do
  11437. {
  11438. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11439. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11440. sleep(1);
  11441. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11442. if(!isSuccess)
  11443. {
  11444. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11445. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11446. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11447. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11448. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11449. }
  11450. else
  11451. {
  11452. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11453. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11454. }
  11455. retriesInt--;
  11456. }while((isSuccess == 0)&&(retriesInt >= 0));
  11457. }
  11458. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11459. {
  11460. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11461. memset(temp, 0, ARRAY_SIZE(temp));
  11462. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11463. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11464. int ftppathlen=strlen(ftpbuf);
  11465. int i=1;
  11466. char filenametemp[50];
  11467. while(i < ftppathlen)
  11468. {
  11469. int len=ftppathlen-i;
  11470. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11471. {
  11472. DEBUG_INFO(" compare '/' all right\n");
  11473. break;
  11474. }
  11475. i=i+1;
  11476. }
  11477. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11478. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11479. filenametemp[i+1] = 0;
  11480. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11481. pch=strchr(temp,'@');
  11482. if(pch==NULL)
  11483. {
  11484. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11485. protocol, host, &port, path);
  11486. strcpy(user,"anonymous");
  11487. strcpy(password,"");
  11488. }
  11489. else
  11490. {
  11491. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11492. protocol, user, password, host, &port, path);
  11493. }
  11494. sscanf(host,"%[^/]%s",host1, path1);
  11495. sprintf(ftppath,"%s", path1);
  11496. //DEBUG_INFO("protocol =%s\n",protocol);
  11497. //DEBUG_INFO("user =%s\n",user);
  11498. //DEBUG_INFO("password =%s\n",password);
  11499. //DEBUG_INFO("host1 =%s\n",host1);
  11500. //DEBUG_INFO("port =%d\n",port);
  11501. //DEBUG_INFO("path1 =%s\n",path1);
  11502. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11503. //ftpFile(host, user, password, port, ftppath, fname);
  11504. //download firmware pthred
  11505. if(port == 0)
  11506. {
  11507. port = 21;
  11508. }
  11509. do
  11510. {
  11511. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11512. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11513. sleep(1);
  11514. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11515. if(!isSuccess)
  11516. {
  11517. //BulldogUtil.sleepMs(interval*1000);
  11518. DEBUG_INFO("Update firmware request and download file fail.\n");
  11519. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11520. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11521. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11522. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11523. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11524. }
  11525. else
  11526. {
  11527. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11528. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11529. }
  11530. retriesInt--;
  11531. }while((!isSuccess)&&(retriesInt >= 0));
  11532. }
  11533. else
  11534. {
  11535. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11536. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11537. sleep(1);
  11538. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11539. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11540. }
  11541. // OCPPPH only, must announce CSU upgrade firmware
  11542. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11543. interLock.isUpdateFirmwareGoing = 0;
  11544. pthread_exit(NULL);
  11545. }
  11546. int handleCertificateSignedRequest(char *uuid, char *payload)
  11547. {
  11548. mtrace();
  11549. int result = PASS;
  11550. json_object *CertificateSigned;
  11551. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11552. CertificateSigned = json_tokener_parse(payload);
  11553. if(!is_error(CertificateSigned))
  11554. {
  11555. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11556. }
  11557. json_object_put(CertificateSigned);
  11558. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11559. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11560. fclose(fp);
  11561. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11562. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11563. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11564. sendCertificateSignedConfirmation(uuid);
  11565. return result;
  11566. }
  11567. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11568. {
  11569. mtrace();
  11570. int result = PASS;
  11571. json_object *DeleteCertificate;
  11572. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11573. DeleteCertificate = json_tokener_parse(payload);
  11574. if(!is_error(DeleteCertificate))
  11575. {
  11576. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11577. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11578. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11579. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11580. }
  11581. json_object_put(DeleteCertificate);
  11582. /*
  11583. * TODO: Delete certificateSigned process
  11584. */
  11585. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11586. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11587. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11588. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11589. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11590. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11591. sendDeleteCertificateConfirmation(uuid);
  11592. return result;
  11593. }
  11594. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11595. {
  11596. mtrace();
  11597. int result = PASS;
  11598. json_object *ExtendedTriggerMessage;
  11599. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11600. ExtendedTriggerMessage = json_tokener_parse(payload);
  11601. if(!is_error(ExtendedTriggerMessage))
  11602. {
  11603. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11604. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11605. {
  11606. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11607. }
  11608. else
  11609. {
  11610. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11611. }
  11612. }
  11613. json_object_put(ExtendedTriggerMessage);
  11614. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11615. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11616. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11617. {
  11618. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11619. }
  11620. else
  11621. {
  11622. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11623. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11624. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11625. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11626. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11627. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11628. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11629. {
  11630. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11631. }
  11632. else
  11633. {
  11634. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11635. }
  11636. }
  11637. sendExtendedTriggerMessageConfirmation(uuid);
  11638. //==========================
  11639. // Trigger message
  11640. //==========================
  11641. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11642. {
  11643. //sendBootNotificationRequest();
  11644. server_sign = FALSE;
  11645. }
  11646. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11647. {
  11648. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11649. }
  11650. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11651. {
  11652. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11653. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11654. {
  11655. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11656. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11657. }
  11658. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11659. }
  11660. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11661. {
  11662. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11663. }
  11664. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11665. {
  11666. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11667. {
  11668. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11669. }
  11670. else
  11671. {
  11672. for(int idx=0;idx< gunTotalNumber;idx++)
  11673. {
  11674. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11675. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11676. }
  11677. }
  11678. }
  11679. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11680. {
  11681. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11682. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11683. {
  11684. 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\" &");
  11685. }
  11686. }
  11687. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11688. {
  11689. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11690. {
  11691. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11692. }
  11693. else
  11694. {
  11695. for(int idx=0;idx< gunTotalNumber;idx++)
  11696. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11697. }
  11698. }
  11699. return result;
  11700. }
  11701. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11702. {
  11703. mtrace();
  11704. int result = PASS;
  11705. json_object *GetInstalledCertificateIds;
  11706. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11707. GetInstalledCertificateIds = json_tokener_parse(payload);
  11708. if(!is_error(GetInstalledCertificateIds))
  11709. {
  11710. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11711. }
  11712. json_object_put(GetInstalledCertificateIds);
  11713. /*
  11714. * TODO: Return installed certificate process
  11715. */
  11716. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11717. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11718. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11719. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11720. sendGetInstalledCertificateIdsConfirmation(uuid);
  11721. return result;
  11722. }
  11723. int handleGetLogRequest(char *uuid, char *payload)
  11724. {
  11725. mtrace();
  11726. int result = PASS;
  11727. json_object *GetLog;
  11728. DEBUG_INFO("handleGetLogRequest...\n");
  11729. GetLog = json_tokener_parse(payload);
  11730. if(!is_error(GetLog))
  11731. {
  11732. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11733. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11734. if(json_object_object_get(GetLog, "retries") != NULL)
  11735. {
  11736. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11737. }
  11738. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11739. {
  11740. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11741. }
  11742. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11743. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11744. {
  11745. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11746. }
  11747. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11748. {
  11749. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11750. }
  11751. }
  11752. json_object_put(GetLog);
  11753. /*
  11754. * TODO: Upload log process
  11755. */
  11756. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11757. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11758. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11759. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11760. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11761. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11762. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11763. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11764. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11765. sendGetLogConfirmation(uuid);
  11766. return result;
  11767. }
  11768. int handleInstallCertificateRequest(char *uuid, char *payload)
  11769. {
  11770. mtrace();
  11771. int result = PASS;
  11772. json_object *InstallCertificate;
  11773. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11774. InstallCertificate = json_tokener_parse(payload);
  11775. if(!is_error(InstallCertificate))
  11776. {
  11777. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11778. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11779. /*
  11780. * TODO: Install certificate process
  11781. */
  11782. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11783. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11784. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11785. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11786. sendInstallCertificateConfirmation(uuid);
  11787. }
  11788. json_object_put(InstallCertificate);
  11789. return result;
  11790. }
  11791. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11792. {
  11793. mtrace();
  11794. int result = PASS;
  11795. json_object *SignedUpdateFirmware;
  11796. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11797. SignedUpdateFirmware = json_tokener_parse(payload);
  11798. if(!is_error(SignedUpdateFirmware))
  11799. {
  11800. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11801. {
  11802. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11803. }
  11804. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11805. {
  11806. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11807. }
  11808. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11809. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11810. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11811. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11812. {
  11813. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11814. }
  11815. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11816. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11817. }
  11818. json_object_put(SignedUpdateFirmware);
  11819. /*
  11820. * TODO: Upgrade firmware process
  11821. */
  11822. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11823. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11824. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11825. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11826. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11827. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11828. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11829. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11830. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11831. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11832. sendInstallCertificateConfirmation(uuid);
  11833. return result;
  11834. }
  11835. int handleUnknownRequest(char *uuid, char *payload)
  11836. {
  11837. mtrace();
  11838. int result = PASS;
  11839. DEBUG_INFO("handleUnknownRequest...\n");
  11840. sendUnknownConfirmation(uuid);
  11841. result = PASS;
  11842. return result;
  11843. }
  11844. //==========================================
  11845. // Handle server response routine
  11846. //==========================================
  11847. void handleAuthorizeResponse(char *payload, int gun_index)
  11848. {
  11849. mtrace();
  11850. char expiryDatestr[30]={0};
  11851. char parentIdTagstr[20]={0};
  11852. char statusstr[20]={0};
  11853. int expiryDateISNULL=FALSE;
  11854. int parentIdTagISNULL=FALSE;
  11855. DEBUG_INFO("handleAuthorizeResponse...\n");
  11856. json_object *Authorize;
  11857. Authorize = json_tokener_parse(payload);
  11858. if(!is_error(Authorize))
  11859. {
  11860. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11861. {
  11862. // Required data
  11863. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11864. // Optional data
  11865. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11866. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11867. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11868. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11869. }
  11870. }
  11871. json_object_put(Authorize);
  11872. if(expiryDateISNULL == FALSE)
  11873. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11874. if(parentIdTagISNULL == FALSE)
  11875. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11876. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11877. //Update idTag information to authorization cache if supproted
  11878. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11879. {
  11880. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11881. }
  11882. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11883. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11884. authorizeRetryTimes = 0;
  11885. }
  11886. void handleBootNotificationResponse(char *payload, int gun_index)
  11887. {
  11888. mtrace();
  11889. char statusStr[12]={0};
  11890. char currentTimeStr[30]={0};
  11891. int intervalInt = 0;
  11892. DEBUG_INFO("handleBootNotificationResponse...\n");
  11893. json_object *BootNotification;
  11894. BootNotification = json_tokener_parse(payload);
  11895. if(!is_error(BootNotification))
  11896. {
  11897. // Required data
  11898. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11899. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11900. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11901. }
  11902. json_object_put(BootNotification);
  11903. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11904. BootNotificationInterval = intervalInt;
  11905. HeartBeatWaitTime = intervalInt;
  11906. //write back to ShmOCPP16DataPH->BootNotification
  11907. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11908. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11909. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11910. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11911. {
  11912. server_sign = TRUE;
  11913. server_pending =FALSE;
  11914. }
  11915. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11916. {
  11917. server_pending = TRUE;
  11918. }
  11919. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11920. srand(time(NULL));
  11921. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11922. SetOcppConnStatus(TRUE);
  11923. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11924. }
  11925. void handleDataTransferResponse(char *payload, int gun_index)
  11926. {
  11927. char sstr[160]={0};//sstr[200]={ 0 };
  11928. int c = 0;
  11929. char *loc;
  11930. DEBUG_INFO("handleDataTransferResponse ...\n");
  11931. loc = strstr(payload, "status");
  11932. c = 0;
  11933. while (loc[3+strlen("status")+c] != '\"')
  11934. {
  11935. sstr[c] = loc[3+strlen("status")+c];
  11936. c++;
  11937. }
  11938. sstr[c] = '\0';
  11939. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11940. }
  11941. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11942. {
  11943. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11944. //struct json_object *obj;
  11945. // obj = json_tokener_parse(payload);
  11946. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11947. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11948. //No fields are defined.
  11949. }
  11950. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11951. {
  11952. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11953. //struct json_object *obj;
  11954. // obj = json_tokener_parse(payload);
  11955. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11956. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11957. //No fields are defined.
  11958. }
  11959. void handleHeartbeatResponse(char *payload, int gun_index)
  11960. {
  11961. mtrace();
  11962. DEBUG_INFO("handleHeartbeatResponse...\n");
  11963. json_object *Heartbeat;
  11964. Heartbeat = json_tokener_parse(payload);
  11965. if(!is_error(Heartbeat))
  11966. {
  11967. // Required data
  11968. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11969. }
  11970. json_object_put(Heartbeat);
  11971. if(FirstHeartBeat == 0)
  11972. {
  11973. FirstHeartBeat = 1;
  11974. DEBUG_INFO("FirstHeartBeat \n");
  11975. }
  11976. HeartBeatWithNOResponse = 0;
  11977. clientTime.Heartbeat=time((time_t*)NULL);
  11978. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11979. }
  11980. void handleMeterValuesResponse(char *payload, int gun_index)
  11981. {
  11982. mtrace();
  11983. DEBUG_INFO("handleMeterValuesResponse...\n");
  11984. }
  11985. void handleStartTransactionResponse(char *payload, int gun_index)
  11986. {
  11987. mtrace();
  11988. //int transactionIdInt = 0;
  11989. FILE *outfile;
  11990. char data[100]={0};
  11991. DEBUG_INFO("handleStartTransactionResponse...\n");
  11992. json_object *StartTransaction;
  11993. StartTransaction = json_tokener_parse(payload);
  11994. if(!is_error(StartTransaction))
  11995. {
  11996. // Required data
  11997. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11998. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11999. // Optional data
  12000. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12001. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12002. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12003. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12004. }
  12005. json_object_put(StartTransaction);
  12006. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12007. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12008. //-----------Start : write to the Queue TransactionId file -----------------//
  12009. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12010. {}
  12011. else
  12012. {
  12013. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12014. if(log == NULL)
  12015. {
  12016. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12017. return ;
  12018. }
  12019. else
  12020. {
  12021. fclose(log);
  12022. }
  12023. }
  12024. // open file for writing
  12025. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12026. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12027. {
  12028. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12029. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12030. fputs(data, outfile);
  12031. fclose (outfile);
  12032. }
  12033. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12034. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12035. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12036. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12037. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12038. }
  12039. void handleStatusNotificationResponse(char *payload, int gun_index)
  12040. {
  12041. mtrace();
  12042. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12043. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12044. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12045. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12046. }
  12047. void handleStopTransactionnResponse(char *payload, int gun_index)
  12048. {
  12049. mtrace();
  12050. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12051. json_object *StopTransaction;
  12052. StopTransaction = json_tokener_parse(payload);
  12053. if(!is_error(StopTransaction))
  12054. {
  12055. // Optional data
  12056. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12057. {
  12058. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12059. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12060. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12061. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12062. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12063. }
  12064. }
  12065. json_object_put(StopTransaction);
  12066. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12067. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12068. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12069. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12070. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12071. }
  12072. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12073. {
  12074. mtrace();
  12075. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12076. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12077. }
  12078. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12079. {
  12080. mtrace();
  12081. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12082. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12083. }
  12084. void handleSignCertificateResponse(char *payload, int gun_index)
  12085. {
  12086. mtrace();
  12087. DEBUG_INFO("handleSignCertificateResponse...\n");
  12088. json_object *SignCertificate;
  12089. SignCertificate = json_tokener_parse(payload);
  12090. if(!is_error(SignCertificate))
  12091. {
  12092. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12093. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12094. }
  12095. json_object_put(SignCertificate);
  12096. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12097. }
  12098. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12099. {
  12100. mtrace();
  12101. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12102. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12103. }
  12104. //==========================================
  12105. // Handle Error routine
  12106. //==========================================
  12107. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12108. {
  12109. mtrace();
  12110. #ifdef SystemLogMessage
  12111. DEBUG_INFO("errorCode: %s\n", errorCode);
  12112. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12113. DEBUG_INFO("errorDetails: %s\n", payload);
  12114. #endif
  12115. }
  12116. //===============================================
  12117. // Common routine
  12118. //===============================================
  12119. int initialConfigurationTable(void)
  12120. {
  12121. //clock_t start_t, end_t, total_t;
  12122. FILE *fp;
  12123. FILE *outfile;
  12124. char str[512]={0};
  12125. char sstr[256]={0};
  12126. int c = 0;
  12127. char *loc;
  12128. int confVersion = 3;
  12129. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12130. //start_t = clock();
  12131. //printf("Starting of the program, start_t = %ld\n", start_t);
  12132. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12133. // Check configuration file size is correct
  12134. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12135. {
  12136. struct stat st;
  12137. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12138. if(st.st_size < 3100)
  12139. {
  12140. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12141. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12142. }
  12143. }
  12144. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12145. {
  12146. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12147. if(outfile == NULL)
  12148. {
  12149. DEBUG_INFO("Error opening file\n");
  12150. return FALSE;
  12151. }
  12152. /*Core Profile*/
  12153. //AllowOfflineTxForUnknownId
  12154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12158. //AuthorizationCacheEnabled
  12159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12163. //AuthorizeRemoteTxRequests
  12164. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12168. //BlinkRepeat
  12169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12173. //ClockAlignedDataInterval
  12174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12178. //ConnectionTimeOut
  12179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12183. //GetConfigurationMaxKeys
  12184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12186. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12188. // HeartbeatInterval
  12189. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12193. // LightIntensity
  12194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12198. // LocalAuthorizeOffline
  12199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12203. // LocalPreAuthorize
  12204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12208. // MaxEnergyOnInvalidId
  12209. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12213. // MeterValuesAlignedData
  12214. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12215. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12217. 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" );
  12218. else
  12219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12221. // MeterValuesAlignedDataMaxLength
  12222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12226. else
  12227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12229. // MeterValuesSampledData
  12230. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12233. 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" );
  12234. else
  12235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].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","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12237. // MeterValuesSampledDataMaxLength
  12238. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12242. else
  12243. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12245. // MeterValueSampleInterval
  12246. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12250. // MinimumStatusDuration
  12251. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12252. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12253. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12254. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12256. // NumberOfConnectors
  12257. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12258. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12259. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12260. {
  12261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12262. }
  12263. else
  12264. {
  12265. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12266. }
  12267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12268. // ResetRetries
  12269. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12273. // ConnectorPhaseRotation
  12274. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12278. // ConnectorPhaseRotationMaxLength
  12279. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12280. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12281. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12283. // StopTransactionOnEVSideDisconnect
  12284. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12286. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12288. // StopTransactionOnInvalidId
  12289. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12293. // StopTxnAlignedData
  12294. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12298. // StopTxnAlignedDataMaxLength
  12299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12303. // StopTxnSampledData
  12304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12308. else
  12309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12311. // StopTxnSampledDataMaxLength
  12312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12315. {
  12316. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12317. }
  12318. else
  12319. {
  12320. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12321. }
  12322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12323. // SupportedFeatureProfiles
  12324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12328. // SupportedFeatureProfilesMaxLength
  12329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12333. // TransactionMessageAttempts
  12334. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12337. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12339. // TransactionMessageRetryInterval
  12340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12343. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12345. // UnlockConnectorOnEVSideDisconnect
  12346. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12350. // WebSocketPingInterval
  12351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12355. // QueueOffLineStartTransactionMessage
  12356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12360. // AuthorizationKey
  12361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12365. // SecurityProfile
  12366. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12368. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12370. // DefaultPrice
  12371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12375. // CustomDisplayCostAndPrice
  12376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12380. // CustomIdleFeeAfterStop
  12381. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12385. // Configuration Version
  12386. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12388. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12390. //* Local Auth List Management Profile*/
  12391. #if 0
  12392. //For OCTT Test Case
  12393. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12396. #endif
  12397. #if 1
  12398. //LocalAuthListEnabled
  12399. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12403. #endif
  12404. //LocalAuthListMaxLength
  12405. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12409. //SendLocalListMaxLength
  12410. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12414. //ReserveConnectorZeroSupported
  12415. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12419. //* Smart Charging Profile */
  12420. //ChargeProfileMaxStackLevel
  12421. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12425. // ChargingScheduleAllowedChargingRateUnit
  12426. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12430. // ChargingScheduleMaxPeriods
  12431. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12435. // ConnectorSwitch3to1PhaseSupported
  12436. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12440. // MaxChargingProfilesInstalled
  12441. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12445. fclose(outfile);
  12446. }
  12447. else
  12448. {
  12449. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12450. char keystr[60]={0};
  12451. char readonlystr[10]={0};
  12452. char valuestr[256]={0};
  12453. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12454. if(fp == NULL) {
  12455. DEBUG_INFO("Error opening file");
  12456. return FALSE;
  12457. }
  12458. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12459. {
  12460. //DEBUG_INFO("Get Configuration \n");
  12461. if(strlen(str) > 0)
  12462. {
  12463. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12464. //*************************key*********************************/
  12465. if(strstr(str, "key") != NULL)
  12466. {
  12467. loc = strstr(str, "key");
  12468. c = 0;
  12469. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12470. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12471. {
  12472. sstr[c] = loc[strlen("key")+3+c];
  12473. c++;
  12474. }
  12475. sstr[c] = '\0';
  12476. strcpy(keystr,sstr);
  12477. }
  12478. //*************************readonly*********************************/
  12479. if(strstr(str, "readonly") != NULL)
  12480. {
  12481. loc = strstr(str, "readonly");
  12482. c = 0;
  12483. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12484. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12485. {
  12486. sstr[c] = loc[strlen("readonly")+2+c];
  12487. c++;
  12488. }
  12489. sstr[c] = '\0';
  12490. strcpy(readonlystr,sstr);
  12491. }
  12492. //*************************value*********************************/
  12493. if(strstr(str, "value") != NULL)
  12494. {
  12495. loc = strstr(str, "value");
  12496. c = 0;
  12497. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12498. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12499. {
  12500. sstr[c] = loc[strlen("value")+3+c];
  12501. c++;
  12502. }
  12503. sstr[c] = '\0';
  12504. strcpy(valuestr,sstr);
  12505. }
  12506. // DEBUG_INFO("keystr=%s\n",keystr);
  12507. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12508. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12509. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12510. {
  12511. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12512. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12514. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12515. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12516. }
  12517. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12518. {
  12519. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12520. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12521. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12522. }
  12523. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12524. {
  12525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12527. }
  12528. if(strcmp(keystr, "BlinkRepeat") == 0)
  12529. {
  12530. //Charger.BlinkRepeat = Integer.parseInt(value);
  12531. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12532. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12533. }
  12534. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12535. {
  12536. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12538. }
  12539. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12540. {
  12541. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12543. }
  12544. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12545. {
  12546. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12548. }
  12549. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12550. {
  12551. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12552. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12553. HeartBeatWaitTime = atoi(valuestr);
  12554. }
  12555. if(strcmp(keystr, "LightIntensity") == 0)
  12556. {
  12557. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12559. }
  12560. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12561. {
  12562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12563. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12564. }
  12565. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12566. {
  12567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12569. }
  12570. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12571. {
  12572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12573. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12574. }
  12575. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12576. {
  12577. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12579. }
  12580. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12581. {
  12582. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12583. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12584. }
  12585. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12586. {
  12587. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12588. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12589. }
  12590. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12591. {
  12592. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12594. }
  12595. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12596. {
  12597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12599. }
  12600. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12601. {
  12602. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12604. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12605. }
  12606. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12607. {
  12608. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12609. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12610. }
  12611. if(strcmp(keystr, "ResetRetries") == 0)
  12612. {
  12613. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12614. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12615. }
  12616. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12617. {
  12618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12620. }
  12621. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12622. {
  12623. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12624. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12625. }
  12626. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12627. {
  12628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12630. }
  12631. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12632. {
  12633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12635. }
  12636. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12637. {
  12638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12640. }
  12641. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12642. {
  12643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12645. }
  12646. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12647. {
  12648. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12649. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12650. }
  12651. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12652. {
  12653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12655. }
  12656. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12657. {
  12658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12660. }
  12661. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12662. {
  12663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12665. }
  12666. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12667. {
  12668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12670. TransactionMessageAttemptsValue = atoi(valuestr);
  12671. }
  12672. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12673. {
  12674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12676. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12677. }
  12678. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12679. {
  12680. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12681. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12682. }
  12683. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12684. {
  12685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12686. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12687. }
  12688. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12689. {
  12690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12691. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12692. }
  12693. if(strcmp(keystr, "AuthorizationKey") == 0)
  12694. {
  12695. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12696. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12697. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12698. }
  12699. if(strcmp(keystr, "SecurityProfile") == 0)
  12700. {
  12701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12702. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12704. }
  12705. if(strcmp(keystr, "DefaultPrice") == 0)
  12706. {
  12707. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12708. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12709. }
  12710. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12711. {
  12712. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12713. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12714. }
  12715. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12716. {
  12717. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12719. }
  12720. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12721. {
  12722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12724. }
  12725. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12726. {
  12727. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12729. }
  12730. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12731. {
  12732. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12733. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12734. }
  12735. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12736. {
  12737. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12738. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12739. }
  12740. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12741. {
  12742. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12743. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12744. }
  12745. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12746. {
  12747. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12749. }
  12750. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12751. {
  12752. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12754. }
  12755. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12756. {
  12757. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12758. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12759. }
  12760. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12761. {
  12762. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12763. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12764. }
  12765. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12766. {
  12767. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12768. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12769. }
  12770. }
  12771. }
  12772. fclose(fp);
  12773. }
  12774. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12775. {
  12776. return PASS;
  12777. }
  12778. else
  12779. {
  12780. return FAIL;
  12781. }
  12782. }
  12783. void StoreConfigurationTable(void)
  12784. {
  12785. FILE *outfile;
  12786. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12787. if(outfile == NULL)
  12788. {
  12789. DEBUG_INFO("Error opening file");
  12790. return ;
  12791. }
  12792. /*Core Profile*/
  12793. //AllowOfflineTxForUnknownId
  12794. /*
  12795. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12796. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12799. */
  12800. //DEBUG_INFO("data=%s\n",data);
  12801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12802. //AuthorizationCacheEnabled
  12803. /*
  12804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12807. */
  12808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12809. //AuthorizeRemoteTxRequests
  12810. /*
  12811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12814. */
  12815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12816. //BlinkRepeat
  12817. /*
  12818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12821. */
  12822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12823. //ClockAlignedDataInterval
  12824. /*
  12825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12828. */
  12829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12830. //ConnectionTimeOut
  12831. /*
  12832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12835. */
  12836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12837. //GetConfigurationMaxKeys
  12838. /*
  12839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12842. */
  12843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12844. // HeartbeatInterval
  12845. /*
  12846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12849. */
  12850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12851. // LightIntensity
  12852. /*
  12853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12856. */
  12857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12858. // LocalAuthorizeOffline
  12859. /*
  12860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12863. */
  12864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12865. // LocalPreAuthorize
  12866. /*
  12867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12870. */
  12871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12872. // MaxEnergyOnInvalidId
  12873. /*
  12874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12877. */
  12878. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12880. // MeterValuesAlignedData
  12881. /*
  12882. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12885. */
  12886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12887. // MeterValuesAlignedDataMaxLength
  12888. /*
  12889. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12892. */
  12893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12894. // MeterValuesSampledData
  12895. /*
  12896. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12899. */
  12900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12901. // MeterValuesSampledDataMaxLength
  12902. /*
  12903. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12906. */
  12907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12908. // MeterValueSampleInterval
  12909. /*
  12910. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12913. */
  12914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12915. // MinimumStatusDuration
  12916. /*
  12917. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12920. */
  12921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12922. // NumberOfConnectors
  12923. /*
  12924. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12926. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12927. {
  12928. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12929. }
  12930. else
  12931. {
  12932. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12933. }
  12934. */
  12935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12936. // ResetRetries
  12937. /*
  12938. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12941. */
  12942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12943. // ConnectorPhaseRotation
  12944. /*
  12945. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12948. */
  12949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12950. // ConnectorPhaseRotationMaxLength
  12951. /*
  12952. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12955. */
  12956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12957. // StopTransactionOnEVSideDisconnect
  12958. /*
  12959. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12962. */
  12963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12964. // StopTransactionOnInvalidId
  12965. /*
  12966. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12969. */
  12970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12971. // StopTxnAlignedData
  12972. /*
  12973. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12976. */
  12977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12978. // StopTxnAlignedDataMaxLength
  12979. /*
  12980. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12983. */
  12984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12985. // StopTxnSampledData
  12986. /*
  12987. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12990. */
  12991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12992. // StopTxnSampledDataMaxLength
  12993. /*
  12994. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12997. */
  12998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12999. // SupportedFeatureProfiles
  13000. /*
  13001. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13003. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13004. */
  13005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13006. // SupportedFeatureProfilesMaxLength
  13007. /*
  13008. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13010. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13011. */
  13012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13013. // TransactionMessageAttempts
  13014. /*
  13015. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13017. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13018. */
  13019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13020. // TransactionMessageRetryInterval
  13021. /*
  13022. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13025. */
  13026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13027. // UnlockConnectorOnEVSideDisconnect
  13028. /*
  13029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13032. */
  13033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13034. // WebSocketPingInterval
  13035. /*
  13036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13039. */
  13040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13041. // QueueOffLineStartTransactionMessage
  13042. /*
  13043. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13046. */
  13047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13048. // AuthorizationKey
  13049. /*
  13050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13053. */
  13054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13055. // SecurityProfile
  13056. /*
  13057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13059. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13060. */
  13061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13062. // DefaultPrice
  13063. /*
  13064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13067. */
  13068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13069. // CustomDisplayCostAndPrice
  13070. /*
  13071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13074. */
  13075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13076. // CustomIdleFeeAfterStop
  13077. /*
  13078. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13081. */
  13082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13083. // ConfigurationVersion
  13084. /*
  13085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13088. */
  13089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13090. //* Local Auth List Management Profile*/
  13091. //LocalAuthListEnabled
  13092. /*
  13093. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13096. */
  13097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13098. //LocalAuthListMaxLength
  13099. /*
  13100. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13103. */
  13104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13105. //SendLocalListMaxLength
  13106. /*
  13107. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13110. */
  13111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13112. //ReserveConnectorZeroSupported
  13113. /*
  13114. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13117. */
  13118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13119. //* Smart Charging Profile */
  13120. //ChargeProfileMaxStackLevel
  13121. /*
  13122. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13125. */
  13126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13127. // ChargingScheduleAllowedChargingRateUnit
  13128. /*
  13129. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13132. */
  13133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13134. // ChargingScheduleMaxPeriods
  13135. /*
  13136. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13138. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13139. */
  13140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13141. // ConnectorSwitch3to1PhaseSupported
  13142. /*
  13143. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13146. */
  13147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13148. // MaxChargingProfilesInstalled
  13149. /*
  13150. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13153. */
  13154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13155. fclose(outfile);
  13156. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13157. }
  13158. void getKeyValue(char *keyReq)
  13159. {
  13160. int isEmpty = FALSE;
  13161. int isKnowKey = FALSE;
  13162. DEBUG_INFO("keyReq = %s\n", keyReq);
  13163. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13164. isEmpty = TRUE;
  13165. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13166. {
  13167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13169. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13170. {
  13171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13172. }
  13173. else
  13174. {
  13175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13176. }
  13177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13178. isKnowKey = TRUE;
  13179. }
  13180. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13181. {
  13182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13184. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13185. {
  13186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13187. }
  13188. else
  13189. {
  13190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13191. }
  13192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13193. isKnowKey = TRUE;
  13194. }
  13195. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13196. {
  13197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13199. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13200. {
  13201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13202. }
  13203. else
  13204. {
  13205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13206. }
  13207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13208. isKnowKey = TRUE;
  13209. }
  13210. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13211. {
  13212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13214. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13215. {
  13216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13217. }
  13218. else
  13219. {
  13220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13221. }
  13222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13223. isKnowKey = TRUE;
  13224. }
  13225. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13226. {
  13227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13229. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13230. {
  13231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13232. }
  13233. else
  13234. {
  13235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13236. }
  13237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13238. isKnowKey = TRUE;
  13239. }
  13240. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13241. {
  13242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13244. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13245. {
  13246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13247. }
  13248. else
  13249. {
  13250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13251. }
  13252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13253. isKnowKey = TRUE;
  13254. }
  13255. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13256. {
  13257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13260. {
  13261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13262. }
  13263. else
  13264. {
  13265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13266. }
  13267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13268. isKnowKey = TRUE;
  13269. }
  13270. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13271. {
  13272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13274. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13275. {
  13276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13277. }
  13278. else
  13279. {
  13280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13281. }
  13282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13283. isKnowKey = TRUE;
  13284. }
  13285. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13286. {
  13287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13289. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13290. {
  13291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13292. }
  13293. else
  13294. {
  13295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13296. }
  13297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13298. isKnowKey = TRUE;
  13299. }
  13300. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13301. {
  13302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13305. {
  13306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13307. }
  13308. else
  13309. {
  13310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13311. }
  13312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13313. isKnowKey = TRUE;
  13314. }
  13315. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13316. {
  13317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13319. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13320. {
  13321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13322. }
  13323. else
  13324. {
  13325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13326. }
  13327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13328. isKnowKey = TRUE;
  13329. }
  13330. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13331. {
  13332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13334. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13335. {
  13336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13337. }
  13338. else
  13339. {
  13340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13341. }
  13342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13343. isKnowKey = TRUE;
  13344. }
  13345. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13346. {
  13347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13349. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13350. {
  13351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13352. }
  13353. else
  13354. {
  13355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13356. }
  13357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13358. isKnowKey = TRUE;
  13359. }
  13360. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13361. {
  13362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13364. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13365. {
  13366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13367. }
  13368. else
  13369. {
  13370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13371. }
  13372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13373. isKnowKey = TRUE;
  13374. }
  13375. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13376. {
  13377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13379. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13380. {
  13381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13382. }
  13383. else
  13384. {
  13385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13386. }
  13387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13388. isKnowKey = TRUE;
  13389. }
  13390. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13391. {
  13392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13394. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13395. {
  13396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13397. }
  13398. else
  13399. {
  13400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13401. }
  13402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13403. isKnowKey = TRUE;
  13404. }
  13405. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13406. {
  13407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13409. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13410. {
  13411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13412. }
  13413. else
  13414. {
  13415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13416. }
  13417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13418. isKnowKey = TRUE;
  13419. }
  13420. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13421. {
  13422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13424. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13425. {
  13426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13427. }
  13428. else
  13429. {
  13430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13431. }
  13432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13433. isKnowKey = TRUE;
  13434. }
  13435. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13436. {
  13437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13439. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13440. {
  13441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13442. }
  13443. else
  13444. {
  13445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13446. }
  13447. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13449. isKnowKey = TRUE;
  13450. }
  13451. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13452. {
  13453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13455. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13456. {
  13457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13458. }
  13459. else
  13460. {
  13461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13462. }
  13463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13464. isKnowKey = TRUE;
  13465. }
  13466. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13467. {
  13468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13470. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13471. {
  13472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13473. }
  13474. else
  13475. {
  13476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13477. }
  13478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13479. isKnowKey = TRUE;
  13480. }
  13481. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13482. {
  13483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13485. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13486. {
  13487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13488. }
  13489. else
  13490. {
  13491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13492. }
  13493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13494. isKnowKey = TRUE;
  13495. }
  13496. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13497. {
  13498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13500. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13501. {
  13502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13503. }
  13504. else
  13505. {
  13506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13507. }
  13508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13509. isKnowKey = TRUE;
  13510. }
  13511. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13512. {
  13513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13515. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13516. {
  13517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13518. }
  13519. else
  13520. {
  13521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13522. }
  13523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13524. isKnowKey = TRUE;
  13525. }
  13526. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13527. {
  13528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13530. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13531. {
  13532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13533. }
  13534. else
  13535. {
  13536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13537. }
  13538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13539. isKnowKey = TRUE;
  13540. }
  13541. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13542. {
  13543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13545. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13546. {
  13547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13548. }
  13549. else
  13550. {
  13551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13552. }
  13553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13554. isKnowKey = TRUE;
  13555. }
  13556. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13557. {
  13558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13560. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13561. {
  13562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13563. }
  13564. else
  13565. {
  13566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13567. }
  13568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13569. isKnowKey = TRUE;
  13570. }
  13571. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13572. {
  13573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13575. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13576. {
  13577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13578. }
  13579. else
  13580. {
  13581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13582. }
  13583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13584. isKnowKey = TRUE;
  13585. }
  13586. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13587. {
  13588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13590. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13591. {
  13592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13593. }
  13594. else
  13595. {
  13596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13597. }
  13598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13599. isKnowKey = TRUE;
  13600. }
  13601. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13602. {
  13603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13605. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13606. {
  13607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13608. }
  13609. else
  13610. {
  13611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13612. }
  13613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13614. isKnowKey = TRUE;
  13615. }
  13616. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13617. {
  13618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13620. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13621. {
  13622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13623. }
  13624. else
  13625. {
  13626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13627. }
  13628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13629. isKnowKey = TRUE;
  13630. }
  13631. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13632. {
  13633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13635. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13636. {
  13637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13638. }
  13639. else
  13640. {
  13641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13642. }
  13643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13644. isKnowKey = TRUE;
  13645. }
  13646. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13647. {
  13648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13650. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13651. {
  13652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13653. }
  13654. else
  13655. {
  13656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13657. }
  13658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13659. isKnowKey = TRUE;
  13660. }
  13661. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13662. {
  13663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13665. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13666. {
  13667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13668. }
  13669. else
  13670. {
  13671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13672. }
  13673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13674. isKnowKey = TRUE;
  13675. }
  13676. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13677. {
  13678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13680. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13681. {
  13682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13683. }
  13684. else
  13685. {
  13686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13687. }
  13688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13689. isKnowKey = TRUE;
  13690. }
  13691. /*
  13692. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13693. {
  13694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13697. {
  13698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13699. }
  13700. else
  13701. {
  13702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13703. }
  13704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13705. isKnowKey = TRUE;
  13706. }*/
  13707. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13708. {
  13709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13711. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13712. {
  13713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13714. }
  13715. else
  13716. {
  13717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13718. }
  13719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13720. isKnowKey = TRUE;
  13721. }
  13722. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13723. {
  13724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13726. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13727. {
  13728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13729. }
  13730. else
  13731. {
  13732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13733. }
  13734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13735. isKnowKey = TRUE;
  13736. }
  13737. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13738. {
  13739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13741. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13742. {
  13743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13744. }
  13745. else
  13746. {
  13747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13748. }
  13749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13750. isKnowKey = TRUE;
  13751. }
  13752. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13753. {
  13754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13756. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13757. {
  13758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13759. }
  13760. else
  13761. {
  13762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13763. }
  13764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13765. isKnowKey = TRUE;
  13766. }
  13767. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13768. {
  13769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13771. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13772. {
  13773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13774. }
  13775. else
  13776. {
  13777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13778. }
  13779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13780. isKnowKey = TRUE;
  13781. }
  13782. #if 1
  13783. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13784. {
  13785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13787. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13788. {
  13789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13790. }
  13791. else
  13792. {
  13793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13794. }
  13795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13796. isKnowKey = TRUE;
  13797. }
  13798. #endif
  13799. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13800. {
  13801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13803. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13804. {
  13805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13806. }
  13807. else
  13808. {
  13809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13810. }
  13811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13812. isKnowKey = TRUE;
  13813. }
  13814. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13815. {
  13816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13818. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13819. {
  13820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13821. }
  13822. else
  13823. {
  13824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13825. }
  13826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13827. isKnowKey = TRUE;
  13828. }
  13829. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13830. {
  13831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13833. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13834. {
  13835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13836. }
  13837. else
  13838. {
  13839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13840. }
  13841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13842. isKnowKey = TRUE;
  13843. }
  13844. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13845. {
  13846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13847. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13848. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13849. {
  13850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13851. }
  13852. else
  13853. {
  13854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13855. }
  13856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13857. isKnowKey = TRUE;
  13858. }
  13859. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13860. {
  13861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13862. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13863. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13864. {
  13865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13866. }
  13867. else
  13868. {
  13869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13870. }
  13871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13872. isKnowKey = TRUE;
  13873. }
  13874. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13875. {
  13876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13877. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13878. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13879. {
  13880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13881. }
  13882. else
  13883. {
  13884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13885. }
  13886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13887. isKnowKey = TRUE;
  13888. }
  13889. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13890. {
  13891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13893. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13894. {
  13895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13896. }
  13897. else
  13898. {
  13899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13900. }
  13901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13902. isKnowKey = TRUE;
  13903. }
  13904. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13905. {
  13906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13908. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13909. {
  13910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13911. }
  13912. else
  13913. {
  13914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13915. }
  13916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13917. isKnowKey = TRUE;
  13918. }
  13919. //=========================================================
  13920. if(!isEmpty && !isKnowKey)
  13921. {
  13922. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13923. strcpy(unknownkey[UnknownKeynum], keyReq);
  13924. UnknownKeynum = UnknownKeynum + 1;
  13925. }
  13926. }
  13927. void processUnkownKey(void)
  13928. {
  13929. DEBUG_INFO("processUnkownKey...\n");
  13930. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13931. for(int index=0; index < UnknownKeynum; index++)
  13932. {
  13933. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13934. {
  13935. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13936. }
  13937. }
  13938. }
  13939. int setKeyValue(char *key, char *value)
  13940. {
  13941. int isSuccess = NotSupported;
  13942. int check_ascii=0;
  13943. char str[256]={0};
  13944. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13945. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13946. {
  13947. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13948. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13949. {
  13950. strcpy(str, (const char*)value);
  13951. for(int i = 0; str[i]; i++){
  13952. str[i] = tolower(str[i]);
  13953. }
  13954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13955. isSuccess = ConfigurationStatus_Accepted;
  13956. }
  13957. else
  13958. {
  13959. isSuccess = ConfigurationStatus_Rejected;
  13960. }
  13961. }
  13962. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13963. {
  13964. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13965. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13966. {
  13967. strcpy(str, (const char*)value);
  13968. for(int i = 0; str[i]; i++){
  13969. str[i] = tolower(str[i]);
  13970. }
  13971. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13972. isSuccess = ConfigurationStatus_Accepted;
  13973. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13974. }
  13975. else
  13976. {
  13977. isSuccess = ConfigurationStatus_Rejected;
  13978. }
  13979. }
  13980. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13981. {
  13982. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13983. {
  13984. strcpy(str, (const char*)value);
  13985. for(int i = 0; str[i]; i++)
  13986. {
  13987. str[i] = tolower(str[i]);
  13988. }
  13989. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13990. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13991. isSuccess = ConfigurationStatus_Accepted;
  13992. }
  13993. else
  13994. {
  13995. isSuccess = ConfigurationStatus_Rejected;
  13996. }
  13997. }
  13998. if(strcmp(key, "BlinkRepeat") == 0)
  13999. {
  14000. //Charger.BlinkRepeat = Integer.parseInt(value);
  14001. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14002. {
  14003. check_ascii = value[0];
  14004. if( (check_ascii < 48) || (check_ascii > 57) )
  14005. {
  14006. isSuccess = ConfigurationStatus_Rejected;
  14007. }
  14008. else
  14009. {
  14010. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14011. isSuccess = ConfigurationStatus_Accepted;
  14012. }
  14013. }
  14014. else
  14015. {
  14016. isSuccess = ConfigurationStatus_Rejected;
  14017. }
  14018. }
  14019. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14020. {
  14021. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14022. {
  14023. check_ascii = value[0];
  14024. if( (check_ascii < 48) || (check_ascii > 57) )
  14025. {
  14026. isSuccess = ConfigurationStatus_Rejected;
  14027. }
  14028. else
  14029. {
  14030. if((atoi(value) == 0) || (atoi(value) >= 10))
  14031. {
  14032. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14034. isSuccess = ConfigurationStatus_Accepted;
  14035. }
  14036. else
  14037. isSuccess = ConfigurationStatus_Rejected;
  14038. }
  14039. }
  14040. else
  14041. {
  14042. isSuccess = ConfigurationStatus_Rejected;
  14043. }
  14044. }
  14045. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14046. {
  14047. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14048. {
  14049. check_ascii = value[0];
  14050. if( (check_ascii < 48) || (check_ascii > 57) )
  14051. {
  14052. isSuccess = ConfigurationStatus_Rejected;
  14053. }
  14054. else
  14055. {
  14056. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14057. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14058. isSuccess = ConfigurationStatus_Accepted;
  14059. }
  14060. }
  14061. else
  14062. {
  14063. isSuccess = ConfigurationStatus_Rejected;
  14064. }
  14065. }
  14066. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14067. {
  14068. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14069. {
  14070. check_ascii = value[0];
  14071. if( (check_ascii < 48) || (check_ascii > 57) )
  14072. {
  14073. isSuccess = ConfigurationStatus_Rejected;
  14074. }
  14075. else
  14076. {
  14077. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14078. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14079. isSuccess = ConfigurationStatus_Accepted;
  14080. }
  14081. }
  14082. else
  14083. {
  14084. isSuccess = ConfigurationStatus_Rejected;
  14085. }
  14086. }
  14087. if(strcmp(key, "HeartbeatInterval") == 0)
  14088. {
  14089. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14090. {
  14091. check_ascii = value[0];
  14092. if( (check_ascii < 48) || (check_ascii > 57) )
  14093. {
  14094. isSuccess = ConfigurationStatus_Rejected;
  14095. }
  14096. else
  14097. {
  14098. if((atoi(value) == 0) || (atoi(value) >= 10))
  14099. {
  14100. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14102. HeartBeatWaitTime = atoi(value);
  14103. isSuccess = ConfigurationStatus_Accepted;
  14104. }
  14105. else
  14106. {
  14107. isSuccess = ConfigurationStatus_Rejected;
  14108. }
  14109. }
  14110. }
  14111. else
  14112. {
  14113. isSuccess = ConfigurationStatus_Rejected;
  14114. }
  14115. }
  14116. if(strcmp(key, "LightIntensity") == 0)
  14117. {
  14118. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14119. {
  14120. check_ascii = value[0];
  14121. if( (check_ascii < 48) || (check_ascii > 57) )
  14122. {
  14123. isSuccess = ConfigurationStatus_Rejected;
  14124. }
  14125. else
  14126. {
  14127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14128. isSuccess = ConfigurationStatus_Accepted;
  14129. }
  14130. }
  14131. else
  14132. {
  14133. isSuccess = ConfigurationStatus_Rejected;
  14134. }
  14135. }
  14136. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14137. {
  14138. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14139. {
  14140. strcpy(str, (const char*)value);
  14141. for(int i = 0; str[i]; i++)
  14142. {
  14143. str[i] = tolower(str[i]);
  14144. }
  14145. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14146. isSuccess = ConfigurationStatus_Accepted;
  14147. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14148. }
  14149. else
  14150. {
  14151. isSuccess = ConfigurationStatus_Rejected;
  14152. }
  14153. }
  14154. if(strcmp(key, "LocalPreAuthorize") == 0)
  14155. {
  14156. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14157. {
  14158. strcpy(str, (const char*)value);
  14159. for(int i = 0; str[i]; i++)
  14160. {
  14161. str[i] = tolower(str[i]);
  14162. }
  14163. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14164. isSuccess = ConfigurationStatus_Accepted;
  14165. }
  14166. else
  14167. {
  14168. isSuccess = ConfigurationStatus_Rejected;
  14169. }
  14170. }
  14171. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14172. {
  14173. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14174. {
  14175. check_ascii = value[0];
  14176. if( (check_ascii < 48) || (check_ascii > 57) )
  14177. {
  14178. isSuccess = ConfigurationStatus_Rejected;
  14179. }
  14180. else
  14181. {
  14182. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14183. isSuccess = ConfigurationStatus_Accepted;
  14184. }
  14185. }
  14186. else
  14187. {
  14188. isSuccess = ConfigurationStatus_Rejected;
  14189. }
  14190. }
  14191. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14192. {
  14193. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14194. {
  14195. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14196. isSuccess = ConfigurationStatus_Accepted;
  14197. }
  14198. else
  14199. {
  14200. isSuccess = ConfigurationStatus_Rejected;
  14201. }
  14202. }
  14203. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14204. {
  14205. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14206. {
  14207. check_ascii = value[0];
  14208. if( (check_ascii < 48) || (check_ascii > 57) )
  14209. {
  14210. isSuccess = ConfigurationStatus_Rejected;
  14211. }
  14212. else
  14213. {
  14214. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14215. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14216. isSuccess = ConfigurationStatus_Accepted;
  14217. }
  14218. }
  14219. else
  14220. {
  14221. isSuccess = ConfigurationStatus_Rejected;
  14222. }
  14223. }
  14224. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14225. {
  14226. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14227. {
  14228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14229. isSuccess = ConfigurationStatus_Accepted;
  14230. }
  14231. else
  14232. {
  14233. isSuccess = ConfigurationStatus_Rejected;
  14234. }
  14235. }
  14236. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14237. {
  14238. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14239. {
  14240. check_ascii = value[0];
  14241. if( (check_ascii < 48) || (check_ascii > 57) )
  14242. {
  14243. isSuccess = ConfigurationStatus_Rejected;
  14244. }
  14245. else
  14246. {
  14247. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14248. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14249. isSuccess = ConfigurationStatus_Accepted;
  14250. }
  14251. }
  14252. else
  14253. {
  14254. isSuccess = ConfigurationStatus_Rejected;
  14255. }
  14256. }
  14257. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14258. {
  14259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14260. {
  14261. check_ascii = value[0];
  14262. if( (check_ascii < 48) || (check_ascii > 57) )
  14263. {
  14264. isSuccess = ConfigurationStatus_Rejected;
  14265. }
  14266. else
  14267. {
  14268. if((atoi(value) == 0) || (atoi(value) >= 10))
  14269. {
  14270. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14271. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14272. isSuccess = ConfigurationStatus_Accepted;
  14273. }
  14274. else
  14275. {
  14276. isSuccess = ConfigurationStatus_Rejected;
  14277. }
  14278. }
  14279. }
  14280. else
  14281. {
  14282. isSuccess = ConfigurationStatus_Rejected;
  14283. }
  14284. }
  14285. if(strcmp(key, "MinimumStatusDuration") == 0)
  14286. {
  14287. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14288. {
  14289. check_ascii = value[0];
  14290. if( (check_ascii < 48) || (check_ascii > 57) )
  14291. {
  14292. isSuccess = ConfigurationStatus_Rejected;
  14293. }
  14294. else
  14295. {
  14296. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14297. {
  14298. isSuccess = ConfigurationStatus_Rejected;
  14299. }
  14300. else
  14301. {
  14302. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14303. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14304. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14305. isSuccess = ConfigurationStatus_Accepted;
  14306. }
  14307. }
  14308. }
  14309. else
  14310. {
  14311. isSuccess = ConfigurationStatus_Rejected;
  14312. }
  14313. }
  14314. if(strcmp(key, "NumberOfConnectors") == 0)
  14315. {
  14316. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14317. {
  14318. check_ascii = value[0];
  14319. if( (check_ascii < 48) || (check_ascii > 57) )
  14320. {
  14321. isSuccess = ConfigurationStatus_Rejected;
  14322. }
  14323. else
  14324. {
  14325. //Charger.ResetRetries = Integer.parseInt(value);
  14326. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14327. isSuccess = ConfigurationStatus_Accepted;
  14328. }
  14329. }
  14330. else
  14331. {
  14332. isSuccess = ConfigurationStatus_Rejected;
  14333. }
  14334. }
  14335. if(strcmp(key, "ResetRetries") == 0)
  14336. {
  14337. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14338. {
  14339. check_ascii = value[0];
  14340. if( (check_ascii < 48) || (check_ascii > 57) )
  14341. {
  14342. isSuccess = ConfigurationStatus_Rejected;
  14343. }
  14344. else
  14345. {
  14346. //Charger.ResetRetries = Integer.parseInt(value);
  14347. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14348. isSuccess = ConfigurationStatus_Accepted;
  14349. }
  14350. }
  14351. else
  14352. {
  14353. isSuccess = ConfigurationStatus_Rejected;
  14354. }
  14355. }
  14356. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14357. {
  14358. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14359. {
  14360. strcpy(str, (const char*)value);
  14361. for(int i = 0; str[i]; i++)
  14362. {
  14363. str[i] = tolower(str[i]);
  14364. }
  14365. if(strcmp(str, "notapplicable")== 0)
  14366. {
  14367. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14368. isSuccess = ConfigurationStatus_Accepted;
  14369. }
  14370. else if(strcmp(str, "unknown")== 0)
  14371. {
  14372. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14373. isSuccess = ConfigurationStatus_Accepted;
  14374. }
  14375. else if(strcmp(str, "rst")== 0)
  14376. {
  14377. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14378. isSuccess = ConfigurationStatus_Accepted;
  14379. }
  14380. else if(strcmp(str, "rts")== 0)
  14381. {
  14382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14383. isSuccess = ConfigurationStatus_Accepted;
  14384. }
  14385. else if(strcmp(str, "srt")== 0)
  14386. {
  14387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14388. isSuccess = ConfigurationStatus_Accepted;
  14389. }
  14390. else if(strcmp(str, "str")== 0)
  14391. {
  14392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14393. isSuccess = ConfigurationStatus_Accepted;
  14394. }
  14395. else if(strcmp(str, "trs")== 0)
  14396. {
  14397. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14398. isSuccess = ConfigurationStatus_Accepted;
  14399. }
  14400. else if(strcmp(str, "tsr")== 0)
  14401. {
  14402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14403. isSuccess = ConfigurationStatus_Accepted;
  14404. }
  14405. else
  14406. {
  14407. isSuccess = ConfigurationStatus_Rejected;
  14408. }
  14409. }
  14410. else
  14411. {
  14412. isSuccess = ConfigurationStatus_Rejected;
  14413. }
  14414. }
  14415. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14416. {
  14417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14418. {
  14419. check_ascii = value[0];
  14420. if( (check_ascii < 48) || (check_ascii > 57) )
  14421. {
  14422. isSuccess = ConfigurationStatus_Rejected;
  14423. }
  14424. else
  14425. {
  14426. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14427. isSuccess = ConfigurationStatus_Accepted;
  14428. }
  14429. }
  14430. else
  14431. {
  14432. isSuccess = ConfigurationStatus_Rejected;
  14433. }
  14434. }
  14435. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14436. {
  14437. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14438. {
  14439. strcpy(str, (const char*)value);
  14440. for(int i = 0; str[i]; i++)
  14441. {
  14442. str[i] = tolower(str[i]);
  14443. }
  14444. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14445. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14446. isSuccess = ConfigurationStatus_Accepted;
  14447. }
  14448. else
  14449. {
  14450. isSuccess = ConfigurationStatus_Rejected;
  14451. }
  14452. }
  14453. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14454. {
  14455. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14456. {
  14457. strcpy(str, (const char*)value);
  14458. for(int i = 0; str[i]; i++)
  14459. {
  14460. str[i] = tolower(str[i]);
  14461. }
  14462. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14463. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14464. isSuccess = ConfigurationStatus_Accepted;
  14465. }
  14466. else
  14467. {
  14468. isSuccess = ConfigurationStatus_Rejected;
  14469. }
  14470. }
  14471. if(strcmp(key, "StopTxnAlignedData") == 0)
  14472. {
  14473. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14474. {
  14475. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14476. isSuccess = ConfigurationStatus_Accepted;
  14477. }
  14478. else
  14479. {
  14480. isSuccess = ConfigurationStatus_Rejected;
  14481. }
  14482. }
  14483. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14484. {
  14485. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14486. {
  14487. check_ascii = value[0];
  14488. if( (check_ascii < 48) || (check_ascii > 57) )
  14489. {
  14490. isSuccess = ConfigurationStatus_Rejected;
  14491. }
  14492. else
  14493. {
  14494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14495. isSuccess = ConfigurationStatus_Accepted;
  14496. }
  14497. }
  14498. else
  14499. {
  14500. isSuccess = ConfigurationStatus_Rejected;
  14501. }
  14502. }
  14503. if(strcmp(key, "StopTxnSampledData") == 0)
  14504. {
  14505. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14506. {
  14507. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14508. isSuccess = ConfigurationStatus_Accepted;
  14509. }
  14510. else
  14511. {
  14512. isSuccess = ConfigurationStatus_Rejected;
  14513. }
  14514. }
  14515. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14516. {
  14517. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14518. {
  14519. check_ascii = value[0];
  14520. if( (check_ascii < 48) || (check_ascii > 57) )
  14521. {
  14522. isSuccess = ConfigurationStatus_Rejected;
  14523. }
  14524. else
  14525. {
  14526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14527. isSuccess = ConfigurationStatus_Accepted;
  14528. }
  14529. }
  14530. else
  14531. {
  14532. isSuccess = ConfigurationStatus_Rejected;
  14533. }
  14534. }
  14535. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14536. {
  14537. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14538. {
  14539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14540. isSuccess = ConfigurationStatus_Accepted;
  14541. }
  14542. else
  14543. {
  14544. isSuccess = ConfigurationStatus_Rejected;
  14545. }
  14546. }
  14547. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14548. {
  14549. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14550. {
  14551. check_ascii = value[0];
  14552. if( (check_ascii < 48) || (check_ascii > 57) )
  14553. {
  14554. isSuccess = ConfigurationStatus_Rejected;
  14555. }
  14556. else
  14557. {
  14558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14559. isSuccess = ConfigurationStatus_Accepted;
  14560. }
  14561. }
  14562. else
  14563. {
  14564. isSuccess = ConfigurationStatus_Rejected;
  14565. }
  14566. }
  14567. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14568. {
  14569. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14570. {
  14571. check_ascii = value[0];
  14572. if( (check_ascii < 48) || (check_ascii > 57) )
  14573. {
  14574. isSuccess = ConfigurationStatus_Rejected;
  14575. }
  14576. else
  14577. {
  14578. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14579. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14580. TransactionMessageAttemptsValue = atoi(value);
  14581. isSuccess = ConfigurationStatus_Accepted;
  14582. }
  14583. }
  14584. else
  14585. {
  14586. isSuccess = ConfigurationStatus_Rejected;
  14587. }
  14588. }
  14589. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14590. {
  14591. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14592. {
  14593. check_ascii = value[0];
  14594. if( (check_ascii < 48) || (check_ascii > 57) )
  14595. {
  14596. isSuccess = ConfigurationStatus_Rejected;
  14597. }
  14598. else
  14599. {
  14600. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14601. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14602. TransactionMessageRetryIntervalValue = atoi(value);
  14603. isSuccess = ConfigurationStatus_Accepted;
  14604. }
  14605. }
  14606. else
  14607. {
  14608. isSuccess = ConfigurationStatus_Rejected;
  14609. }
  14610. }
  14611. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14612. {
  14613. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14614. {
  14615. strcpy(str, (const char*)value);
  14616. for(int i = 0; str[i]; i++)
  14617. {
  14618. str[i] = tolower(str[i]);
  14619. }
  14620. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14621. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14622. isSuccess = ConfigurationStatus_Accepted;
  14623. }
  14624. else
  14625. {
  14626. isSuccess = ConfigurationStatus_Rejected;
  14627. }
  14628. }
  14629. if(strcmp(key, "WebSocketPingInterval") == 0)
  14630. {
  14631. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14632. {
  14633. check_ascii = value[0];
  14634. if( (check_ascii < 48) || (check_ascii > 57) )
  14635. {
  14636. isSuccess = ConfigurationStatus_Rejected;
  14637. }
  14638. else
  14639. {
  14640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14641. isSuccess = ConfigurationStatus_Accepted;
  14642. }
  14643. }
  14644. else
  14645. {
  14646. isSuccess = ConfigurationStatus_Rejected;
  14647. }
  14648. }
  14649. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14650. {
  14651. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14652. {
  14653. strcpy(str, (const char*)value);
  14654. for(int i = 0; str[i]; i++)
  14655. {
  14656. str[i] = tolower(str[i]);
  14657. }
  14658. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14660. isSuccess = ConfigurationStatus_Accepted;
  14661. }
  14662. else
  14663. {
  14664. isSuccess = ConfigurationStatus_Rejected;
  14665. }
  14666. }
  14667. if(strcmp(key, "AuthorizationKey") == 0)
  14668. {
  14669. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14670. {
  14671. strcpy(str, (const char*)value);
  14672. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14673. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14674. isSuccess = ConfigurationStatus_Accepted;
  14675. }
  14676. else
  14677. {
  14678. isSuccess = ConfigurationStatus_Rejected;
  14679. }
  14680. }
  14681. if(strcmp(key, "SecurityProfile") == 0)
  14682. {
  14683. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14684. {
  14685. check_ascii = value[0];
  14686. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14687. {
  14688. isSuccess = ConfigurationStatus_Rejected;
  14689. }
  14690. else if(check_ascii == 0x33)
  14691. {
  14692. isSuccess = NotSupported;
  14693. }
  14694. else
  14695. {
  14696. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14697. {
  14698. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14699. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14700. isSuccess = ConfigurationStatus_Accepted;
  14701. }
  14702. else
  14703. isSuccess = ConfigurationStatus_Rejected;
  14704. }
  14705. }
  14706. else
  14707. {
  14708. isSuccess = ConfigurationStatus_Rejected;
  14709. }
  14710. }
  14711. if(strcmp(key, "DefaultPrice") == 0)
  14712. {
  14713. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14714. {
  14715. strcpy(str, (const char*)value);
  14716. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14717. isSuccess = ConfigurationStatus_Accepted;
  14718. }
  14719. else
  14720. {
  14721. isSuccess = ConfigurationStatus_Rejected;
  14722. }
  14723. }
  14724. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14725. {
  14726. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14727. {
  14728. strcpy(str, (const char*)value);
  14729. for(int i = 0; str[i]; i++)
  14730. {
  14731. str[i] = tolower(str[i]);
  14732. }
  14733. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14735. isSuccess = ConfigurationStatus_Accepted;
  14736. }
  14737. else
  14738. {
  14739. isSuccess = ConfigurationStatus_Rejected;
  14740. }
  14741. }
  14742. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14743. {
  14744. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14745. {
  14746. strcpy(str, (const char*)value);
  14747. for(int i = 0; str[i]; i++)
  14748. {
  14749. str[i] = tolower(str[i]);
  14750. }
  14751. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14753. isSuccess = ConfigurationStatus_Accepted;
  14754. }
  14755. else
  14756. {
  14757. isSuccess = ConfigurationStatus_Rejected;
  14758. }
  14759. }
  14760. #if 0
  14761. //For OCPP Test Case
  14762. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14763. {
  14764. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14765. {
  14766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14767. isSuccess = ConfigurationStatus_Accepted;
  14768. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14769. }
  14770. else
  14771. {
  14772. isSuccess = ConfigurationStatus_Rejected;
  14773. }
  14774. }
  14775. #endif
  14776. #if 1
  14777. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14778. {
  14779. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14780. {
  14781. strcpy(str, (const char*)value);
  14782. for(int i = 0; str[i]; i++)
  14783. {
  14784. str[i] = tolower(str[i]);
  14785. }
  14786. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14787. isSuccess = ConfigurationStatus_Accepted;
  14788. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14789. }
  14790. else
  14791. {
  14792. isSuccess = ConfigurationStatus_Rejected;
  14793. }
  14794. }
  14795. #endif
  14796. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14797. {
  14798. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14799. {
  14800. check_ascii = value[0];
  14801. if( (check_ascii < 48) || (check_ascii > 57) )
  14802. {
  14803. isSuccess = ConfigurationStatus_Rejected;
  14804. }
  14805. else
  14806. {
  14807. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14808. isSuccess = ConfigurationStatus_Accepted;
  14809. }
  14810. }
  14811. else
  14812. {
  14813. isSuccess = ConfigurationStatus_Rejected;
  14814. }
  14815. }
  14816. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14817. {
  14818. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14819. {
  14820. check_ascii = value[0];
  14821. if( (check_ascii < 48) || (check_ascii > 57) )
  14822. {
  14823. isSuccess = ConfigurationStatus_Rejected;
  14824. }
  14825. else
  14826. {
  14827. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14828. isSuccess = ConfigurationStatus_Accepted;
  14829. }
  14830. }
  14831. else
  14832. {
  14833. isSuccess = ConfigurationStatus_Rejected;
  14834. }
  14835. }
  14836. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14837. {
  14838. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14839. {
  14840. strcpy(str, (const char*)value);
  14841. for(int i = 0; str[i]; i++)
  14842. {
  14843. str[i] = tolower(str[i]);
  14844. }
  14845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14846. isSuccess = ConfigurationStatus_Accepted;
  14847. }
  14848. else
  14849. {
  14850. isSuccess = ConfigurationStatus_Rejected;
  14851. }
  14852. }
  14853. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14854. {
  14855. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14856. {
  14857. check_ascii = value[0];
  14858. if( (check_ascii < 48) || (check_ascii > 57) )
  14859. {
  14860. isSuccess = ConfigurationStatus_Rejected;
  14861. }
  14862. else
  14863. {
  14864. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14865. isSuccess = ConfigurationStatus_Accepted;
  14866. }
  14867. }
  14868. else
  14869. {
  14870. isSuccess = ConfigurationStatus_Rejected;
  14871. }
  14872. }
  14873. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14874. {
  14875. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14876. {
  14877. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14878. isSuccess = ConfigurationStatus_Accepted;
  14879. }
  14880. else
  14881. {
  14882. isSuccess = ConfigurationStatus_Rejected;
  14883. }
  14884. }
  14885. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14886. {
  14887. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14888. {
  14889. check_ascii = value[0];
  14890. if( (check_ascii < 48) || (check_ascii > 57) )
  14891. {
  14892. isSuccess = ConfigurationStatus_Rejected;
  14893. }
  14894. else
  14895. {
  14896. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14897. isSuccess = ConfigurationStatus_Accepted;
  14898. }
  14899. }
  14900. else
  14901. {
  14902. isSuccess = ConfigurationStatus_Rejected;
  14903. }
  14904. }
  14905. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14906. {
  14907. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14908. {
  14909. strcpy(str, (const char*)value);
  14910. for(int i = 0; str[i]; i++)
  14911. {
  14912. str[i] = tolower(str[i]);
  14913. }
  14914. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14915. isSuccess = ConfigurationStatus_Accepted;
  14916. }
  14917. else
  14918. {
  14919. isSuccess = ConfigurationStatus_Rejected;
  14920. }
  14921. }
  14922. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14923. {
  14924. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14925. {
  14926. check_ascii = value[0];
  14927. if( (check_ascii < 48) || (check_ascii > 57) )
  14928. {
  14929. isSuccess = ConfigurationStatus_Rejected;
  14930. }
  14931. else
  14932. {
  14933. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14934. isSuccess = ConfigurationStatus_Accepted;
  14935. }
  14936. }
  14937. else
  14938. {
  14939. isSuccess = ConfigurationStatus_Rejected;
  14940. }
  14941. }
  14942. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14943. return isSuccess;
  14944. }
  14945. int TransactionMessageAttemptsGet(void)
  14946. {
  14947. return TransactionMessageAttemptsValue;
  14948. }
  14949. int FirstHeartBeatResponse(void)
  14950. {
  14951. return FirstHeartBeat;
  14952. }
  14953. int TransactionMessageRetryIntervalGet(void)
  14954. {
  14955. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14956. }
  14957. int ReadHttpStatus(int sock)
  14958. {
  14959. //char c;
  14960. char buff[1024]="",*ptr=buff+1;
  14961. int bytes_received, status;
  14962. DEBUG_INFO("Begin Response ..\n");
  14963. while((bytes_received = recv(sock, ptr, 1, 0))){
  14964. if(bytes_received==-1){
  14965. perror("ReadHttpStatus");
  14966. exit(1);
  14967. }
  14968. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14969. ptr++;
  14970. }
  14971. *ptr=0;
  14972. ptr=buff+1;
  14973. sscanf(ptr,"%*s %d ", &status);
  14974. DEBUG_INFO("%s\n",ptr);
  14975. DEBUG_INFO("status=%d\n",status);
  14976. DEBUG_INFO("End Response ..\n");
  14977. return (bytes_received>0)?status:0;
  14978. }
  14979. //the only filed that it parsed is 'Content-Length'
  14980. int ParseHeader(int sock)
  14981. {
  14982. //char c;
  14983. char buff[1024]="",*ptr=buff+4;
  14984. int bytes_received;
  14985. DEBUG_INFO("Begin HEADER ..\n");
  14986. while((bytes_received = recv(sock, ptr, 1, 0))){
  14987. if(bytes_received==-1){
  14988. perror("Parse Header");
  14989. exit(1);
  14990. }
  14991. if(
  14992. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14993. (ptr[-1]=='\r') && (*ptr=='\n' )
  14994. ) break;
  14995. ptr++;
  14996. }
  14997. *ptr=0;
  14998. ptr=buff+4;
  14999. //printf("%s",ptr);
  15000. if(bytes_received){
  15001. ptr=strstr(ptr,"Content-Length:");
  15002. if(ptr){
  15003. sscanf(ptr,"%*s %d",&bytes_received);
  15004. }else
  15005. bytes_received=-1; //unknown size
  15006. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15007. }
  15008. DEBUG_INFO("End HEADER ..\n");
  15009. return bytes_received ;
  15010. }
  15011. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15012. {
  15013. int result = TRUE;
  15014. char rmFileCmd[100]={0};
  15015. char FilePath[100]={0};
  15016. char ftpbuf[200];
  15017. int systemresult;
  15018. sprintf(FilePath,"/mnt/%s",filename);
  15019. system("ping 8.8.8.8 &");
  15020. if((access(FilePath,F_OK))!=-1)
  15021. {
  15022. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15023. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15024. system(rmFileCmd);
  15025. }
  15026. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15027. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15028. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15029. systemresult = system(ftpbuf);
  15030. if(systemresult != 0)
  15031. {
  15032. DEBUG_INFO("http DownLoad error!\n");
  15033. result = FALSE;
  15034. }
  15035. system("pkill ping");
  15036. return result;
  15037. }
  15038. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15039. {
  15040. int result = TRUE;
  15041. char rmFileCmd[100]={0};
  15042. char FilePath[100]={0};
  15043. char ftpbuf[200];
  15044. int systemresult;
  15045. sprintf(FilePath,"/mnt/%s",filename);
  15046. system("ping 8.8.8.8 &");
  15047. if((access(FilePath,F_OK))!=-1)
  15048. {
  15049. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15050. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15051. system(rmFileCmd);
  15052. }
  15053. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15054. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15055. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15056. systemresult = system(ftpbuf);
  15057. if(systemresult != 0)
  15058. {
  15059. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15060. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15061. systemresult = system(ftpbuf);
  15062. if(systemresult != 0)
  15063. {
  15064. DEBUG_WARN("wget error!\n");
  15065. result = FALSE;
  15066. }
  15067. }
  15068. system("pkill ping");
  15069. return result;
  15070. }
  15071. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15072. {
  15073. char rmFileCmd[100]={0};
  15074. char FilePath[100]={0};
  15075. char buf[512];
  15076. int systemresult = 0;
  15077. //DEBUG_INFO("filename=%s\n",filename);
  15078. //DEBUG_INFO("url=%s\n",url);
  15079. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15080. if((access(FilePath,F_OK))!=-1)
  15081. {
  15082. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15083. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15084. system(rmFileCmd);
  15085. }
  15086. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15087. if(fp == NULL)
  15088. {
  15089. DEBUG_INFO("log is NULL\n");
  15090. return FALSE;
  15091. }
  15092. else
  15093. {
  15094. fprintf(fp, "%s\n", url);
  15095. fprintf(fp, "%s\n", filename);
  15096. fclose(fp);
  15097. }
  15098. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15099. if(phpFP == NULL)
  15100. {
  15101. DEBUG_INFO("PHP upload fail.\n");
  15102. return FALSE;
  15103. }
  15104. else
  15105. {
  15106. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15107. {
  15108. if(strstr(buf, "result") != NULL)
  15109. {
  15110. sscanf(buf, "result: %d", &systemresult);
  15111. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15112. }
  15113. }
  15114. pclose(phpFP);
  15115. }
  15116. if(systemresult != 1)
  15117. {
  15118. DEBUG_INFO("HTTP upload error!\n");
  15119. return FALSE;
  15120. }
  15121. return TRUE;
  15122. }
  15123. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15124. {
  15125. struct hostent* server;
  15126. char *IPbuffer;
  15127. char ftpbuf[200];
  15128. int systemresult;
  15129. // To retrieve host information
  15130. server = gethostbyname(location);
  15131. // To convert an Internet network
  15132. // address into ASCII string
  15133. IPbuffer = inet_ntoa(*((struct in_addr*)
  15134. server->h_addr_list[0]));
  15135. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15136. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15137. /* format : ftpput -u username -p passwd IP target source*/
  15138. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15139. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15140. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15141. systemresult = system(ftpbuf);
  15142. DEBUG_INFO("systemresult=%d\n",systemresult);
  15143. if(systemresult != 0)
  15144. {
  15145. DEBUG_INFO("ftpput error!\n");
  15146. return FALSE;
  15147. }
  15148. return TRUE;
  15149. }
  15150. int GetOcppServerURL()
  15151. {
  15152. int result = FALSE;
  15153. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15154. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15155. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15156. struct yuarel url;
  15157. char urlStr[512];
  15158. // OCPPPH only
  15159. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  15160. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  15161. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  15162. {
  15163. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  15164. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15165. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15166. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  15167. if(yuarel_parse(&url, urlStr) != -1)
  15168. {
  15169. sprintf(OcppProtocol, "%s", url.scheme);
  15170. sprintf(OcppHost, "%s", url.host);
  15171. if(url.path == NULL)
  15172. OcppTempPath[0] = '\0';
  15173. else
  15174. sprintf(OcppTempPath, "%s", url.path);
  15175. if(url.port == 0)
  15176. {
  15177. if(strcmp(OcppProtocol, "wss") == 0)
  15178. OcppPort = 443;
  15179. else
  15180. OcppPort = 80;
  15181. }
  15182. else
  15183. OcppPort = url.port;
  15184. result = TRUE;
  15185. }
  15186. }
  15187. else
  15188. {
  15189. strcpy(OcppHost,"");
  15190. }
  15191. return result;
  15192. }
  15193. int GetOcppPath()
  15194. {
  15195. int result = FALSE;
  15196. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  15197. {
  15198. if(OcppTempPath == NULL)
  15199. {
  15200. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  15201. }
  15202. else
  15203. {
  15204. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  15205. }
  15206. result = TRUE;
  15207. goto End;
  15208. }
  15209. else
  15210. {
  15211. strcpy(OcppPath,"");
  15212. }
  15213. End:
  15214. return result;
  15215. }
  15216. int GetOcppPort()
  15217. {
  15218. return OcppPort;
  15219. }
  15220. int GetOcppConnStatus(void)
  15221. {
  15222. return ShmOCPP16DataPH->OcppConnStatus;
  15223. }
  15224. void SetOcppConnStatus(uint8_t status)
  15225. {
  15226. ShmOCPP16DataPH->OcppConnStatus = status;
  15227. }
  15228. int GetHeartBeatWithNOResponse(void)
  15229. {
  15230. return HeartBeatWithNOResponse;
  15231. }
  15232. void SetHeartBeatWithNOResponse(void)
  15233. {
  15234. HeartBeatWithNOResponse = 0;
  15235. }
  15236. void GetStartTransactionIdTag(int gun_index)
  15237. {
  15238. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15239. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15240. }
  15241. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15242. {
  15243. char ch;
  15244. FILE *fptr1;
  15245. int temptransactionId;
  15246. char str[100]={0};
  15247. temptransactionId = 0;
  15248. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15249. {
  15250. DEBUG_INFO("IdTag is empty.\n");
  15251. return temptransactionId;
  15252. }
  15253. /*------ Read the file ----------------*/
  15254. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  15255. if (!fptr1)
  15256. {
  15257. DEBUG_INFO("QueueTransactionId file open error.\n");
  15258. //printf(" File not found or unable to open the input file!!\n");
  15259. return temptransactionId;
  15260. }
  15261. ch=fgetc(fptr1);
  15262. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  15263. rewind(fptr1);
  15264. if(ch!=EOF)
  15265. {
  15266. // printf("%c",ch);
  15267. while (fgets(str, 100, fptr1) != NULL)
  15268. {
  15269. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15270. if(str[0]=='\0')
  15271. {
  15272. break;
  15273. }
  15274. char *revbuf[8] = {0}; // Variable store string split
  15275. int num = 0;// Quantity after string split
  15276. DEBUG_INFO("Transaction queue data= %s\n", str);
  15277. splitstring(str,",",revbuf,&num); // String split
  15278. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15279. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15280. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15281. DEBUG_INFO("------------------------------\n");
  15282. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15283. {
  15284. if(isStopTransaction)
  15285. {
  15286. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15287. {
  15288. temptransactionId = atoi(revbuf[2]);
  15289. //break;
  15290. }
  15291. }
  15292. else
  15293. {
  15294. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15295. {
  15296. temptransactionId = atoi(revbuf[2]);
  15297. //break;
  15298. }
  15299. }
  15300. }
  15301. }
  15302. }
  15303. else
  15304. DEBUG_INFO("EOF\n");
  15305. fclose(fptr1);
  15306. /*------- End of reading ---------------*/
  15307. return temptransactionId;
  15308. }
  15309. void SetTransactionIdZero(int transactionId)
  15310. {
  15311. char ch;
  15312. FILE *fptr1, *fptr2;
  15313. int temptransactionId = 0;
  15314. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15315. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15316. if (!fptr1)
  15317. {
  15318. //printf(" File not found or unable to open the input file!!\n");
  15319. return ;
  15320. }
  15321. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15322. if (!fptr2)
  15323. {
  15324. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15325. fclose(fptr1);
  15326. return ;
  15327. }
  15328. ch=fgetc(fptr1);
  15329. rewind(fptr1);
  15330. if(ch!=EOF)
  15331. {
  15332. // copy all contents to the temporary file except the specific line
  15333. while (fgets(str, 100, fptr1) != NULL)
  15334. {
  15335. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15336. if(str[0]=='\0')
  15337. {
  15338. break;
  15339. }
  15340. char *revbuf[8] = {0};
  15341. int num = 0;
  15342. strcpy(strtemp, str);
  15343. splitstring(str,",",revbuf,&num);
  15344. if(revbuf[2][0] != '\0')
  15345. {
  15346. temptransactionId = atoi(revbuf[2]);
  15347. if(transactionId != temptransactionId)
  15348. {
  15349. fprintf(fptr2, "%s\n", strtemp);
  15350. }
  15351. }
  15352. }
  15353. }
  15354. fclose(fptr1);
  15355. fclose(fptr2);
  15356. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15357. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15358. /*------ Read the file ----------------*/
  15359. }
  15360. int InternetDisconnect(void)
  15361. {
  15362. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15363. }
  15364. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15365. void storeTempStopTransaction(int gun_index)
  15366. {
  15367. char guid[37]={0};
  15368. int tempIndex = 0;
  15369. char TempStopTransaction[256];
  15370. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15371. DEBUG_INFO("storeTempStopTransaction...\n");
  15372. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15373. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15374. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15375. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15376. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15377. {
  15378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15379. {
  15380. tempIndex = ((gun_index==2) ? 1: 0);
  15381. }
  15382. else
  15383. {
  15384. tempIndex = gun_index;
  15385. }
  15386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15387. {
  15388. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15389. {
  15390. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15391. }
  15392. }// END OF CHAdeMO_QUANTITY
  15393. }
  15394. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15395. {
  15396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15397. {
  15398. tempIndex = ((gun_index==2) ? 1: 0);
  15399. }
  15400. else
  15401. {
  15402. tempIndex = gun_index;
  15403. }
  15404. for (int index = 0; index < CCS_QUANTITY; index++)
  15405. {
  15406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15407. {
  15408. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15409. }
  15410. }// END OF CCS_QUANTITY
  15411. }
  15412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15413. {
  15414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15415. {
  15416. tempIndex = ((gun_index==2) ? 1: 0);
  15417. }
  15418. else
  15419. {
  15420. tempIndex = gun_index;
  15421. }
  15422. for (int index = 0; index < GB_QUANTITY; index++)
  15423. {
  15424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15425. {
  15426. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15427. }
  15428. }// END OF GB_QUANTITY
  15429. }
  15430. else if(gunType[gun_index] == GUN_TYPE_DO)
  15431. {
  15432. tempIndex = gun_index;
  15433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15434. {
  15435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15436. {
  15437. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15438. }
  15439. }
  15440. }
  15441. else
  15442. {
  15443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15444. {
  15445. tempIndex = 2;
  15446. }
  15447. else
  15448. {
  15449. tempIndex = gun_index;
  15450. }
  15451. for (int index = 0; index < AC_QUANTITY; index++)
  15452. {
  15453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15454. {
  15455. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15456. }
  15457. }// END OF AC_QUANTITY
  15458. }
  15459. //Stop Transaction Time
  15460. struct timeval tmnow;
  15461. struct tm *tm;
  15462. char buf[28];//, usec_buf[6];
  15463. gettimeofday(&tmnow, NULL);
  15464. time_t t;
  15465. t = time(NULL);
  15466. /*UTC time and date*/
  15467. tm = gmtime(&t);
  15468. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15469. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15470. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15471. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15472. random_uuid(guid);
  15473. /***********************************transactionData******************************************************/
  15474. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15476. //=================================
  15477. //1. Transaction_Begin
  15478. //=================================
  15479. //============================== Energy.Active.Import.Interval ===========================================
  15480. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15481. {
  15482. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15483. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15485. 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*/]);
  15486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15487. 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))
  15488. {
  15489. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15490. }
  15491. else
  15492. {
  15493. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15494. }
  15495. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15497. }
  15498. //=================================
  15499. //2. Transaction_End
  15500. //=================================
  15501. //2.1====================================== Current.Import L1 ==============================================
  15502. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15503. {
  15504. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15505. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15506. {
  15507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15508. {
  15509. tempIndex = ((gun_index==2) ? 1: 0);
  15510. }
  15511. else
  15512. {
  15513. tempIndex = gun_index;
  15514. }
  15515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15516. {
  15517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15518. {
  15519. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15520. }
  15521. }// End of for CHAdeMO_QUANTITY
  15522. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15523. }
  15524. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15525. {
  15526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15527. {
  15528. tempIndex = ((gun_index==2) ? 1: 0);
  15529. }
  15530. else
  15531. {
  15532. tempIndex = gun_index;
  15533. }
  15534. for (int index = 0; index < CCS_QUANTITY; index++)
  15535. {
  15536. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15537. {
  15538. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15539. }
  15540. }// End of for CCS_QUANTITY
  15541. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15542. }
  15543. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15544. {
  15545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15546. {
  15547. tempIndex = ((gun_index==2) ? 1: 0);
  15548. }
  15549. else
  15550. {
  15551. tempIndex = gun_index;
  15552. }
  15553. for (int index = 0; index < GB_QUANTITY; index++)
  15554. {
  15555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15556. {
  15557. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15558. }
  15559. }// End of for GB_QUANTITY
  15560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15561. }
  15562. else if(gunType[gun_index] == GUN_TYPE_DO)
  15563. {
  15564. tempIndex = gun_index;
  15565. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15566. {
  15567. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15568. {
  15569. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15570. }
  15571. }
  15572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15573. }
  15574. else
  15575. {
  15576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15577. {
  15578. tempIndex = 2;
  15579. }
  15580. else
  15581. {
  15582. tempIndex = gun_index;
  15583. }
  15584. for (int index = 0; index < AC_QUANTITY; index++)
  15585. {
  15586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15587. {
  15588. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15589. }
  15590. }// End of for AC_QUANTITY
  15591. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15592. }
  15593. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15596. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15599. }
  15600. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15601. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15602. {
  15603. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15604. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15605. {
  15606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15607. {
  15608. tempIndex = ((gun_index==2) ? 1: 0);
  15609. }
  15610. else
  15611. {
  15612. tempIndex = gun_index;
  15613. }
  15614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15615. {
  15616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15617. {
  15618. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15619. }
  15620. }// END OF CHAdeMO_QUANTITY
  15621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15622. }
  15623. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15624. {
  15625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15626. {
  15627. tempIndex = ((gun_index==2) ? 1: 0);
  15628. }
  15629. else
  15630. {
  15631. tempIndex = gun_index;
  15632. }
  15633. for (int index = 0; index < CCS_QUANTITY; index++)
  15634. {
  15635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15636. {
  15637. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15638. }
  15639. }// END OF CCS_QUANTITY
  15640. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15641. }
  15642. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15643. {
  15644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15645. {
  15646. tempIndex = ((gun_index==2) ? 1: 0);
  15647. }
  15648. else
  15649. {
  15650. tempIndex = gun_index;
  15651. }
  15652. for (int index = 0; index < GB_QUANTITY; index++)
  15653. {
  15654. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15655. {
  15656. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15657. }
  15658. }// END OF GB_QUANTITY
  15659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15660. }
  15661. else if(gunType[gun_index] == GUN_TYPE_DO)
  15662. {
  15663. tempIndex = gun_index;
  15664. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15665. {
  15666. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15667. {
  15668. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15669. }
  15670. }
  15671. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15672. }
  15673. else
  15674. {
  15675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15676. {
  15677. tempIndex = 2;
  15678. }
  15679. else
  15680. {
  15681. tempIndex = gun_index;
  15682. }
  15683. for (int index = 0; index < AC_QUANTITY; index++)
  15684. {
  15685. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15686. {
  15687. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15688. }
  15689. }// END OF AC_QUANTITY
  15690. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15691. }
  15692. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15693. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15694. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15695. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15697. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15698. }
  15699. //2.3====================================== Power.Active.Import =========================================
  15700. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15701. {
  15702. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15703. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15704. {
  15705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15706. {
  15707. tempIndex = ((gun_index==2) ? 1: 0);
  15708. }
  15709. else
  15710. {
  15711. tempIndex = gun_index;
  15712. }
  15713. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15714. {
  15715. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15716. {
  15717. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15718. }
  15719. } // End for CHAdeMO_QUANTITY
  15720. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15721. }
  15722. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15723. {
  15724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15725. {
  15726. tempIndex = ((gun_index==2) ? 1: 0);
  15727. }
  15728. else
  15729. {
  15730. tempIndex = gun_index;
  15731. }
  15732. for (int index = 0; index < CCS_QUANTITY; index++)
  15733. {
  15734. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15735. {
  15736. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15737. }
  15738. } // END for CCS_QUANTITY
  15739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15740. }
  15741. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15742. {
  15743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15744. {
  15745. tempIndex = ((gun_index==2) ? 1: 0);
  15746. }
  15747. else
  15748. {
  15749. tempIndex = gun_index;
  15750. }
  15751. for (int index = 0; index < GB_QUANTITY; index++)
  15752. {
  15753. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15754. {
  15755. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15756. }
  15757. }// END for GB_QUANTITY
  15758. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15759. }
  15760. else if(gunType[gun_index] == GUN_TYPE_DO)
  15761. {
  15762. tempIndex = gun_index;
  15763. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15764. {
  15765. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15766. {
  15767. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15768. }
  15769. }
  15770. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15771. }
  15772. else
  15773. {
  15774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15775. {
  15776. tempIndex = 2;
  15777. }
  15778. else
  15779. {
  15780. tempIndex = gun_index;
  15781. }
  15782. for (int index = 0; index < AC_QUANTITY; index++)
  15783. {
  15784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15785. {
  15786. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15787. }
  15788. } // END for AC_QUANTITY
  15789. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15790. }
  15791. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15792. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15793. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15794. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15795. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15796. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15797. }
  15798. //2.4====================================== Voltage L1 ====================================================
  15799. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15800. {
  15801. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15802. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15803. {
  15804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15805. {
  15806. tempIndex = ((gun_index==2) ? 1: 0);
  15807. }
  15808. else
  15809. {
  15810. tempIndex = gun_index;
  15811. }
  15812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15813. {
  15814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15815. {
  15816. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15817. }
  15818. } // END OF FOR CHAdeMO_QUANTITY
  15819. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15820. }
  15821. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15822. {
  15823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15824. {
  15825. tempIndex = ((gun_index==2) ? 1: 0);
  15826. }
  15827. else
  15828. {
  15829. tempIndex = gun_index;
  15830. }
  15831. for (int index = 0; index < CCS_QUANTITY; index++)
  15832. {
  15833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15834. {
  15835. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15836. }
  15837. } // END OF FOR CCS_QUANTITY
  15838. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15839. }
  15840. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15841. {
  15842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15843. {
  15844. tempIndex = ((gun_index==2) ? 1: 0);
  15845. }
  15846. else
  15847. {
  15848. tempIndex = gun_index;
  15849. }
  15850. for (int index = 0; index < GB_QUANTITY; index++)
  15851. {
  15852. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15853. {
  15854. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15855. }
  15856. } // END OF FOR GB_QUANTITY
  15857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15858. }
  15859. else if(gunType[gun_index] == GUN_TYPE_DO)
  15860. {
  15861. tempIndex = gun_index;
  15862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15863. {
  15864. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15865. {
  15866. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15867. }
  15868. }
  15869. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15870. }
  15871. else
  15872. {
  15873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15874. {
  15875. tempIndex = 2;
  15876. }
  15877. else
  15878. {
  15879. tempIndex = gun_index;
  15880. }
  15881. for (int index = 0; index < AC_QUANTITY; index++)
  15882. {
  15883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15884. {
  15885. 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
  15886. }
  15887. } // END OF FOR AC_QUANTITY
  15888. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15889. }
  15890. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15891. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15892. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15893. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15894. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15895. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15896. }
  15897. //2.5============================================== End SoC =========================================================
  15898. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  15899. {
  15900. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15901. 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))
  15902. {
  15903. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15904. {
  15905. tempIndex = ((gun_index==2) ? 1: 0);
  15906. }
  15907. else
  15908. {
  15909. tempIndex = gun_index;
  15910. }
  15911. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15912. {
  15913. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15914. {
  15915. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15916. {
  15917. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15918. }
  15919. }
  15920. }
  15921. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15922. {
  15923. for (int index = 0; index < CCS_QUANTITY; index++)
  15924. {
  15925. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15926. {
  15927. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15928. }
  15929. }
  15930. }
  15931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15932. {
  15933. for (int index = 0; index < GB_QUANTITY; index++)
  15934. {
  15935. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15936. {
  15937. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15938. }
  15939. }
  15940. }
  15941. else if(gunType[gun_index] == GUN_TYPE_DO)
  15942. {
  15943. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15944. {
  15945. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15946. {
  15947. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15948. }
  15949. }
  15950. }
  15951. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15952. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15953. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15954. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15957. } // END FOR DC CASE
  15958. }
  15959. //2.6====================================== Current.Import L2 ==============================================
  15960. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15961. {
  15962. // AC 3 phase L2 current
  15963. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15964. {
  15965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15966. {
  15967. tempIndex = 2;
  15968. }
  15969. else
  15970. {
  15971. tempIndex = gun_index;
  15972. }
  15973. for (int index = 0; index < AC_QUANTITY; index++)
  15974. {
  15975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15976. {
  15977. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15978. }
  15979. }// End of for AC_QUANTITY
  15980. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15981. }
  15982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15983. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15985. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15986. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15987. }
  15988. //2.7====================================== Current.Import L3 ==============================================
  15989. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15990. {
  15991. // AC 3 phase L3 current
  15992. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15993. {
  15994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15995. {
  15996. tempIndex = 2;
  15997. }
  15998. else
  15999. {
  16000. tempIndex = gun_index;
  16001. }
  16002. for (int index = 0; index < AC_QUANTITY; index++)
  16003. {
  16004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16005. {
  16006. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16007. }
  16008. }// End of for AC_QUANTITY
  16009. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16010. }
  16011. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16012. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16013. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16014. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16016. }
  16017. //2.9====================================== Voltage L2 ====================================================
  16018. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16019. {
  16020. // AC 3 phase L2 volatge
  16021. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16022. {
  16023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16024. {
  16025. tempIndex = 2;
  16026. }
  16027. else
  16028. {
  16029. tempIndex = gun_index;
  16030. }
  16031. for (int index = 0; index < AC_QUANTITY; index++)
  16032. {
  16033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16034. {
  16035. 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
  16036. }
  16037. } // END OF FOR AC_QUANTITY
  16038. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16039. }
  16040. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16041. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16043. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16044. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16045. }
  16046. //2.10====================================== Voltage L3 ====================================================
  16047. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16048. {
  16049. // AC 3 phase L3 volatge
  16050. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16051. {
  16052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16053. {
  16054. tempIndex = 2;
  16055. }
  16056. else
  16057. {
  16058. tempIndex = gun_index;
  16059. }
  16060. for (int index = 0; index < AC_QUANTITY; index++)
  16061. {
  16062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16063. {
  16064. 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
  16065. }
  16066. } // END OF FOR AC_QUANTITY
  16067. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16068. }
  16069. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16070. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16074. }
  16075. //====================== Start SoC ================================
  16076. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16077. {
  16078. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16079. 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))
  16080. {
  16081. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16082. {
  16083. tempIndex = ((gun_index==2) ? 1: 0);
  16084. }
  16085. else
  16086. {
  16087. tempIndex = gun_index;
  16088. }
  16089. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16090. {
  16091. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16092. {
  16093. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16094. {
  16095. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16096. }
  16097. }
  16098. }
  16099. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16100. {
  16101. for (int index = 0; index < CCS_QUANTITY; index++)
  16102. {
  16103. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16104. {
  16105. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16106. }
  16107. }
  16108. }
  16109. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16110. {
  16111. for (int index = 0; index < GB_QUANTITY; index++)
  16112. {
  16113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16114. {
  16115. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16116. }
  16117. }
  16118. }
  16119. else if(gunType[gun_index] == GUN_TYPE_DO)
  16120. {
  16121. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16122. {
  16123. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16124. {
  16125. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16126. }
  16127. }
  16128. }
  16129. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16130. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16131. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16132. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16133. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16134. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16135. } // END FOR DC CASE
  16136. }
  16137. //======================================== Message create ==============================================
  16138. json_object *StopTransaction = json_object_new_object();
  16139. json_object *transactionDatas = json_object_new_array();
  16140. json_object *sampledValues = json_object_new_array();
  16141. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  16142. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16143. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16144. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16145. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16146. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16147. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16148. {
  16149. json_object *transactionData = json_object_new_object();
  16150. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16151. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16152. {
  16153. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16154. {
  16155. json_object *sampledValue = json_object_new_object();
  16156. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16157. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16158. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16159. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16160. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16161. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16162. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16163. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16164. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16165. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16166. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16167. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16168. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16169. json_object_array_add(sampledValues, sampledValue);
  16170. }
  16171. }
  16172. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16173. json_object_array_add(transactionDatas, transactionData);
  16174. }
  16175. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16176. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16177. ,MESSAGE_TYPE_CALL
  16178. ,guid
  16179. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16180. json_object_put(StopTransaction);
  16181. // Check File "TempStopTransaction" Exist
  16182. if((access(TempStopTransaction,F_OK))!=-1)
  16183. {
  16184. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16185. fclose(fopen(TempStopTransaction, "w"));
  16186. }
  16187. else
  16188. {
  16189. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16190. FILE *log = fopen(TempStopTransaction, "w+");
  16191. if(log == NULL)
  16192. {
  16193. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16194. return ;
  16195. }
  16196. else
  16197. {
  16198. fclose(log);
  16199. }
  16200. }
  16201. //Add TempStopTransaction | Update TempStopTransaction
  16202. // open file for writing
  16203. FILE *outfile;
  16204. outfile = fopen (TempStopTransaction, "a");
  16205. //DEBUG_INFO("data = %s\n", queuedata);
  16206. fputs(queuedata, outfile);
  16207. fputs("\n", outfile);
  16208. fclose (outfile);
  16209. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16210. }
  16211. void checkTempStopTransaction(int gun_index)
  16212. {
  16213. FILE *fptr1;
  16214. char ch;
  16215. char str[QUEUE_MESSAGE_LENGTH]={0};
  16216. char guid[37]={0};
  16217. char tempdata[65]={0};
  16218. char connectorStr[2]={0};
  16219. char TempStopTransaction[256];
  16220. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16221. fptr1 = fopen(TempStopTransaction, "r");
  16222. //TempStopTransaction格式: 槍號,StopTransaction封包
  16223. if (!fptr1)
  16224. {
  16225. //printf(" File not found or unable to open the input file!!\n");
  16226. return ;
  16227. }
  16228. ch=fgetc(fptr1);
  16229. //printf(" Now the content of the file %s is : \n",fname);
  16230. rewind(fptr1);
  16231. if(ch!=EOF)
  16232. {
  16233. // copy all contents to the temporary file except the specific line
  16234. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16235. {
  16236. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16237. if(str[0]=='\0')
  16238. {
  16239. break;
  16240. }
  16241. //TempStopTransaction格式: 槍號,StopTransaction封包
  16242. strncpy(connectorStr, str, 1);
  16243. if(atoi(connectorStr) != (gun_index+1))
  16244. {
  16245. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16246. fclose(fptr1);
  16247. return ;
  16248. }
  16249. //random_uuid(guid);
  16250. strncpy(guid, str+6, 36); //copy guid
  16251. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16252. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16253. {
  16254. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16255. }
  16256. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16257. OCPP_insert_transaction_msg(NO, str);
  16258. memset(str,0,ARRAY_SIZE(str));
  16259. }
  16260. }
  16261. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16262. fclose(fptr1);
  16263. remove(TempStopTransaction); // remove the original file
  16264. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16265. }
  16266. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16267. {
  16268. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16269. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16270. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16271. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16272. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16273. }
  16274. int GetWebSocketPingInterval(void)
  16275. {
  16276. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16277. }
  16278. int GetServerSign(void)
  16279. {
  16280. return server_sign;
  16281. }
  16282. uint8_t GetOcppSecurityProfile()
  16283. {
  16284. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16285. }
  16286. void GetOcppChargerBoxId(uint8_t *data)
  16287. {
  16288. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16289. }
  16290. void GetOcppSecurityPassword(uint8_t *data)
  16291. {
  16292. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16293. }
  16294. void SetOcppVersion(uint8_t *version)
  16295. {
  16296. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16297. DEBUG_INFO("ocpp version: %s\n", version);
  16298. if(strstr((char*)version, "ocpp1.6") != NULL)
  16299. {
  16300. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16301. }
  16302. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16303. {
  16304. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16305. system("pkill OcppBackend");
  16306. }
  16307. }
  16308. void SetServerSign(int value)
  16309. {
  16310. server_sign = value;
  16311. }
  16312. int GetBootNotificationInterval(void)
  16313. {
  16314. return BootNotificationInterval;
  16315. }
  16316. int GetInternetConn(void)
  16317. {
  16318. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16319. }
  16320. int GetBackendConnectionTimeout(void)
  16321. {
  16322. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16323. }
  16324. int isConnectorInitMode(int gun_index)
  16325. {
  16326. int tempIndex = 0;
  16327. int result = TRUE;
  16328. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16329. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16330. {
  16331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16332. {
  16333. tempIndex = ((gun_index==2) ? 1: 0);
  16334. }
  16335. else
  16336. {
  16337. tempIndex = gun_index;
  16338. }
  16339. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16340. {
  16341. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16342. {
  16343. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16344. } //end of the same index
  16345. }//end of for CHAdeMO_QUANTITY
  16346. }
  16347. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16348. {
  16349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16350. {
  16351. tempIndex = ((gun_index==2) ? 1: 0);
  16352. }
  16353. else
  16354. {
  16355. tempIndex = gun_index;
  16356. }
  16357. for (int index = 0; index < CCS_QUANTITY; index++)
  16358. {
  16359. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16360. {
  16361. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16362. } //end of the same index
  16363. } // end of for CCS_QUANTITY
  16364. }
  16365. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16366. {
  16367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16368. {
  16369. tempIndex = ((gun_index==2) ? 1: 0);
  16370. }
  16371. else
  16372. {
  16373. tempIndex = gun_index;
  16374. }
  16375. for (int index = 0; index < GB_QUANTITY; index++)
  16376. {
  16377. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16378. {
  16379. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16380. } //end of the same index
  16381. } // end of for GB_QUANTITY
  16382. }
  16383. else if(gunType[gun_index] == GUN_TYPE_DO)
  16384. {
  16385. tempIndex = gun_index;
  16386. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16387. {
  16388. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16389. {
  16390. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16391. } //end of the same index
  16392. }
  16393. }
  16394. else
  16395. {
  16396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16397. {
  16398. tempIndex = 2;
  16399. }
  16400. else
  16401. {
  16402. tempIndex = gun_index;
  16403. }
  16404. for (int index = 0; index < AC_QUANTITY; index++)
  16405. {
  16406. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16407. {
  16408. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16409. }//end of the same index
  16410. }//end of for AC_QUANTITY
  16411. }
  16412. return result;
  16413. }
  16414. void refreshProcDogTimer()
  16415. {
  16416. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16417. }
  16418. void InitialSystemValue(void)
  16419. {
  16420. int connectorIndex = 0;
  16421. //int valueASCII = 0;
  16422. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16423. gunTotalNumber=0;
  16424. SystemInitial = 0;
  16425. locallistVersion=0;
  16426. BootNotificationInterval = 0;
  16427. authorizeRetryTimes = 0;
  16428. GunStatusInterval = 10;
  16429. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16430. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16431. //Hear Beat
  16432. HeartBeatWithNOResponse = 0;
  16433. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16434. FirstHeartBeat = 0;
  16435. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16436. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16437. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16438. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16439. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16440. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16441. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16442. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16443. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16444. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16445. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16446. memset(gunType, 0, ARRAY_SIZE(gunType));
  16447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16448. {
  16449. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16450. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16451. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16452. {
  16453. // DO series
  16454. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16455. {
  16456. SystemInitial = SystemInitial + 1;
  16457. gunTotalNumber = gunTotalNumber + 1;
  16458. gunType[connectorIndex] = GUN_TYPE_DO;
  16459. connectorIndex = connectorIndex + 1;
  16460. }
  16461. }
  16462. else
  16463. {
  16464. // DM, DW, DS series
  16465. //check connector / socket type (index: 8, 9, 10)
  16466. for(int index=7; index <10 ; index++)
  16467. {
  16468. if(index != 8)
  16469. {
  16470. // DC Connector
  16471. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16472. {
  16473. SystemInitial = SystemInitial + 1;
  16474. gunTotalNumber = gunTotalNumber + 1;
  16475. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16476. connectorIndex = connectorIndex + 1;
  16477. }
  16478. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16479. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16480. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16481. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16482. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16483. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16484. {
  16485. SystemInitial = SystemInitial + 1;
  16486. gunTotalNumber = gunTotalNumber + 1;
  16487. gunType[connectorIndex] = GUN_TYPE_CCS;
  16488. connectorIndex = connectorIndex + 1;
  16489. }
  16490. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16491. {
  16492. SystemInitial = SystemInitial + 1;
  16493. gunTotalNumber = gunTotalNumber + 1;
  16494. gunType[connectorIndex] = GUN_TYPE_GBT;
  16495. connectorIndex = connectorIndex + 1;
  16496. }
  16497. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16498. {
  16499. SystemInitial = SystemInitial + 1;
  16500. gunTotalNumber = gunTotalNumber + 1;
  16501. gunType[connectorIndex] = GUN_TYPE_DO;
  16502. connectorIndex = connectorIndex + 1;
  16503. }
  16504. }
  16505. else
  16506. {
  16507. // AC Connector
  16508. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16509. {
  16510. SystemInitial = SystemInitial + 1;
  16511. gunTotalNumber = gunTotalNumber + 1;
  16512. gunType[connectorIndex] = GUN_TYPE_AC;
  16513. connectorIndex = connectorIndex + 1;
  16514. }
  16515. }
  16516. }
  16517. }
  16518. //DEBUG_INFO("DC ...\n");
  16519. }
  16520. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16521. {
  16522. //check connector / socket type (index: 8, 9, 10)
  16523. for(int index=7; index <10 ; index++)
  16524. {
  16525. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16526. {
  16527. SystemInitial = SystemInitial + 1;
  16528. gunTotalNumber = gunTotalNumber + 1;
  16529. gunType[connectorIndex] = GUN_TYPE_AC;
  16530. connectorIndex = connectorIndex + 1;
  16531. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16532. }
  16533. }
  16534. }
  16535. //Status && ConnectorPlugIn Setting
  16536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16537. {
  16538. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16539. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16540. }
  16541. for (int index = 0; index < CCS_QUANTITY; index++)
  16542. {
  16543. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16544. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16545. }
  16546. for (int index = 0; index < GB_QUANTITY; index++)
  16547. {
  16548. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16549. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16550. }
  16551. for (int index = 0; index < AC_QUANTITY; index++)
  16552. {
  16553. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16554. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16555. }
  16556. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16557. {
  16558. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16559. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16560. }
  16561. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16562. {
  16563. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16564. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16565. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16566. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16567. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16568. }
  16569. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16570. clientTime.Heartbeat=time((time_t*)NULL);
  16571. sleep(1);
  16572. }
  16573. void LWS_Send(char *str)
  16574. {
  16575. //=====================================================
  16576. // Check InternetConn 0: disconnected, 1: connected
  16577. //====================================================
  16578. if(GetOcppConnStatus() == 0)
  16579. {
  16580. DEBUG_INFO("offline now !!!\n");
  16581. return;
  16582. }
  16583. // Only disable isWebsocketSendable operation initiated by charger
  16584. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16585. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16586. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16587. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16588. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16589. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16590. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16591. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16592. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16593. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16594. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16595. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16596. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16597. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16598. {
  16599. isWebsocketSendable = 0;
  16600. }
  16601. pthread_mutex_lock(&lock_send);
  16602. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16603. sprintf((char *)SendBuffer, "%s", str);
  16604. SendBufLen = strlen(str);
  16605. pthread_mutex_unlock(&lock_send);
  16606. lws_callback_on_writable(wsi_client);
  16607. //lws_service(context, 0);
  16608. //sleep(1);
  16609. }
  16610. void LWS_SendNow(char *str)
  16611. {
  16612. //=====================================================
  16613. // Check InternetConn 0: disconnected, 1: connected
  16614. //====================================================
  16615. if(GetOcppConnStatus() == 0)
  16616. {
  16617. DEBUG_INFO("offline now !!!\n");
  16618. return;
  16619. }
  16620. // Only disable isWebsocketSendable operation initiated by charger
  16621. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16622. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16623. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16624. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16625. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16626. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16627. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16628. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16629. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16630. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16631. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16632. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16633. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16634. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16635. {
  16636. isWebsocketSendable = 0;
  16637. }
  16638. pthread_mutex_lock(&lock_send);
  16639. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16640. sprintf((char *)SendBuffer, "%s", str);
  16641. SendBufLen = strlen(str);
  16642. pthread_mutex_unlock(&lock_send);
  16643. lws_callback_on_writable(wsi_client);
  16644. lws_service(context, 0);
  16645. //sleep(1);
  16646. }