MessageHandler.c 833 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075
  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 StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  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[500]={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, "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, "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*10));
  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*10));
  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*10));
  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*10));
  6267. }
  6268. }
  6269. }
  6270. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6271. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6272. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Power_Offered]);
  6273. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6274. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].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[4000]={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. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8800. return result;
  8801. }
  8802. void* GetDiagnosticsProcess(void* data)
  8803. {
  8804. pthread_detach(pthread_self());
  8805. mtrace();
  8806. int retriesInt=0, retryIntervalInt=0;
  8807. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8808. 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};
  8809. int port=0;
  8810. int isSuccess = FALSE;
  8811. char ftpbuf[200]={0};
  8812. char cmdBuf[2048];
  8813. struct tm *tmNow;
  8814. time_t CurrentTime;
  8815. struct tm tmStart;
  8816. struct tm tmStop;
  8817. CurrentTime = time(NULL);
  8818. tmNow=localtime(&CurrentTime);
  8819. uint16_t targetYear, targetMonth;
  8820. json_object *GetDiagnostics;
  8821. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8822. GetDiagnostics = json_tokener_parse(data);
  8823. if(!is_error(GetDiagnostics))
  8824. {
  8825. // Required data
  8826. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8827. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8828. // Optional data
  8829. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8830. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8831. else
  8832. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8833. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8834. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8835. else
  8836. retryIntervalInt = 30;
  8837. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8838. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8839. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8840. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8841. }
  8842. json_object_put(GetDiagnostics);
  8843. // Pack log to compress file
  8844. 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) &&
  8845. (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))
  8846. {
  8847. // Pack system log
  8848. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8849. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8850. targetYear = tmStart.tm_year;
  8851. targetMonth = tmStart.tm_mon;
  8852. do
  8853. {
  8854. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8855. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8856. if(targetMonth+1>=13)
  8857. {
  8858. targetYear += 1;
  8859. targetMonth = 1;
  8860. }
  8861. else
  8862. {
  8863. targetMonth += 1;
  8864. }
  8865. }while((targetYear < (tmNow->tm_year+1900)) ||
  8866. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8867. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8868. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8869. system(cmdBuf);
  8870. // Pack charging & event log
  8871. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8872. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8873. targetYear = tmStart.tm_year;
  8874. targetMonth = tmStart.tm_mon;
  8875. do
  8876. {
  8877. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8878. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8879. if(targetMonth+1>=13)
  8880. {
  8881. targetYear += 1;
  8882. targetMonth = 1;
  8883. }
  8884. else
  8885. {
  8886. targetMonth += 1;
  8887. }
  8888. }while((targetYear < (tmNow->tm_year+1900)) ||
  8889. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8890. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8891. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8892. system(cmdBuf);
  8893. // Combine log file
  8894. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8895. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8896. }
  8897. else
  8898. {
  8899. system("exec /root/logPackTools 'log' 6");
  8900. }
  8901. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8902. system(cmdBuf);
  8903. checkUploadLog();
  8904. //****************location*******************/
  8905. if(strcmp(locationstr,"")==0)
  8906. {
  8907. DEBUG_INFO("location is <Empty>!\n");
  8908. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8909. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8910. goto end;
  8911. }
  8912. memset(protocol, 0, ARRAY_SIZE(protocol));
  8913. memset(user, 0, ARRAY_SIZE(user) );
  8914. memset(password, 0, ARRAY_SIZE(password));
  8915. memset(host, 0, ARRAY_SIZE(host));
  8916. memset(path, 0, ARRAY_SIZE(path));
  8917. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8918. memset(host1, 0, ARRAY_SIZE(host1));
  8919. memset(path1, 0, ARRAY_SIZE(path1));
  8920. /*location: ftp://user:password@host:port/path*/
  8921. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8922. if((access(fnamePlusPath,F_OK))!=-1)
  8923. {
  8924. DEBUG_INFO("fnamePlusPath exist.\n");
  8925. }
  8926. else
  8927. {
  8928. DEBUG_INFO("fnamePlusPath not exist!\n");
  8929. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8930. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8931. goto end;
  8932. }
  8933. if(strchr(locationstr,'@')==NULL)
  8934. {
  8935. sscanf(locationstr,
  8936. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8937. protocol, host, &port, path);
  8938. strcpy(user,"anonymous");
  8939. strcpy(password,"");
  8940. }
  8941. else
  8942. {
  8943. //DEBUG_INFO("pch=%s\n", pch);
  8944. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8945. protocol, user, password, host, &port, path);
  8946. }
  8947. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8948. {
  8949. DEBUG_INFO("protocol is not ftp/http ! \n");
  8950. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8951. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8952. goto end;
  8953. }
  8954. if(strncmp(locationstr,"http", 4) == 0)
  8955. {
  8956. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8957. sprintf(ftppath,"/%s", path);
  8958. do
  8959. {
  8960. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8961. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8962. sleep(3);
  8963. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8964. if(!isSuccess)
  8965. {
  8966. DEBUG_INFO("Diagnostics fail.\n");
  8967. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8968. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8969. sleep(retryIntervalInt);
  8970. }
  8971. else
  8972. {
  8973. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8974. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8975. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8976. }
  8977. retriesInt--;
  8978. }while((isSuccess == 0)&&(retriesInt >= 0));
  8979. }
  8980. else
  8981. {
  8982. sscanf(host,"%[^/]%s",host1, path1);
  8983. if(strlen(path) > 0)
  8984. sprintf(ftppath,"/%s", path);
  8985. else
  8986. sprintf(ftppath,"/%s", path1);
  8987. int ftppathlen=strlen(ftppath);
  8988. int i=1;
  8989. char filenametemp[50];
  8990. while(i < ftppathlen)
  8991. {
  8992. int len=ftppathlen-i;
  8993. if(ftppath[len]== 47) // '/' ascll code: 47
  8994. {
  8995. DEBUG_INFO("find '/' all right\n");
  8996. break;
  8997. }
  8998. i=i+1;
  8999. }
  9000. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9001. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9002. filenametemp[i+1] = 0;
  9003. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9004. if(port == 0)
  9005. port = 21;
  9006. do
  9007. {
  9008. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9009. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9010. sleep(3);
  9011. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9012. if(!isSuccess)
  9013. {
  9014. DEBUG_INFO("Diagnostics fail.\n");
  9015. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9016. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9017. sleep(retryIntervalInt);
  9018. }
  9019. else
  9020. {
  9021. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9022. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9023. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9024. }
  9025. retriesInt--;
  9026. }while((!isSuccess)&&(retriesInt >= 0));
  9027. }
  9028. end:
  9029. system("rm -f /mnt/*");
  9030. sleep(5);
  9031. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9032. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9033. pthread_exit(NULL);
  9034. }
  9035. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9036. {
  9037. mtrace();
  9038. int result = FAIL;
  9039. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9040. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9041. {
  9042. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9043. locallistVersion = -1;
  9044. }
  9045. else
  9046. {
  9047. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9048. OCPP_getListVerion();
  9049. }
  9050. //from db.OCPP_getListVerion
  9051. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9052. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9053. sendGetLocalListVersionConfirmation(uuid,"");
  9054. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9055. return result;
  9056. }
  9057. int handleRemoteStartRequest(char *uuid, char *payload)
  9058. {
  9059. mtrace();
  9060. int result = FAIL;
  9061. int connectorIdInt=-1;
  9062. int tempIndex = 0;
  9063. int connectorIdIsNULL, chargingProfileIsNULL;
  9064. char comfirmstr[20]={0};
  9065. char cmdBuf[512];
  9066. json_object *RemoteStartTransaction;
  9067. FILE *fp;
  9068. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9069. if(server_pending == TRUE)
  9070. {
  9071. return 0;
  9072. }
  9073. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9074. RemoteStartTransaction = json_tokener_parse(payload);
  9075. if(!is_error(RemoteStartTransaction))
  9076. {
  9077. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9078. {
  9079. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9080. }
  9081. else
  9082. {
  9083. connectorIdIsNULL = TRUE;
  9084. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9085. {
  9086. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9087. {
  9088. connectorIdIsNULL = FALSE;
  9089. connectorIdInt = (gun_index+1);
  9090. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9091. break;
  9092. }
  9093. }
  9094. }
  9095. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9096. {
  9097. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9098. // Required data
  9099. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9100. // Optional data
  9101. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9102. {
  9103. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9104. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9105. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9106. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9107. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9108. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9109. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9110. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9111. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9112. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9113. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9114. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9115. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9116. {
  9117. 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")));
  9118. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9119. 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"));
  9120. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9121. 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"));
  9122. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9123. 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")));
  9124. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9125. {
  9126. 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++)
  9127. {
  9128. 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"));
  9129. 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"));
  9130. 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)
  9131. 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"));
  9132. }
  9133. }
  9134. }
  9135. }
  9136. else
  9137. {
  9138. chargingProfileIsNULL = TRUE;
  9139. }
  9140. }
  9141. }
  9142. else
  9143. {
  9144. connectorIdIsNULL = TRUE;
  9145. }
  9146. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9147. {
  9148. DEBUG_WARN("Connector id is NULL\n.");
  9149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9150. goto end;
  9151. }
  9152. /*
  9153. enum _SYSTEM_STATUS
  9154. {
  9155. S_BOOTING = 0,
  9156. S_IDLE, = 1
  9157. S_AUTHORIZING, = 2
  9158. S_REASSIGN_CHECK, = 3
  9159. S_REASSIGN, = 4
  9160. S_PRECHARGE, = 5
  9161. S_PREPARING_FOR_EV, = 6
  9162. S_PREPARING_FOR_EVSE, = 7
  9163. S_CHARGING, = 8
  9164. S_TERMINATING, = 9
  9165. S_COMPLETE, = 10
  9166. S_ALARM, = 11
  9167. S_FAULT = 12
  9168. }
  9169. */
  9170. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9171. {
  9172. //check Transaction active
  9173. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9174. {
  9175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9176. {
  9177. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9178. }
  9179. else
  9180. {
  9181. tempIndex = connectorIdInt -1;
  9182. }
  9183. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9184. {
  9185. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9186. {
  9187. 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))
  9188. {
  9189. //Reserved
  9190. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9191. }
  9192. 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))
  9193. {
  9194. //Reserved
  9195. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9196. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9197. goto end;
  9198. }
  9199. else
  9200. {
  9201. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9202. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9203. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9204. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9205. {
  9206. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9207. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9208. goto end;
  9209. }
  9210. }//END FOR ELSE
  9211. }
  9212. }// END FOR CHAdeMO_QUANTITY
  9213. }
  9214. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9215. {
  9216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9217. {
  9218. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9219. }
  9220. else
  9221. {
  9222. tempIndex = connectorIdInt -1;
  9223. }
  9224. for (int index = 0; index < CCS_QUANTITY; index++)
  9225. {
  9226. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9227. {
  9228. 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))
  9229. {
  9230. //Reserved
  9231. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9232. }
  9233. 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))
  9234. {
  9235. //Reserved
  9236. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9237. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9238. goto end;
  9239. }
  9240. else
  9241. {
  9242. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9243. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9244. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9245. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9246. {
  9247. DEBUG_WARN("CCS connector not allow start\n.");
  9248. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9249. goto end;
  9250. }
  9251. }// END FOR ELSE
  9252. }
  9253. }// END FOR CCS_QUANTITY
  9254. }
  9255. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9256. {
  9257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9258. {
  9259. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9260. }
  9261. else
  9262. {
  9263. tempIndex = connectorIdInt -1;
  9264. }
  9265. for (int index = 0; index < GB_QUANTITY; index++)
  9266. {
  9267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9268. {
  9269. 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))
  9270. {
  9271. //Reserved
  9272. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9273. }
  9274. 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))
  9275. {
  9276. //Reserved
  9277. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9278. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9279. goto end;
  9280. }
  9281. else
  9282. {
  9283. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9284. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9285. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9286. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9287. {
  9288. DEBUG_WARN("GB connector not allow start\n.");
  9289. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9290. goto end;
  9291. }
  9292. }// END FOR ELSE
  9293. }
  9294. } // END FOR GB_QUANTITY
  9295. }
  9296. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9297. {
  9298. tempIndex = connectorIdInt -1;
  9299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9300. {
  9301. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9302. {
  9303. 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))
  9304. {
  9305. //Reserved
  9306. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9307. }
  9308. 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))
  9309. {
  9310. //Reserved
  9311. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9313. goto end;
  9314. }
  9315. else
  9316. {
  9317. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9318. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9319. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9320. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9321. {
  9322. DEBUG_WARN("GB connector not allow start\n.");
  9323. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9324. goto end;
  9325. }
  9326. }// END FOR ELSE
  9327. }
  9328. } // END FOR GB_QUANTITY
  9329. }
  9330. else
  9331. {
  9332. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9333. {
  9334. tempIndex = 2;
  9335. }
  9336. else
  9337. {
  9338. tempIndex = connectorIdInt -1;
  9339. }
  9340. for (int index = 0; index < AC_QUANTITY; index++)
  9341. {
  9342. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9343. {
  9344. 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))
  9345. {
  9346. //Reserved
  9347. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9348. }
  9349. 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))
  9350. {
  9351. //Reserved
  9352. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9353. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9354. goto end;
  9355. }
  9356. else
  9357. {
  9358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9359. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9360. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9361. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9362. {
  9363. DEBUG_WARN("AC connector not allow start\n.");
  9364. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9365. goto end;
  9366. }
  9367. }//END FOR ELSE
  9368. }
  9369. }// END FOR AC_QUANTITY
  9370. }
  9371. if(chargingProfileIsNULL == FALSE)
  9372. {
  9373. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9374. {
  9375. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9376. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9377. //memset idTag
  9378. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9379. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9380. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9382. // Save profile to file
  9383. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9384. system(cmdBuf);
  9385. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9386. fp = fopen(cmdBuf, "w");
  9387. 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));
  9388. fclose(fp);
  9389. }
  9390. else
  9391. {
  9392. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9393. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9394. }
  9395. }
  9396. else
  9397. {
  9398. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9399. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9400. //memset idTag
  9401. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9402. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9403. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9404. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9405. }
  9406. }
  9407. else
  9408. {
  9409. DEBUG_WARN("Connector id over\n.");
  9410. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9411. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9412. }
  9413. end:
  9414. json_object_put(RemoteStartTransaction);
  9415. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9416. {
  9417. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9418. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9419. }
  9420. //OCPP send RemoteStartConfirmation by first.
  9421. sendRemoteStartConfirmation(uuid, comfirmstr);
  9422. return result;
  9423. }
  9424. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9425. {
  9426. mtrace();
  9427. int result = FAIL;
  9428. int match = FALSE;
  9429. int GunNO = 0;
  9430. int tempIndex = 0;
  9431. int transactionIdInt=0;
  9432. int transactionIdIsNULL= TRUE;
  9433. char comfirmstr[20];
  9434. json_object *RemoteStopTransaction;
  9435. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9436. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9437. if(server_pending == TRUE)
  9438. {
  9439. return 0;
  9440. }
  9441. RemoteStopTransaction = json_tokener_parse(payload);
  9442. if(!is_error(RemoteStopTransaction))
  9443. {
  9444. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9445. {
  9446. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9447. transactionIdIsNULL = FALSE;
  9448. }
  9449. }
  9450. json_object_put(RemoteStopTransaction);
  9451. if(transactionIdIsNULL == FALSE)
  9452. {
  9453. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9454. {
  9455. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9456. {
  9457. //check Transaction active
  9458. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9459. {
  9460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9461. {
  9462. tempIndex = ((gun_index==2) ? 1: 0);
  9463. }
  9464. else
  9465. {
  9466. tempIndex = gun_index;
  9467. }
  9468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9469. {
  9470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9471. {
  9472. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9473. {
  9474. match = TRUE;
  9475. GunNO = gun_index;
  9476. }
  9477. }
  9478. }// END FOR CHAdeMO_QUANTITY
  9479. }
  9480. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9481. {
  9482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9483. {
  9484. tempIndex = ((gun_index==2) ? 1: 0);
  9485. }
  9486. else
  9487. {
  9488. tempIndex = gun_index;
  9489. }
  9490. for (int index = 0; index < CCS_QUANTITY; index++)
  9491. {
  9492. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9493. {
  9494. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9495. {
  9496. match = TRUE;
  9497. GunNO = gun_index;
  9498. }
  9499. }
  9500. }// END FOR CCS_QUANTITY
  9501. }
  9502. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9503. {
  9504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9505. {
  9506. tempIndex = ((gun_index==2) ? 1: 0);
  9507. }
  9508. else
  9509. {
  9510. tempIndex = gun_index;
  9511. }
  9512. for (int index = 0; index < GB_QUANTITY; index++)
  9513. {
  9514. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9515. {
  9516. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9517. {
  9518. match = TRUE;
  9519. GunNO = gun_index;
  9520. }
  9521. }
  9522. }// END FOR GB_QUANTITY
  9523. }
  9524. else if(gunType[gun_index] == GUN_TYPE_DO)
  9525. {
  9526. tempIndex = gun_index;
  9527. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9528. {
  9529. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9530. {
  9531. 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
  9532. {
  9533. match = TRUE;
  9534. GunNO = gun_index;
  9535. }
  9536. }
  9537. }// END FOR GB_QUANTITY
  9538. }
  9539. else
  9540. {
  9541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9542. {
  9543. tempIndex = 2;
  9544. }
  9545. else
  9546. {
  9547. tempIndex = gun_index;
  9548. }
  9549. for (int index = 0; index < AC_QUANTITY; index++)
  9550. {
  9551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9552. {
  9553. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9554. {
  9555. match = TRUE;
  9556. GunNO = gun_index;
  9557. }
  9558. }
  9559. }// END FOR CHAdeMO_QUANTITY
  9560. } // END FOR AC ELSE
  9561. }// CHECK IF ResponseTransactionId == transactionIdInt
  9562. }//END FOR
  9563. if( match == TRUE)
  9564. {
  9565. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9566. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9567. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9568. }
  9569. else
  9570. {
  9571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9572. }
  9573. }
  9574. else
  9575. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9576. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9577. return result;
  9578. }
  9579. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9580. {
  9581. mtrace();
  9582. int result = FAIL;
  9583. int connectorIdInt=0, reservationIdInt=0;
  9584. int tempIndex = 0;
  9585. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9586. char comfirmstr[20]={0};
  9587. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9588. int c = 0;
  9589. char *loc;
  9590. //char *ptr;
  9591. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9592. strcpy(sstrtemp, stringtrimspace(payload));
  9593. //***(1)connectorId ****/
  9594. c=0;
  9595. loc = strstr(sstrtemp, "connectorId");
  9596. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9597. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9598. {
  9599. sstr[c] = loc[strlen("connectorId")+2+c];
  9600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9601. c++;
  9602. }
  9603. sstr[c] = '\0';
  9604. connectorIdInt = atoi(sstr);
  9605. //***(2)expiryDate ****/
  9606. loc = strstr(sstrtemp, "expiryDate");
  9607. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9608. c = 0;
  9609. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9610. {
  9611. sstr[c] = loc[3+strlen("expiryDate")+c];
  9612. c++;
  9613. }
  9614. sstr[c] = '\0';
  9615. strcpy(expiryDatestr, sstr);
  9616. //***(3)idTag ****/
  9617. loc = strstr(sstrtemp, "idTag");
  9618. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9619. c = 0;
  9620. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9621. {
  9622. sstr[c] = loc[3+strlen("idTag")+c];
  9623. c++;
  9624. }
  9625. sstr[c] = '\0';
  9626. strcpy(idTagstr, sstr);
  9627. //***(4)parentIdTag ****/
  9628. loc = strstr(sstrtemp, "parentIdTag");
  9629. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9630. c = 0;
  9631. if(loc == NULL)
  9632. {
  9633. strcpy(parentIdTagstr, "");
  9634. }
  9635. else
  9636. {
  9637. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9638. {
  9639. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9640. c++;
  9641. }
  9642. sstr[c] = '\0';
  9643. strcpy(parentIdTagstr, sstr);
  9644. }
  9645. //***(5)reservationId ****/
  9646. c=0;
  9647. loc = strstr(sstrtemp, "reservationId");
  9648. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9649. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9650. {
  9651. sstr[c] = loc[strlen("reservationId")+2+c];
  9652. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9653. c++;
  9654. }
  9655. sstr[c] = '\0';
  9656. reservationIdInt = atoi(sstr);
  9657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9658. /*
  9659. enum SYSTEM_STATUS
  9660. {
  9661. SYS_MODE_BOOTING = 0,
  9662. SYS_MODE_IDLE = 1,
  9663. SYS_MODE_AUTHORIZING = 2,
  9664. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9665. SYS_MODE_REASSIGN = 4,
  9666. SYS_MODE_PREPARING = 5,
  9667. SYS_MODE_PREPARE_FOR_EV = 6,
  9668. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9669. SYS_MODE_CHARGING = 8,
  9670. SYS_MODE_TERMINATING = 9,
  9671. SYS_MODE_COMPLETE = 10,
  9672. SYS_MODE_ALARM = 11,
  9673. SYS_MODE_FAULT = 12,
  9674. SYS_MODE_RESERVATION = 13,
  9675. SYS_MODE_BOOKING = 14,
  9676. SYS_MODE_MAINTAIN = 15,
  9677. SYS_MODE_DEBUG = 16,
  9678. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9679. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9680. SYS_MODE_UPDATE = 19
  9681. };
  9682. */
  9683. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9684. {
  9685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9686. goto end;
  9687. }
  9688. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9689. {
  9690. //check Transaction active
  9691. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9692. {
  9693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9694. {
  9695. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9696. }
  9697. else
  9698. {
  9699. tempIndex = connectorIdInt -1;
  9700. }
  9701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9702. {
  9703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9704. {
  9705. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9706. {
  9707. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9708. {
  9709. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9710. {
  9711. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9713. }
  9714. 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'))
  9715. {
  9716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9717. }
  9718. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9719. {
  9720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9721. }
  9722. else
  9723. {
  9724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9725. }
  9726. }
  9727. 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
  9728. {
  9729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9730. }
  9731. }
  9732. else
  9733. {
  9734. //replace reservation
  9735. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9737. }
  9738. }
  9739. } // END FOR CHAdeMO_QUANTITY
  9740. }
  9741. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9742. {
  9743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9744. {
  9745. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9746. }
  9747. else
  9748. {
  9749. tempIndex = connectorIdInt -1;
  9750. }
  9751. for (int index = 0; index < CCS_QUANTITY; index++)
  9752. {
  9753. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9754. {
  9755. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9756. {
  9757. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9758. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9759. {
  9760. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9761. {
  9762. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9764. }
  9765. 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'))
  9766. {
  9767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9768. }
  9769. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9770. {
  9771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9772. }
  9773. else
  9774. {
  9775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9776. }
  9777. }
  9778. 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
  9779. {
  9780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9781. }
  9782. }
  9783. else
  9784. {
  9785. //replace reservation
  9786. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9788. }
  9789. }
  9790. } // END FOR CCS_QUANTITY
  9791. }
  9792. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9793. {
  9794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9795. {
  9796. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9797. }
  9798. else
  9799. {
  9800. tempIndex = connectorIdInt -1;
  9801. }
  9802. for (int index = 0; index < GB_QUANTITY; index++)
  9803. {
  9804. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9805. {
  9806. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9807. {
  9808. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9809. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9810. {
  9811. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9812. {
  9813. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9815. }
  9816. 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'))
  9817. {
  9818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9819. }
  9820. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9821. {
  9822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9823. }
  9824. else
  9825. {
  9826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9827. }
  9828. }
  9829. 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
  9830. {
  9831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9832. }
  9833. }
  9834. else
  9835. {
  9836. //replace reservation
  9837. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9839. }
  9840. }
  9841. }// END FOR GB_QUANTITY
  9842. }
  9843. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9844. {
  9845. tempIndex = connectorIdInt -1;
  9846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9847. {
  9848. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9849. {
  9850. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9851. {
  9852. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9853. 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
  9854. {
  9855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9856. {
  9857. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9859. }
  9860. 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'))
  9861. {
  9862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9863. }
  9864. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9865. {
  9866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9867. }
  9868. else
  9869. {
  9870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9871. }
  9872. }
  9873. 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
  9874. {
  9875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9876. }
  9877. }
  9878. else
  9879. {
  9880. //replace reservation
  9881. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9883. }
  9884. }
  9885. }// END FOR GB_QUANTITY
  9886. }
  9887. else
  9888. {
  9889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9890. {
  9891. tempIndex = 2;
  9892. }
  9893. else
  9894. {
  9895. tempIndex = (connectorIdInt -1);
  9896. }
  9897. for (int index = 0; index < AC_QUANTITY; index++)
  9898. {
  9899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9900. {
  9901. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9902. {
  9903. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9904. {
  9905. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9906. {
  9907. 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))
  9908. {
  9909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9910. }
  9911. else
  9912. {
  9913. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9915. }
  9916. }
  9917. 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'))
  9918. {
  9919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9920. }
  9921. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9922. {
  9923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9924. }
  9925. else
  9926. {
  9927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9928. }
  9929. }
  9930. 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
  9931. {
  9932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9933. }
  9934. }
  9935. else
  9936. {
  9937. //replace reservation
  9938. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9940. }
  9941. }
  9942. } // END FOR AC_QUANTITY
  9943. }
  9944. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9945. }
  9946. else if(connectorIdInt == 0)
  9947. {
  9948. //check Transaction active
  9949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9950. {
  9951. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9952. {
  9953. 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'))
  9954. {
  9955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9956. goto end;
  9957. }
  9958. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9959. {
  9960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9961. goto end;
  9962. }
  9963. 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
  9964. {
  9965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9966. goto end;
  9967. }
  9968. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9969. {
  9970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9971. goto end;
  9972. }
  9973. }
  9974. }// END FOR CHAdeMO_QUANTITY
  9975. for (int index = 0; index < CCS_QUANTITY; index++)
  9976. {
  9977. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9978. {
  9979. 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'))
  9980. {
  9981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9982. goto end;
  9983. }
  9984. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9985. {
  9986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9987. goto end;
  9988. }
  9989. 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
  9990. {
  9991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9992. goto end;
  9993. }
  9994. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9995. {
  9996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9997. goto end;
  9998. }
  9999. }
  10000. } // END FOR CCS_QUANTITY
  10001. for (int index = 0; index < GB_QUANTITY; index++)
  10002. {
  10003. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10004. {
  10005. 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'))
  10006. {
  10007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10008. goto end;
  10009. }
  10010. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10011. {
  10012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10013. goto end;
  10014. }
  10015. 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
  10016. {
  10017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10018. goto end;
  10019. }
  10020. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10021. {
  10022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10023. goto end;
  10024. }
  10025. }
  10026. } // END FOR GB_QUANTITY
  10027. for (int index = 0; index < AC_QUANTITY; index++)
  10028. {
  10029. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10030. {
  10031. 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'))
  10032. {
  10033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10034. goto end;
  10035. }
  10036. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10037. {
  10038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10039. goto end;
  10040. }
  10041. 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
  10042. {
  10043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10044. goto end;
  10045. }
  10046. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10047. {
  10048. 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))
  10049. {
  10050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10051. goto end;
  10052. }
  10053. }
  10054. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10055. {
  10056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10057. goto end;
  10058. }
  10059. }
  10060. }// END FOR AC_QUANTITY
  10061. //The connectorId is 0
  10062. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10064. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10065. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10066. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10067. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10068. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10069. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10070. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10071. result = TRUE;
  10072. return result;
  10073. }
  10074. else
  10075. {
  10076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10077. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10078. }
  10079. if(strcmp(comfirmstr,"Accepted") == 0)
  10080. {
  10081. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10082. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10083. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10084. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10085. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10086. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  10087. result = TRUE;
  10088. return result;
  10089. }
  10090. end:
  10091. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10092. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10093. return result;
  10094. }
  10095. int handleResetRequest(char *uuid, char *payload)
  10096. {
  10097. mtrace();
  10098. int result = FAIL;
  10099. char sstr[10]={0},sstrtemp[30]={ 0 };
  10100. char typestr[10]={0};
  10101. char comfirmstr[20]={0};
  10102. int c = 0;
  10103. char *loc;
  10104. DEBUG_INFO("handleResetRequest...\n");
  10105. strcpy(sstrtemp, stringtrimspace(payload));
  10106. loc = strstr(sstrtemp, "type");
  10107. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10108. c = 0;
  10109. while (loc[3+strlen("type")+c] != '\"')
  10110. {
  10111. sstr[c] = loc[3+strlen("type")+c];
  10112. c++;
  10113. }
  10114. sstr[c] = '\0';
  10115. strcpy(typestr,sstr);
  10116. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  10117. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10118. {
  10119. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  10120. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  10121. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10122. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10123. }
  10124. else
  10125. {
  10126. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10127. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10128. result = PASS;
  10129. }
  10130. sendResetConfirmation(uuid, comfirmstr);
  10131. return result;
  10132. }
  10133. int handleSendLocalListRequest(char *uuid, char *payload)
  10134. {
  10135. mtrace();
  10136. int result = FAIL;
  10137. char comfirmstr[20];
  10138. int checkState_Faulted = FALSE;
  10139. json_object *SendLocalList;
  10140. DEBUG_INFO("handleSendLocalListRequest...\n");
  10141. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10142. {
  10143. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10144. goto end;
  10145. }
  10146. //check Charge Point state
  10147. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10148. {
  10149. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10150. {
  10151. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10152. }
  10153. }
  10154. for (int index = 0; index < CCS_QUANTITY; index++)
  10155. {
  10156. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10157. {
  10158. checkState_Faulted = TRUE; //OCPP Status
  10159. }
  10160. }
  10161. for (int index = 0; index < GB_QUANTITY; index++)
  10162. {
  10163. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10164. {
  10165. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10166. }
  10167. }
  10168. //check Charge Point state
  10169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10170. {
  10171. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10172. {
  10173. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10174. }
  10175. }
  10176. //check Charge Point state
  10177. for (int index = 0; index < AC_QUANTITY; index++)
  10178. {
  10179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10180. {
  10181. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10182. }
  10183. }
  10184. if(checkState_Faulted == TRUE)
  10185. {
  10186. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10187. goto end;
  10188. }
  10189. // Parsing payload
  10190. SendLocalList = json_tokener_parse(payload);
  10191. if(!is_error(SendLocalList))
  10192. {
  10193. // Required data
  10194. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10195. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10196. // Optional data
  10197. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10198. {
  10199. //Check UpdateType
  10200. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10201. {
  10202. //Local list full update
  10203. DEBUG_INFO("Local list full update.\n");
  10204. OCPP_getListVerion();
  10205. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10206. {
  10207. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10208. goto end;
  10209. }
  10210. OCPP_cleanLocalList();
  10211. }
  10212. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10213. {
  10214. //Local list different update
  10215. DEBUG_INFO("Local list different update.\n");
  10216. OCPP_getListVerion();
  10217. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10218. {
  10219. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10220. goto end;
  10221. }
  10222. }
  10223. else
  10224. {
  10225. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10226. goto end;
  10227. }
  10228. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  10229. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10230. {
  10231. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10232. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10233. {
  10234. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].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")));
  10235. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10236. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].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")));
  10237. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10238. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].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")));
  10239. }
  10240. // Add to db
  10241. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10242. {
  10243. //Local list full update
  10244. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10245. idx,
  10246. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10247. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10248. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10249. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10250. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10251. // update list
  10252. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10253. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10254. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10255. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10256. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10257. }
  10258. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10259. {
  10260. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10261. idx,
  10262. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10263. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10264. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10265. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10266. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10267. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10268. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10269. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10270. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10271. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10272. }
  10273. }
  10274. }
  10275. else
  10276. {
  10277. //Check UpdateType
  10278. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10279. {
  10280. //Local list full update
  10281. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10282. OCPP_cleanLocalList();
  10283. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10284. goto end;
  10285. }
  10286. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10287. {
  10288. //Local list different update
  10289. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10290. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10291. goto end;
  10292. }
  10293. }
  10294. result = PASS;
  10295. }
  10296. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10297. end:
  10298. json_object_put(SendLocalList);
  10299. sendSendLocalListConfirmation(uuid, comfirmstr);
  10300. return result;
  10301. }
  10302. #define MAX 200
  10303. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10304. {
  10305. mtrace();
  10306. int result = FAIL;
  10307. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10308. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10309. char chargingProfilePurposeStr[30]={0};
  10310. char chargingProfileKindStr[16]={0};
  10311. char recurrencyKindStr[10]={0};
  10312. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10313. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10314. int chargingSchedulePeriodCount = 0;
  10315. char comfirmstr[20]={0};
  10316. int meet= FALSE;
  10317. FILE *fptr1;
  10318. char filename[MAX]={0};
  10319. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  10320. char rmFileCmd[50]={0};
  10321. char tempchargingProfilePurposeStr[30]={0};
  10322. char word[1600]={0};
  10323. int n_chargingProfile = 0;
  10324. json_object *SetChargingProfile;
  10325. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10326. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10327. SetChargingProfile = json_tokener_parse(payload);
  10328. if(!is_error(SetChargingProfile))
  10329. {
  10330. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10331. {
  10332. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10333. if(connectorIdInt == 0)
  10334. {
  10335. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10336. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10337. }
  10338. else
  10339. {
  10340. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10341. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10342. }
  10343. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10344. }
  10345. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10346. {
  10347. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10348. {
  10349. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10350. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10351. {
  10352. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10353. }
  10354. else
  10355. {
  10356. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10357. }
  10358. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10359. }
  10360. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10361. {
  10362. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10363. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10364. {
  10365. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10366. }
  10367. else
  10368. {
  10369. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10370. }
  10371. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10372. }
  10373. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10374. {
  10375. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10376. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10377. {
  10378. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10379. }
  10380. else
  10381. {
  10382. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10383. }
  10384. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10385. }
  10386. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10387. {
  10388. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10389. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10390. {
  10391. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10392. }
  10393. else
  10394. {
  10395. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10396. }
  10397. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10398. }
  10399. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10400. {
  10401. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10402. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10403. {
  10404. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10405. }
  10406. else
  10407. {
  10408. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10409. }
  10410. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10411. }
  10412. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10413. {
  10414. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10415. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10416. {
  10417. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10418. }
  10419. else
  10420. {
  10421. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10422. }
  10423. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10424. }
  10425. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10426. {
  10427. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10428. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10429. {
  10430. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10431. }
  10432. else
  10433. {
  10434. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10435. }
  10436. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10437. }
  10438. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10439. {
  10440. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10441. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10442. {
  10443. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10444. }
  10445. else
  10446. {
  10447. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10448. }
  10449. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10450. }
  10451. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10452. {
  10453. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10454. {
  10455. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10456. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10457. {
  10458. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10459. }
  10460. else
  10461. {
  10462. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10463. }
  10464. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10465. }
  10466. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10467. {
  10468. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10469. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10470. {
  10471. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10472. }
  10473. else
  10474. {
  10475. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10476. }
  10477. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10478. }
  10479. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10480. {
  10481. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10482. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10483. {
  10484. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10485. }
  10486. else
  10487. {
  10488. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10489. }
  10490. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10491. }
  10492. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10493. {
  10494. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10495. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10496. {
  10497. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10498. }
  10499. else
  10500. {
  10501. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10502. }
  10503. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10504. }
  10505. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10506. {
  10507. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10508. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10509. if(chargingSchedulePeriodCount <= 10)
  10510. {
  10511. 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++)
  10512. {
  10513. 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)
  10514. {
  10515. 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"));
  10516. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10517. {
  10518. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10519. }
  10520. else
  10521. {
  10522. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10523. }
  10524. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10525. }
  10526. 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)
  10527. {
  10528. 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"));
  10529. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10530. {
  10531. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10532. }
  10533. else
  10534. {
  10535. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10536. }
  10537. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10538. }
  10539. 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)
  10540. {
  10541. 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"));
  10542. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10543. {
  10544. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10545. }
  10546. else
  10547. {
  10548. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10549. }
  10550. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10551. }
  10552. }
  10553. }
  10554. }
  10555. }
  10556. }
  10557. }
  10558. json_object_put(SetChargingProfile);
  10559. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10560. {
  10561. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10562. goto end;
  10563. }
  10564. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10565. {
  10566. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10567. if(connectorIdInt != 0)
  10568. {
  10569. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10570. goto end;
  10571. }
  10572. strcpy(filename, ChargePointMaxProfile_JSON );
  10573. fptr1 = fopen(filename, "r");
  10574. if (!fptr1)
  10575. {
  10576. //file not exist
  10577. DEBUG_INFO("Unable to open the input file!!\n");
  10578. fptr1 = fopen(filename, "w+");
  10579. }
  10580. else
  10581. {
  10582. //Check Charging Profile Count
  10583. while(fscanf(fptr1, "%s", word) != EOF)
  10584. {
  10585. //DEBUG_INFO("word=%s\n",word);
  10586. if(strstr(word, "chargingProfileId")!= NULL)
  10587. {
  10588. //DEBUG_INFO("test chargingProfileId \n");
  10589. n_chargingProfile = n_chargingProfile + 1;
  10590. //DEBUG_INFO("chargingProfileId Found\n");
  10591. }
  10592. }
  10593. }
  10594. fclose(fptr1);
  10595. }
  10596. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10597. {
  10598. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10599. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10600. {
  10601. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10602. goto end;
  10603. }
  10604. memset(filename, 0, ARRAY_SIZE(filename));
  10605. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  10606. fptr1 = fopen(filename, "r");
  10607. if (!fptr1)
  10608. {
  10609. //file not exist
  10610. //DEBUG_INFO("Unable to open the input file!!\n");
  10611. fptr1 = fopen(filename, "w+");
  10612. }
  10613. else
  10614. {
  10615. //Check Charging Profile Count
  10616. while(fscanf(fptr1, "%s", word) != EOF)
  10617. {
  10618. //DEBUG_INFO("word=%s\n",word);
  10619. if(strstr(word, "chargingProfileId")!= NULL)
  10620. {
  10621. //DEBUG_INFO("test chargingProfileId \n");
  10622. n_chargingProfile = n_chargingProfile + 1;
  10623. //DEBUG_INFO("chargingProfileId Found\n");
  10624. }
  10625. }
  10626. }
  10627. fclose(fptr1);
  10628. }
  10629. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10630. {
  10631. //printf("set chargingProfile 1-4\n");
  10632. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10633. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10634. if(connectorIdInt == 0)
  10635. {
  10636. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10637. goto end;
  10638. }
  10639. int tempIndex = 0;
  10640. //check Transaction active
  10641. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10642. {
  10643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10644. {
  10645. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10646. }
  10647. else
  10648. {
  10649. tempIndex = connectorIdInt -1;
  10650. }
  10651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10652. {
  10653. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10654. {
  10655. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10656. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10657. {
  10658. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10659. {
  10660. meet = TRUE;
  10661. break;
  10662. }
  10663. }
  10664. }
  10665. }
  10666. }
  10667. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10668. {
  10669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10670. {
  10671. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10672. }
  10673. else
  10674. {
  10675. tempIndex = connectorIdInt -1;
  10676. }
  10677. for (int index = 0; index < CCS_QUANTITY; index++)
  10678. {
  10679. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10680. {
  10681. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10682. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10683. {
  10684. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10685. {
  10686. meet = TRUE;
  10687. break;
  10688. }
  10689. }
  10690. }
  10691. }
  10692. }
  10693. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10694. {
  10695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10696. {
  10697. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10698. }
  10699. else
  10700. {
  10701. tempIndex = connectorIdInt -1;
  10702. }
  10703. for (int index = 0; index < GB_QUANTITY; index++)
  10704. {
  10705. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10706. {
  10707. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10708. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10709. {
  10710. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10711. {
  10712. meet = TRUE;
  10713. break;
  10714. }
  10715. }
  10716. }
  10717. }
  10718. }
  10719. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10720. {
  10721. tempIndex = connectorIdInt -1;
  10722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10723. {
  10724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10725. {
  10726. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10727. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10728. {
  10729. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10730. {
  10731. meet = TRUE;
  10732. break;
  10733. }
  10734. }
  10735. }
  10736. }
  10737. }
  10738. else
  10739. {
  10740. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10741. {
  10742. tempIndex = 2;
  10743. }
  10744. else
  10745. {
  10746. tempIndex = (connectorIdInt -1);
  10747. }
  10748. for (int index = 0; index < AC_QUANTITY; index++)
  10749. {
  10750. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10751. {
  10752. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10753. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10754. {
  10755. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10756. {
  10757. meet = TRUE;
  10758. break;
  10759. }
  10760. }
  10761. }
  10762. }
  10763. }
  10764. //check Transaction active
  10765. if(meet == FALSE)
  10766. {
  10767. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10768. goto end;
  10769. }
  10770. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10771. {
  10772. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10773. goto end;
  10774. }
  10775. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10776. fptr1 = fopen(filename, "r");
  10777. if (!fptr1)
  10778. {
  10779. //file not exist
  10780. DEBUG_INFO("Unable to open the input file!!\n");
  10781. fptr1 = fopen(filename, "w+");
  10782. }
  10783. else
  10784. {
  10785. //Check Charging Profile Count
  10786. while(fscanf(fptr1, "%s", word) != EOF)
  10787. {
  10788. //DEBUG_INFO("word=%s\n",word);
  10789. if(strstr(word, "chargingProfileId")!= NULL)
  10790. {
  10791. //DEBUG_INFO("test chargingProfileId \n");
  10792. n_chargingProfile = n_chargingProfile + 1;
  10793. //DEBUG_INFO("chargingProfileId Found\n");
  10794. }
  10795. }
  10796. }
  10797. fclose(fptr1);
  10798. }
  10799. // Check ChargeProfileMaxStackLevel
  10800. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10801. {
  10802. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10803. goto end;
  10804. }
  10805. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10806. {
  10807. int i = 0;
  10808. char fnametemp[200]={0};
  10809. n_chargingProfile = 0;
  10810. //Check ChargePointMaxProfile.json exit
  10811. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  10812. {
  10813. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  10814. //Check Charging Profile Count
  10815. while(fscanf(fptr1, "%s", word) != EOF)
  10816. {
  10817. //DEBUG_INFO("word=%s\n",word);
  10818. if(strstr(word, "chargingProfileId")!= NULL)
  10819. {
  10820. //DEBUG_INFO("test chargingProfileId \n");
  10821. n_chargingProfile = n_chargingProfile + 1;
  10822. i = i + 1;
  10823. //DEBUG_INFO("chargingProfileId Found\n");
  10824. }
  10825. memset(word, 0, ARRAY_SIZE(word));
  10826. }
  10827. fclose(fptr1);
  10828. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10829. }
  10830. //Check TxDefaultProfile_0.json exit
  10831. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  10832. {
  10833. i = 0;
  10834. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  10835. //Check Charging Profile Count
  10836. while(fscanf(fptr1, "%s", word) != EOF)
  10837. {
  10838. //DEBUG_INFO("word=%s\n",word);
  10839. if(strstr(word, "chargingProfileId")!= NULL)
  10840. {
  10841. //DEBUG_INFO("test chargingProfileId \n");
  10842. n_chargingProfile = n_chargingProfile + 1;
  10843. i = i + 1;
  10844. //DEBUG_INFO("chargingProfileId Found\n");
  10845. }
  10846. memset(word, 0, ARRAY_SIZE(word));
  10847. }
  10848. fclose(fptr1);
  10849. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10850. }
  10851. //Check TxDefaultProfile_%d.json
  10852. for(int j=1; j <= gunTotalNumber; j++)
  10853. {
  10854. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10855. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10856. if((access(fnametemp,F_OK))!=-1)
  10857. {
  10858. i = 0;
  10859. fptr1 = fopen(fnametemp, "r");
  10860. //Check Charging Profile Count
  10861. while(fscanf(fptr1, "%s", word) != EOF)
  10862. {
  10863. //DEBUG_INFO("word=%s\n",word);
  10864. if(strstr(word, "chargingProfileId")!= NULL)
  10865. {
  10866. //DEBUG_INFO("test chargingProfileId \n");
  10867. n_chargingProfile = n_chargingProfile + 1;
  10868. i = i + 1;
  10869. //DEBUG_INFO("chargingProfileId Found\n");
  10870. }
  10871. memset(word, 0, ARRAY_SIZE(word));
  10872. }
  10873. fclose(fptr1);
  10874. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10875. }
  10876. }
  10877. //Check TxProfile_%d.json
  10878. for(int j=1; j <= gunTotalNumber; j++)
  10879. {
  10880. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10881. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10882. if((access(fnametemp,F_OK))!=-1)
  10883. {
  10884. i = 0;
  10885. fptr1 = fopen(fnametemp, "r");
  10886. //Check Charging Profile Count
  10887. while(fscanf(fptr1, "%s", word) != EOF)
  10888. {
  10889. //DEBUG_INFO("word=%s\n",word);
  10890. if(strstr(word, "chargingProfileId")!= NULL)
  10891. {
  10892. //DEBUG_INFO("test chargingProfileId \n");
  10893. n_chargingProfile = n_chargingProfile + 1;
  10894. i = i + 1;
  10895. //DEBUG_INFO("chargingProfileId Found\n");
  10896. }
  10897. memset(word, 0, ARRAY_SIZE(word));
  10898. }
  10899. fclose(fptr1);
  10900. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10901. }
  10902. }
  10903. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10904. {
  10905. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10906. goto end;
  10907. }
  10908. }
  10909. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10910. //**********************************Write to File********************************************************/
  10911. FILE *infile;
  10912. FILE *outfile;
  10913. infile = fopen (filename, "r");
  10914. outfile = fopen (tempfile, "w");
  10915. int d =0;
  10916. d = fgetc(infile);
  10917. rewind(infile);
  10918. if(d == EOF)
  10919. {
  10920. // Profile is empty
  10921. fprintf(outfile,"%s\n",payload);
  10922. fclose(infile);
  10923. fclose(outfile);
  10924. sprintf(rmFileCmd,"rm -f %s",filename);
  10925. system(rmFileCmd);
  10926. rename(tempfile, filename);
  10927. }
  10928. else
  10929. {
  10930. // Profile is not empty
  10931. char buf[2048]={0};
  10932. int ChargingProfileAdded = FALSE;
  10933. while (fgets(buf, sizeof(buf), infile) != NULL)
  10934. {
  10935. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10936. json_object *tmpChargingProfile;
  10937. tmpChargingProfile = json_tokener_parse(buf);
  10938. if(!is_error(SetChargingProfile))
  10939. {
  10940. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10941. {
  10942. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10943. }
  10944. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10945. {
  10946. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10947. {
  10948. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10949. }
  10950. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10951. {
  10952. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10953. }
  10954. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10955. {
  10956. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10957. }
  10958. }
  10959. }
  10960. json_object_put(tmpChargingProfile);
  10961. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10962. {
  10963. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10964. {
  10965. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10966. if(ChargingProfileAdded == FALSE)
  10967. {
  10968. fprintf(outfile,"%s\n",payload);
  10969. ChargingProfileAdded = TRUE;
  10970. }
  10971. }
  10972. else
  10973. {
  10974. if(tempstackLevelInt < stackLevelInt)
  10975. {
  10976. if(ChargingProfileAdded == FALSE)
  10977. {
  10978. fprintf(outfile,"%s\n",buf);
  10979. fprintf(outfile,"%s\n",payload);
  10980. ChargingProfileAdded = TRUE;
  10981. }
  10982. else
  10983. {
  10984. fprintf(outfile,"%s\n",buf);
  10985. }
  10986. }
  10987. else
  10988. {
  10989. if(ChargingProfileAdded == FALSE)
  10990. {
  10991. fprintf(outfile,"%s\n",buf);
  10992. fprintf(outfile,"%s\n",payload);
  10993. ChargingProfileAdded = TRUE;
  10994. }
  10995. else
  10996. {
  10997. fprintf(outfile,"%s\n",buf);
  10998. }
  10999. }
  11000. }
  11001. }
  11002. else
  11003. {
  11004. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11005. {
  11006. if(ChargingProfileAdded == FALSE)
  11007. {
  11008. fprintf(outfile,"%s\n",buf);
  11009. fprintf(outfile,"%s\n",payload);
  11010. ChargingProfileAdded = TRUE;
  11011. }
  11012. else
  11013. {
  11014. fprintf(outfile,"%s\n",buf);
  11015. }
  11016. }
  11017. else if(tempstackLevelInt < stackLevelInt)
  11018. {
  11019. if(ChargingProfileAdded == FALSE)
  11020. {
  11021. fprintf(outfile,"%s\n",buf);
  11022. fprintf(outfile,"%s\n",payload);
  11023. ChargingProfileAdded = TRUE;
  11024. }
  11025. else
  11026. {
  11027. fprintf(outfile,"%s\n",buf);
  11028. }
  11029. }
  11030. else
  11031. {
  11032. if(ChargingProfileAdded == FALSE)
  11033. {
  11034. fprintf(outfile,"%s\n",buf);
  11035. fprintf(outfile,"%s\n",payload);
  11036. ChargingProfileAdded = TRUE;
  11037. }
  11038. else
  11039. {
  11040. fprintf(outfile,"%s\n",buf);
  11041. }
  11042. }
  11043. }
  11044. } // end of while loop
  11045. fclose(infile);
  11046. fclose(outfile);
  11047. sprintf(rmFileCmd,"rm -f %s",filename);
  11048. system(rmFileCmd);
  11049. rename(tempfile, filename);
  11050. }
  11051. sleep(1);
  11052. result = TRUE;
  11053. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11054. end:
  11055. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11056. {
  11057. if(connectorIdInt == 0)
  11058. {
  11059. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11060. {
  11061. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11062. }
  11063. }
  11064. else
  11065. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  11066. }
  11067. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11068. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11069. return result;
  11070. }
  11071. int handleTriggerMessageRequest(char *uuid, char *payload)
  11072. {
  11073. mtrace();
  11074. int result = FAIL;
  11075. int connectorIdIsNULL = FALSE;
  11076. int connectorIdInt =0;
  11077. char sstr[40]={0},sstrtemp[100]={ 0 };
  11078. char requestedMessagestr[40]={0};
  11079. char comfirmstr[20]={0};
  11080. int c = 0;
  11081. char *loc;
  11082. DEBUG_INFO("handleTriggerMessageRequest\n");
  11083. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11084. strcpy(sstrtemp, stringtrimspace(payload));
  11085. c = 0;
  11086. loc = strstr(sstrtemp, "requestedMessage");
  11087. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11088. {
  11089. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11090. c++;
  11091. }
  11092. sstr[c] = '\0';
  11093. strcpy(requestedMessagestr, sstr);
  11094. c = 0;
  11095. loc = strstr(sstrtemp, "connectorId");
  11096. if(loc == NULL)
  11097. {
  11098. connectorIdIsNULL = TRUE;
  11099. }
  11100. else
  11101. {
  11102. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11103. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11104. {
  11105. sstr[c] = loc[strlen("connectorId")+2+c];
  11106. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11107. c++;
  11108. }
  11109. sstr[c] = '\0';
  11110. connectorIdInt = atoi(sstr);
  11111. }
  11112. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11113. {
  11114. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11115. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11116. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11117. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11118. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11119. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11120. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11121. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11122. {
  11123. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11124. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11125. return TRUE;
  11126. }
  11127. else
  11128. {
  11129. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11130. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11131. }
  11132. }
  11133. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11134. {
  11135. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11136. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11137. return TRUE;
  11138. }
  11139. //==========================
  11140. // Trigger message
  11141. //==========================
  11142. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11143. {
  11144. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11145. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11146. {
  11147. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11148. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11149. }
  11150. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11151. }
  11152. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11153. {
  11154. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11155. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11156. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11157. }
  11158. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11159. {
  11160. //sendBootNotificationRequest();
  11161. server_sign = FALSE;
  11162. }
  11163. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11164. {
  11165. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11166. }
  11167. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11168. {
  11169. if(connectorIdIsNULL == FALSE)
  11170. {
  11171. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11172. {
  11173. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11174. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11175. }
  11176. }
  11177. else
  11178. {
  11179. for(int idx=0;idx< gunTotalNumber;idx++)
  11180. {
  11181. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11182. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11183. }
  11184. }
  11185. }
  11186. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11187. {
  11188. if(connectorIdIsNULL == FALSE)
  11189. {
  11190. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11191. {
  11192. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11193. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11194. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11195. }
  11196. }
  11197. else
  11198. {
  11199. for(int idx=0;idx< gunTotalNumber;idx++)
  11200. {
  11201. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11202. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11203. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11204. }
  11205. }
  11206. }
  11207. return result;
  11208. }
  11209. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11210. {
  11211. mtrace();
  11212. int result = FAIL;
  11213. int connectorIdInt =0;
  11214. char comfirmstr[20]={0};
  11215. int tempIndex = 0;
  11216. json_object *UnlockConnector;
  11217. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11218. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11219. UnlockConnector = json_tokener_parse(payload);
  11220. if(!is_error(UnlockConnector))
  11221. {
  11222. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11223. {
  11224. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11225. }
  11226. }
  11227. json_object_put(UnlockConnector);
  11228. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11229. if(gunTotalNumber == 0)
  11230. {
  11231. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11232. goto end;
  11233. }
  11234. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11235. {
  11236. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11237. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11238. goto end;
  11239. }
  11240. else
  11241. {
  11242. //check Transaction active
  11243. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11244. {
  11245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11246. {
  11247. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11248. }
  11249. else
  11250. {
  11251. tempIndex = connectorIdInt -1;
  11252. }
  11253. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11254. {
  11255. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11256. {
  11257. //stop Transaction
  11258. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11259. }
  11260. }
  11261. }
  11262. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11263. {
  11264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11265. {
  11266. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11267. }
  11268. else
  11269. {
  11270. tempIndex = connectorIdInt -1;
  11271. }
  11272. for (int index = 0; index < CCS_QUANTITY; index++)
  11273. {
  11274. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11275. {
  11276. //stop Transaction
  11277. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11278. }
  11279. }
  11280. }
  11281. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11282. {
  11283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11284. {
  11285. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11286. }
  11287. else
  11288. {
  11289. tempIndex = connectorIdInt -1;
  11290. }
  11291. for (int index = 0; index < GB_QUANTITY; index++)
  11292. {
  11293. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11294. {
  11295. //stop Transaction
  11296. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11297. }
  11298. }
  11299. }
  11300. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11301. {
  11302. tempIndex = connectorIdInt -1;
  11303. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11304. {
  11305. 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)))
  11306. {
  11307. //stop Transaction
  11308. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11309. }
  11310. }
  11311. }
  11312. else
  11313. {
  11314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11315. {
  11316. tempIndex = 2;
  11317. }
  11318. else
  11319. {
  11320. tempIndex = connectorIdInt-1;
  11321. }
  11322. for (int index = 0; index < AC_QUANTITY; index++)
  11323. {
  11324. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11325. {
  11326. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11327. }
  11328. }
  11329. }
  11330. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11331. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11332. result = TRUE;
  11333. return result;
  11334. }
  11335. end:
  11336. //json_object_put(obj); --- remove temporally
  11337. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11338. return result;
  11339. }
  11340. static char UpdateFirmwarepayloadData[300]={0};
  11341. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11342. {
  11343. mtrace();
  11344. int result = FAIL;
  11345. pthread_t t;
  11346. sendUpdateFirmwareConfirmation(uuid);
  11347. memset(UpdateFirmwarepayloadData, 0, 300);
  11348. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11349. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11350. ////pthread_join(t, NULL); //
  11351. //pthread_detach(t);
  11352. //sendUpdateFirmwareConfirmation(uuid);
  11353. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11354. return result;
  11355. }
  11356. void *UpdateFirmwareProcess(void *data)
  11357. {
  11358. pthread_detach(pthread_self());
  11359. mtrace();
  11360. int retriesInt =0, retryIntervalInt=0;
  11361. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11362. int port=0;
  11363. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11364. int isSuccess = 0;
  11365. char ftpbuf[512];
  11366. char temp[100];
  11367. char * pch;
  11368. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11369. json_object *UpdateFirmware;
  11370. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11371. if(!is_error(UpdateFirmware))
  11372. {
  11373. // Required data
  11374. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11375. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11376. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11377. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11378. // Optional data
  11379. if(json_object_object_get(UpdateFirmware, "retries"))
  11380. {
  11381. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11382. }
  11383. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11384. {
  11385. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11386. }
  11387. }
  11388. json_object_put(UpdateFirmware);
  11389. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11390. memset(path, 0, ARRAY_SIZE(path));
  11391. // Wait retrieveData
  11392. if(strlen(retrieveDatestr) > 10)
  11393. {
  11394. do
  11395. {
  11396. sleep(1);
  11397. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11398. }
  11399. // Ready to download
  11400. system("rm -f /mnt/*");
  11401. if(strncmp(locationstr,"http", 4) == 0)
  11402. {
  11403. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11404. sprintf(ftppath,"/%s", path);
  11405. DEBUG_INFO("locationstr: %s\n", locationstr);
  11406. DEBUG_INFO("protocol: %s\n",protocol);
  11407. DEBUG_INFO("host: %s\n",host);
  11408. DEBUG_INFO("path: %s\n",path);
  11409. DEBUG_INFO("ftppath: %s\n",ftppath);
  11410. int ftppathlen=strlen(ftppath);
  11411. int i=1;
  11412. char filenametemp[50];
  11413. while(i < ftppathlen)
  11414. {
  11415. int len=ftppathlen-i;
  11416. if(ftppath[len]== 47) // '/' ascll code: 47
  11417. {
  11418. DEBUG_INFO("compare '/' all right\n");
  11419. break;
  11420. }
  11421. i=i+1;
  11422. }
  11423. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11424. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11425. filenametemp[i+1] = 0;
  11426. do
  11427. {
  11428. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11429. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11430. sleep(1);
  11431. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11432. if(!isSuccess)
  11433. {
  11434. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11435. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11436. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11437. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11438. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11439. }
  11440. else
  11441. {
  11442. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11443. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11444. }
  11445. retriesInt--;
  11446. }while((isSuccess == 0)&&(retriesInt >= 0));
  11447. }
  11448. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11449. {
  11450. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11451. memset(temp, 0, ARRAY_SIZE(temp));
  11452. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11453. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11454. int ftppathlen=strlen(ftpbuf);
  11455. int i=1;
  11456. char filenametemp[50];
  11457. while(i < ftppathlen)
  11458. {
  11459. int len=ftppathlen-i;
  11460. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11461. {
  11462. DEBUG_INFO(" compare '/' all right\n");
  11463. break;
  11464. }
  11465. i=i+1;
  11466. }
  11467. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11468. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11469. filenametemp[i+1] = 0;
  11470. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11471. pch=strchr(temp,'@');
  11472. if(pch==NULL)
  11473. {
  11474. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11475. protocol, host, &port, path);
  11476. strcpy(user,"anonymous");
  11477. strcpy(password,"");
  11478. }
  11479. else
  11480. {
  11481. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11482. protocol, user, password, host, &port, path);
  11483. }
  11484. sscanf(host,"%[^/]%s",host1, path1);
  11485. sprintf(ftppath,"%s", path1);
  11486. //DEBUG_INFO("protocol =%s\n",protocol);
  11487. //DEBUG_INFO("user =%s\n",user);
  11488. //DEBUG_INFO("password =%s\n",password);
  11489. //DEBUG_INFO("host1 =%s\n",host1);
  11490. //DEBUG_INFO("port =%d\n",port);
  11491. //DEBUG_INFO("path1 =%s\n",path1);
  11492. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11493. //ftpFile(host, user, password, port, ftppath, fname);
  11494. //download firmware pthred
  11495. if(port == 0)
  11496. {
  11497. port = 21;
  11498. }
  11499. do
  11500. {
  11501. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11502. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11503. sleep(1);
  11504. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11505. if(!isSuccess)
  11506. {
  11507. //BulldogUtil.sleepMs(interval*1000);
  11508. DEBUG_INFO("Update firmware request and download file fail.\n");
  11509. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11510. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11511. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11512. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11513. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11514. }
  11515. else
  11516. {
  11517. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11518. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11519. }
  11520. retriesInt--;
  11521. }while((!isSuccess)&&(retriesInt >= 0));
  11522. }
  11523. else
  11524. {
  11525. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11526. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11527. sleep(1);
  11528. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11529. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11530. }
  11531. // OCPPPH only, must announce CSU upgrade firmware
  11532. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11533. pthread_exit(NULL);
  11534. }
  11535. int handleCertificateSignedRequest(char *uuid, char *payload)
  11536. {
  11537. mtrace();
  11538. int result = PASS;
  11539. json_object *CertificateSigned;
  11540. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11541. CertificateSigned = json_tokener_parse(payload);
  11542. if(!is_error(CertificateSigned))
  11543. {
  11544. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11545. }
  11546. json_object_put(CertificateSigned);
  11547. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11548. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11549. fclose(fp);
  11550. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11551. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11552. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11553. sendCertificateSignedConfirmation(uuid);
  11554. return result;
  11555. }
  11556. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11557. {
  11558. mtrace();
  11559. int result = PASS;
  11560. json_object *DeleteCertificate;
  11561. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11562. DeleteCertificate = json_tokener_parse(payload);
  11563. if(!is_error(DeleteCertificate))
  11564. {
  11565. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11566. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11567. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11568. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11569. }
  11570. json_object_put(DeleteCertificate);
  11571. /*
  11572. * TODO: Delete certificateSigned process
  11573. */
  11574. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11575. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11576. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11577. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11578. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11579. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11580. sendDeleteCertificateConfirmation(uuid);
  11581. return result;
  11582. }
  11583. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11584. {
  11585. mtrace();
  11586. int result = PASS;
  11587. json_object *ExtendedTriggerMessage;
  11588. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11589. ExtendedTriggerMessage = json_tokener_parse(payload);
  11590. if(!is_error(ExtendedTriggerMessage))
  11591. {
  11592. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11593. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11594. {
  11595. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11596. }
  11597. else
  11598. {
  11599. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11600. }
  11601. }
  11602. json_object_put(ExtendedTriggerMessage);
  11603. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11604. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11605. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11606. {
  11607. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11608. }
  11609. else
  11610. {
  11611. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11612. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11613. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11614. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11615. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11616. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11617. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11618. {
  11619. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11620. }
  11621. else
  11622. {
  11623. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11624. }
  11625. }
  11626. sendExtendedTriggerMessageConfirmation(uuid);
  11627. //==========================
  11628. // Trigger message
  11629. //==========================
  11630. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11631. {
  11632. //sendBootNotificationRequest();
  11633. server_sign = FALSE;
  11634. }
  11635. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11636. {
  11637. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11638. }
  11639. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11640. {
  11641. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11642. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11643. {
  11644. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11645. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11646. }
  11647. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11648. }
  11649. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11650. {
  11651. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11652. }
  11653. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11654. {
  11655. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11656. {
  11657. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11658. }
  11659. else
  11660. {
  11661. for(int idx=0;idx< gunTotalNumber;idx++)
  11662. {
  11663. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11664. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11665. }
  11666. }
  11667. }
  11668. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11669. {
  11670. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11671. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11672. {
  11673. 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\" &");
  11674. }
  11675. }
  11676. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11677. {
  11678. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11679. {
  11680. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11681. }
  11682. else
  11683. {
  11684. for(int idx=0;idx< gunTotalNumber;idx++)
  11685. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11686. }
  11687. }
  11688. return result;
  11689. }
  11690. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11691. {
  11692. mtrace();
  11693. int result = PASS;
  11694. json_object *GetInstalledCertificateIds;
  11695. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11696. GetInstalledCertificateIds = json_tokener_parse(payload);
  11697. if(!is_error(GetInstalledCertificateIds))
  11698. {
  11699. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11700. }
  11701. json_object_put(GetInstalledCertificateIds);
  11702. /*
  11703. * TODO: Return installed certificate process
  11704. */
  11705. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11706. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11707. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11708. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11709. sendGetInstalledCertificateIdsConfirmation(uuid);
  11710. return result;
  11711. }
  11712. int handleGetLogRequest(char *uuid, char *payload)
  11713. {
  11714. mtrace();
  11715. int result = PASS;
  11716. json_object *GetLog;
  11717. DEBUG_INFO("handleGetLogRequest...\n");
  11718. GetLog = json_tokener_parse(payload);
  11719. if(!is_error(GetLog))
  11720. {
  11721. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11722. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11723. if(json_object_object_get(GetLog, "retries") != NULL)
  11724. {
  11725. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11726. }
  11727. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11728. {
  11729. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11730. }
  11731. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11732. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11733. {
  11734. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11735. }
  11736. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11737. {
  11738. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11739. }
  11740. }
  11741. json_object_put(GetLog);
  11742. /*
  11743. * TODO: Upload log process
  11744. */
  11745. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11746. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11747. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11748. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11749. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11750. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11751. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11752. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11753. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11754. sendGetLogConfirmation(uuid);
  11755. return result;
  11756. }
  11757. int handleInstallCertificateRequest(char *uuid, char *payload)
  11758. {
  11759. mtrace();
  11760. int result = PASS;
  11761. json_object *InstallCertificate;
  11762. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11763. InstallCertificate = json_tokener_parse(payload);
  11764. if(!is_error(InstallCertificate))
  11765. {
  11766. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11767. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11768. /*
  11769. * TODO: Install certificate process
  11770. */
  11771. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11772. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11773. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11774. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11775. sendInstallCertificateConfirmation(uuid);
  11776. }
  11777. json_object_put(InstallCertificate);
  11778. return result;
  11779. }
  11780. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11781. {
  11782. mtrace();
  11783. int result = PASS;
  11784. json_object *SignedUpdateFirmware;
  11785. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11786. SignedUpdateFirmware = json_tokener_parse(payload);
  11787. if(!is_error(SignedUpdateFirmware))
  11788. {
  11789. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11790. {
  11791. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11792. }
  11793. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11794. {
  11795. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11796. }
  11797. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11798. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11799. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11800. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11801. {
  11802. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11803. }
  11804. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11805. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11806. }
  11807. json_object_put(SignedUpdateFirmware);
  11808. /*
  11809. * TODO: Upgrade firmware process
  11810. */
  11811. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11812. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11813. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11814. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11815. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11816. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11817. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11818. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11819. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11820. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11821. sendInstallCertificateConfirmation(uuid);
  11822. return result;
  11823. }
  11824. int handleUnknownRequest(char *uuid, char *payload)
  11825. {
  11826. mtrace();
  11827. int result = PASS;
  11828. DEBUG_INFO("handleUnknownRequest...\n");
  11829. sendUnknownConfirmation(uuid);
  11830. result = PASS;
  11831. return result;
  11832. }
  11833. //==========================================
  11834. // Handle server response routine
  11835. //==========================================
  11836. void handleAuthorizeResponse(char *payload, int gun_index)
  11837. {
  11838. mtrace();
  11839. char expiryDatestr[30]={0};
  11840. char parentIdTagstr[20]={0};
  11841. char statusstr[20]={0};
  11842. int expiryDateISNULL=FALSE;
  11843. int parentIdTagISNULL=FALSE;
  11844. DEBUG_INFO("handleAuthorizeResponse...\n");
  11845. json_object *Authorize;
  11846. Authorize = json_tokener_parse(payload);
  11847. if(!is_error(Authorize))
  11848. {
  11849. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11850. {
  11851. // Required data
  11852. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11853. // Optional data
  11854. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11855. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11856. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11857. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11858. }
  11859. }
  11860. json_object_put(Authorize);
  11861. if(expiryDateISNULL == FALSE)
  11862. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11863. if(parentIdTagISNULL == FALSE)
  11864. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11865. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11866. //Update idTag information to authorization cache if supproted
  11867. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11868. {
  11869. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11870. }
  11871. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11872. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11873. authorizeRetryTimes = 0;
  11874. }
  11875. void handleBootNotificationResponse(char *payload, int gun_index)
  11876. {
  11877. mtrace();
  11878. char statusStr[12]={0};
  11879. char currentTimeStr[30]={0};
  11880. int intervalInt = 0;
  11881. DEBUG_INFO("handleBootNotificationResponse...\n");
  11882. json_object *BootNotification;
  11883. BootNotification = json_tokener_parse(payload);
  11884. if(!is_error(BootNotification))
  11885. {
  11886. // Required data
  11887. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11888. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11889. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11890. }
  11891. json_object_put(BootNotification);
  11892. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11893. BootNotificationInterval = intervalInt;
  11894. HeartBeatWaitTime = intervalInt;
  11895. //write back to ShmOCPP16DataPH->BootNotification
  11896. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11897. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11898. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11899. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11900. {
  11901. server_sign = TRUE;
  11902. server_pending =FALSE;
  11903. }
  11904. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11905. {
  11906. server_pending = TRUE;
  11907. }
  11908. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11909. srand(time(NULL));
  11910. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11911. SetOcppConnStatus(TRUE);
  11912. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11913. }
  11914. void handleDataTransferResponse(char *payload, int gun_index)
  11915. {
  11916. char sstr[160]={0};//sstr[200]={ 0 };
  11917. int c = 0;
  11918. char *loc;
  11919. DEBUG_INFO("handleDataTransferResponse ...\n");
  11920. loc = strstr(payload, "status");
  11921. c = 0;
  11922. while (loc[3+strlen("status")+c] != '\"')
  11923. {
  11924. sstr[c] = loc[3+strlen("status")+c];
  11925. c++;
  11926. }
  11927. sstr[c] = '\0';
  11928. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11929. }
  11930. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11931. {
  11932. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11933. //struct json_object *obj;
  11934. // obj = json_tokener_parse(payload);
  11935. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11936. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11937. //No fields are defined.
  11938. }
  11939. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11940. {
  11941. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11942. //struct json_object *obj;
  11943. // obj = json_tokener_parse(payload);
  11944. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11945. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11946. //No fields are defined.
  11947. }
  11948. void handleHeartbeatResponse(char *payload, int gun_index)
  11949. {
  11950. mtrace();
  11951. DEBUG_INFO("handleHeartbeatResponse...\n");
  11952. json_object *Heartbeat;
  11953. Heartbeat = json_tokener_parse(payload);
  11954. if(!is_error(Heartbeat))
  11955. {
  11956. // Required data
  11957. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11958. }
  11959. json_object_put(Heartbeat);
  11960. if(FirstHeartBeat == 0)
  11961. {
  11962. FirstHeartBeat = 1;
  11963. DEBUG_INFO("FirstHeartBeat \n");
  11964. }
  11965. HeartBeatWithNOResponse = 0;
  11966. clientTime.Heartbeat=time((time_t*)NULL);
  11967. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11968. }
  11969. void handleMeterValuesResponse(char *payload, int gun_index)
  11970. {
  11971. mtrace();
  11972. DEBUG_INFO("handleMeterValuesResponse...\n");
  11973. }
  11974. void handleStartTransactionResponse(char *payload, int gun_index)
  11975. {
  11976. mtrace();
  11977. //int transactionIdInt = 0;
  11978. FILE *outfile;
  11979. char data[100]={0};
  11980. DEBUG_INFO("handleStartTransactionResponse...\n");
  11981. json_object *StartTransaction;
  11982. StartTransaction = json_tokener_parse(payload);
  11983. if(!is_error(StartTransaction))
  11984. {
  11985. // Required data
  11986. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11987. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11988. // Optional data
  11989. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11990. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11991. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11992. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11993. }
  11994. json_object_put(StartTransaction);
  11995. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11996. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11997. //-----------Start : write to the Queue TransactionId file -----------------//
  11998. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11999. {}
  12000. else
  12001. {
  12002. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12003. if(log == NULL)
  12004. {
  12005. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12006. return ;
  12007. }
  12008. else
  12009. {
  12010. fclose(log);
  12011. }
  12012. }
  12013. // open file for writing
  12014. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12015. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12016. {
  12017. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12018. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12019. fputs(data, outfile);
  12020. fclose (outfile);
  12021. }
  12022. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12023. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12024. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12025. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12026. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12027. }
  12028. void handleStatusNotificationResponse(char *payload, int gun_index)
  12029. {
  12030. mtrace();
  12031. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12032. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12033. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12034. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12035. }
  12036. void handleStopTransactionnResponse(char *payload, int gun_index)
  12037. {
  12038. mtrace();
  12039. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12040. json_object *StopTransaction;
  12041. StopTransaction = json_tokener_parse(payload);
  12042. if(!is_error(StopTransaction))
  12043. {
  12044. // Optional data
  12045. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12046. {
  12047. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12048. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12049. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12050. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12051. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12052. }
  12053. }
  12054. json_object_put(StopTransaction);
  12055. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12056. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12057. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12058. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12059. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12060. }
  12061. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12062. {
  12063. mtrace();
  12064. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12065. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12066. }
  12067. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12068. {
  12069. mtrace();
  12070. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12071. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12072. }
  12073. void handleSignCertificateResponse(char *payload, int gun_index)
  12074. {
  12075. mtrace();
  12076. DEBUG_INFO("handleSignCertificateResponse...\n");
  12077. json_object *SignCertificate;
  12078. SignCertificate = json_tokener_parse(payload);
  12079. if(!is_error(SignCertificate))
  12080. {
  12081. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12082. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12083. }
  12084. json_object_put(SignCertificate);
  12085. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12086. }
  12087. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12088. {
  12089. mtrace();
  12090. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12091. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12092. }
  12093. //==========================================
  12094. // Handle Error routine
  12095. //==========================================
  12096. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12097. {
  12098. mtrace();
  12099. #ifdef SystemLogMessage
  12100. DEBUG_INFO("errorCode: %s\n", errorCode);
  12101. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12102. DEBUG_INFO("errorDetails: %s\n", payload);
  12103. #endif
  12104. }
  12105. //===============================================
  12106. // Common routine
  12107. //===============================================
  12108. int initialConfigurationTable(void)
  12109. {
  12110. //clock_t start_t, end_t, total_t;
  12111. FILE *fp;
  12112. FILE *outfile;
  12113. char str[512]={0};
  12114. char sstr[256]={0};
  12115. int c = 0;
  12116. char *loc;
  12117. int confVersion = 3;
  12118. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12119. //start_t = clock();
  12120. //printf("Starting of the program, start_t = %ld\n", start_t);
  12121. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12122. // Check configuration file size is correct
  12123. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12124. {
  12125. struct stat st;
  12126. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12127. if(st.st_size < 3100)
  12128. {
  12129. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12130. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12131. }
  12132. }
  12133. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12134. {
  12135. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12136. if(outfile == NULL)
  12137. {
  12138. DEBUG_INFO("Error opening file\n");
  12139. return FALSE;
  12140. }
  12141. /*Core Profile*/
  12142. //AllowOfflineTxForUnknownId
  12143. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12147. //AuthorizationCacheEnabled
  12148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12152. //AuthorizeRemoteTxRequests
  12153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12157. //BlinkRepeat
  12158. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12162. //ClockAlignedDataInterval
  12163. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12167. //ConnectionTimeOut
  12168. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12172. //GetConfigurationMaxKeys
  12173. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12177. // HeartbeatInterval
  12178. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12182. // LightIntensity
  12183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12187. // LocalAuthorizeOffline
  12188. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12192. // LocalPreAuthorize
  12193. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12194. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12197. // MaxEnergyOnInvalidId
  12198. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12202. // MeterValuesAlignedData
  12203. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12206. 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" );
  12207. else
  12208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12210. // MeterValuesAlignedDataMaxLength
  12211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12215. else
  12216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12218. // MeterValuesSampledData
  12219. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12222. 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" );
  12223. else
  12224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12226. // MeterValuesSampledDataMaxLength
  12227. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12231. else
  12232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12234. // MeterValueSampleInterval
  12235. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12237. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12239. // MinimumStatusDuration
  12240. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12243. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12245. // NumberOfConnectors
  12246. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12249. {
  12250. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12251. }
  12252. else
  12253. {
  12254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12255. }
  12256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12257. // ResetRetries
  12258. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12262. // ConnectorPhaseRotation
  12263. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12267. // ConnectorPhaseRotationMaxLength
  12268. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12272. // StopTransactionOnEVSideDisconnect
  12273. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12277. // StopTransactionOnInvalidId
  12278. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12280. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12282. // StopTxnAlignedData
  12283. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12287. // StopTxnAlignedDataMaxLength
  12288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12292. // StopTxnSampledData
  12293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12297. else
  12298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12300. // StopTxnSampledDataMaxLength
  12301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12304. {
  12305. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12306. }
  12307. else
  12308. {
  12309. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12310. }
  12311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12312. // SupportedFeatureProfiles
  12313. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12315. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12317. // SupportedFeatureProfilesMaxLength
  12318. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12322. // TransactionMessageAttempts
  12323. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12326. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12328. // TransactionMessageRetryInterval
  12329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12332. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12334. // UnlockConnectorOnEVSideDisconnect
  12335. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12339. // WebSocketPingInterval
  12340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12344. // QueueOffLineStartTransactionMessage
  12345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12349. // AuthorizationKey
  12350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12354. // SecurityProfile
  12355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12357. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12359. // DefaultPrice
  12360. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12364. // CustomDisplayCostAndPrice
  12365. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12369. // CustomIdleFeeAfterStop
  12370. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12374. // Configuration Version
  12375. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12377. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12379. //* Local Auth List Management Profile*/
  12380. #if 0
  12381. //For OCTT Test Case
  12382. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12385. #endif
  12386. #if 1
  12387. //LocalAuthListEnabled
  12388. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12392. #endif
  12393. //LocalAuthListMaxLength
  12394. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12396. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12398. //SendLocalListMaxLength
  12399. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12403. //ReserveConnectorZeroSupported
  12404. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12408. //* Smart Charging Profile */
  12409. //ChargeProfileMaxStackLevel
  12410. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12414. // ChargingScheduleAllowedChargingRateUnit
  12415. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12419. // ChargingScheduleMaxPeriods
  12420. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12424. // ConnectorSwitch3to1PhaseSupported
  12425. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12429. // MaxChargingProfilesInstalled
  12430. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12434. fclose(outfile);
  12435. }
  12436. else
  12437. {
  12438. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12439. char keystr[60]={0};
  12440. char readonlystr[10]={0};
  12441. char valuestr[256]={0};
  12442. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12443. if(fp == NULL) {
  12444. DEBUG_INFO("Error opening file");
  12445. return FALSE;
  12446. }
  12447. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12448. {
  12449. //DEBUG_INFO("Get Configuration \n");
  12450. if(strlen(str) > 0)
  12451. {
  12452. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12453. //*************************key*********************************/
  12454. if(strstr(str, "key") != NULL)
  12455. {
  12456. loc = strstr(str, "key");
  12457. c = 0;
  12458. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12459. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12460. {
  12461. sstr[c] = loc[strlen("key")+3+c];
  12462. c++;
  12463. }
  12464. sstr[c] = '\0';
  12465. strcpy(keystr,sstr);
  12466. }
  12467. //*************************readonly*********************************/
  12468. if(strstr(str, "readonly") != NULL)
  12469. {
  12470. loc = strstr(str, "readonly");
  12471. c = 0;
  12472. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12473. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12474. {
  12475. sstr[c] = loc[strlen("readonly")+2+c];
  12476. c++;
  12477. }
  12478. sstr[c] = '\0';
  12479. strcpy(readonlystr,sstr);
  12480. }
  12481. //*************************value*********************************/
  12482. if(strstr(str, "value") != NULL)
  12483. {
  12484. loc = strstr(str, "value");
  12485. c = 0;
  12486. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12487. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12488. {
  12489. sstr[c] = loc[strlen("value")+3+c];
  12490. c++;
  12491. }
  12492. sstr[c] = '\0';
  12493. strcpy(valuestr,sstr);
  12494. }
  12495. // DEBUG_INFO("keystr=%s\n",keystr);
  12496. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12497. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12498. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12499. {
  12500. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12501. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12502. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12503. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12504. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12505. }
  12506. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12507. {
  12508. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12511. }
  12512. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12513. {
  12514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12516. }
  12517. if(strcmp(keystr, "BlinkRepeat") == 0)
  12518. {
  12519. //Charger.BlinkRepeat = Integer.parseInt(value);
  12520. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12521. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12522. }
  12523. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12524. {
  12525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12527. }
  12528. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12529. {
  12530. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12532. }
  12533. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12534. {
  12535. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12537. }
  12538. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12539. {
  12540. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12542. HeartBeatWaitTime = atoi(valuestr);
  12543. }
  12544. if(strcmp(keystr, "LightIntensity") == 0)
  12545. {
  12546. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12548. }
  12549. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12550. {
  12551. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12552. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12553. }
  12554. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12555. {
  12556. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12558. }
  12559. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12560. {
  12561. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12562. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12563. }
  12564. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12565. {
  12566. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12567. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12568. }
  12569. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12570. {
  12571. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12572. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12573. }
  12574. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12575. {
  12576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12577. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12578. }
  12579. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12580. {
  12581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12582. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12583. }
  12584. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12585. {
  12586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12587. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12588. }
  12589. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12590. {
  12591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12593. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12594. }
  12595. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12596. {
  12597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12599. }
  12600. if(strcmp(keystr, "ResetRetries") == 0)
  12601. {
  12602. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12604. }
  12605. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12606. {
  12607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12609. }
  12610. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12611. {
  12612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12613. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12614. }
  12615. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12616. {
  12617. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12619. }
  12620. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12621. {
  12622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12624. }
  12625. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12626. {
  12627. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12629. }
  12630. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12631. {
  12632. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12633. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12634. }
  12635. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12636. {
  12637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12638. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12639. }
  12640. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12641. {
  12642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12643. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12644. }
  12645. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12646. {
  12647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12648. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12649. }
  12650. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12651. {
  12652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12653. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12654. }
  12655. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12656. {
  12657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12659. TransactionMessageAttemptsValue = atoi(valuestr);
  12660. }
  12661. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12662. {
  12663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12665. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12666. }
  12667. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12668. {
  12669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12671. }
  12672. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12673. {
  12674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12676. }
  12677. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12678. {
  12679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12681. }
  12682. if(strcmp(keystr, "AuthorizationKey") == 0)
  12683. {
  12684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12685. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12686. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12687. }
  12688. if(strcmp(keystr, "SecurityProfile") == 0)
  12689. {
  12690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12691. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12692. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12693. }
  12694. if(strcmp(keystr, "DefaultPrice") == 0)
  12695. {
  12696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12697. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12698. }
  12699. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12700. {
  12701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12703. }
  12704. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12705. {
  12706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12707. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12708. }
  12709. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12710. {
  12711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12712. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12713. }
  12714. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12715. {
  12716. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12717. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12718. }
  12719. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12720. {
  12721. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12722. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12723. }
  12724. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12725. {
  12726. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12727. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12728. }
  12729. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12730. {
  12731. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12732. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12733. }
  12734. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12735. {
  12736. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12738. }
  12739. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12740. {
  12741. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12742. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12743. }
  12744. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12745. {
  12746. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12748. }
  12749. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12750. {
  12751. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12753. }
  12754. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12755. {
  12756. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12758. }
  12759. }
  12760. }
  12761. fclose(fp);
  12762. }
  12763. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12764. {
  12765. return PASS;
  12766. }
  12767. else
  12768. {
  12769. return FAIL;
  12770. }
  12771. }
  12772. void StoreConfigurationTable(void)
  12773. {
  12774. FILE *outfile;
  12775. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12776. if(outfile == NULL)
  12777. {
  12778. DEBUG_INFO("Error opening file");
  12779. return ;
  12780. }
  12781. /*Core Profile*/
  12782. //AllowOfflineTxForUnknownId
  12783. /*
  12784. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12785. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12786. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12787. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12788. */
  12789. //DEBUG_INFO("data=%s\n",data);
  12790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12791. //AuthorizationCacheEnabled
  12792. /*
  12793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12796. */
  12797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12798. //AuthorizeRemoteTxRequests
  12799. /*
  12800. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12801. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12802. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12803. */
  12804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12805. //BlinkRepeat
  12806. /*
  12807. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12810. */
  12811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12812. //ClockAlignedDataInterval
  12813. /*
  12814. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12817. */
  12818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12819. //ConnectionTimeOut
  12820. /*
  12821. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12824. */
  12825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12826. //GetConfigurationMaxKeys
  12827. /*
  12828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12831. */
  12832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12833. // HeartbeatInterval
  12834. /*
  12835. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12838. */
  12839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12840. // LightIntensity
  12841. /*
  12842. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12843. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12845. */
  12846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12847. // LocalAuthorizeOffline
  12848. /*
  12849. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12852. */
  12853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12854. // LocalPreAuthorize
  12855. /*
  12856. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12859. */
  12860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12861. // MaxEnergyOnInvalidId
  12862. /*
  12863. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12866. */
  12867. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12869. // MeterValuesAlignedData
  12870. /*
  12871. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12874. */
  12875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12876. // MeterValuesAlignedDataMaxLength
  12877. /*
  12878. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12881. */
  12882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12883. // MeterValuesSampledData
  12884. /*
  12885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12888. */
  12889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12890. // MeterValuesSampledDataMaxLength
  12891. /*
  12892. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12895. */
  12896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12897. // MeterValueSampleInterval
  12898. /*
  12899. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12902. */
  12903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12904. // MinimumStatusDuration
  12905. /*
  12906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12909. */
  12910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12911. // NumberOfConnectors
  12912. /*
  12913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12916. {
  12917. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12918. }
  12919. else
  12920. {
  12921. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12922. }
  12923. */
  12924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12925. // ResetRetries
  12926. /*
  12927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12930. */
  12931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12932. // ConnectorPhaseRotation
  12933. /*
  12934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12937. */
  12938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12939. // ConnectorPhaseRotationMaxLength
  12940. /*
  12941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12944. */
  12945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12946. // StopTransactionOnEVSideDisconnect
  12947. /*
  12948. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12951. */
  12952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12953. // StopTransactionOnInvalidId
  12954. /*
  12955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12958. */
  12959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12960. // StopTxnAlignedData
  12961. /*
  12962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12965. */
  12966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12967. // StopTxnAlignedDataMaxLength
  12968. /*
  12969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12972. */
  12973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12974. // StopTxnSampledData
  12975. /*
  12976. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12979. */
  12980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12981. // StopTxnSampledDataMaxLength
  12982. /*
  12983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12986. */
  12987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12988. // SupportedFeatureProfiles
  12989. /*
  12990. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12993. */
  12994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12995. // SupportedFeatureProfilesMaxLength
  12996. /*
  12997. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13000. */
  13001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13002. // TransactionMessageAttempts
  13003. /*
  13004. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13007. */
  13008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13009. // TransactionMessageRetryInterval
  13010. /*
  13011. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13014. */
  13015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13016. // UnlockConnectorOnEVSideDisconnect
  13017. /*
  13018. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13021. */
  13022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13023. // WebSocketPingInterval
  13024. /*
  13025. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13028. */
  13029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13030. // QueueOffLineStartTransactionMessage
  13031. /*
  13032. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13035. */
  13036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13037. // AuthorizationKey
  13038. /*
  13039. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13042. */
  13043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13044. // SecurityProfile
  13045. /*
  13046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13049. */
  13050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13051. // DefaultPrice
  13052. /*
  13053. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13056. */
  13057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13058. // CustomDisplayCostAndPrice
  13059. /*
  13060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13063. */
  13064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13065. // CustomIdleFeeAfterStop
  13066. /*
  13067. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13069. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13070. */
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13072. // ConfigurationVersion
  13073. /*
  13074. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13075. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13077. */
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13079. //* Local Auth List Management Profile*/
  13080. //LocalAuthListEnabled
  13081. /*
  13082. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13085. */
  13086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13087. //LocalAuthListMaxLength
  13088. /*
  13089. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13092. */
  13093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13094. //SendLocalListMaxLength
  13095. /*
  13096. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13099. */
  13100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13101. //ReserveConnectorZeroSupported
  13102. /*
  13103. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13106. */
  13107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13108. //* Smart Charging Profile */
  13109. //ChargeProfileMaxStackLevel
  13110. /*
  13111. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13114. */
  13115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13116. // ChargingScheduleAllowedChargingRateUnit
  13117. /*
  13118. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13121. */
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13123. // ChargingScheduleMaxPeriods
  13124. /*
  13125. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13128. */
  13129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13130. // ConnectorSwitch3to1PhaseSupported
  13131. /*
  13132. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13135. */
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13137. // MaxChargingProfilesInstalled
  13138. /*
  13139. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13142. */
  13143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13144. fclose(outfile);
  13145. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13146. }
  13147. void getKeyValue(char *keyReq)
  13148. {
  13149. int isEmpty = FALSE;
  13150. int isKnowKey = FALSE;
  13151. DEBUG_INFO("keyReq = %s\n", keyReq);
  13152. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13153. isEmpty = TRUE;
  13154. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13155. {
  13156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13158. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13159. {
  13160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13161. }
  13162. else
  13163. {
  13164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13165. }
  13166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13167. isKnowKey = TRUE;
  13168. }
  13169. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13170. {
  13171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13173. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13174. {
  13175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13176. }
  13177. else
  13178. {
  13179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13180. }
  13181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13182. isKnowKey = TRUE;
  13183. }
  13184. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13185. {
  13186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13188. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13189. {
  13190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13191. }
  13192. else
  13193. {
  13194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13195. }
  13196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13197. isKnowKey = TRUE;
  13198. }
  13199. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13200. {
  13201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13203. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13204. {
  13205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13206. }
  13207. else
  13208. {
  13209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13210. }
  13211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13212. isKnowKey = TRUE;
  13213. }
  13214. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13215. {
  13216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13218. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13219. {
  13220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13221. }
  13222. else
  13223. {
  13224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13225. }
  13226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13227. isKnowKey = TRUE;
  13228. }
  13229. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13230. {
  13231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13233. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13234. {
  13235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13236. }
  13237. else
  13238. {
  13239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13240. }
  13241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13242. isKnowKey = TRUE;
  13243. }
  13244. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13245. {
  13246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13248. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13249. {
  13250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13251. }
  13252. else
  13253. {
  13254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13255. }
  13256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13257. isKnowKey = TRUE;
  13258. }
  13259. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13260. {
  13261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13263. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13264. {
  13265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13266. }
  13267. else
  13268. {
  13269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13270. }
  13271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13272. isKnowKey = TRUE;
  13273. }
  13274. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13275. {
  13276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13278. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13279. {
  13280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13281. }
  13282. else
  13283. {
  13284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13285. }
  13286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13287. isKnowKey = TRUE;
  13288. }
  13289. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13290. {
  13291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13293. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13294. {
  13295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13296. }
  13297. else
  13298. {
  13299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13300. }
  13301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13302. isKnowKey = TRUE;
  13303. }
  13304. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13305. {
  13306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13308. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13309. {
  13310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13311. }
  13312. else
  13313. {
  13314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13315. }
  13316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13317. isKnowKey = TRUE;
  13318. }
  13319. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13320. {
  13321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13323. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13324. {
  13325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13326. }
  13327. else
  13328. {
  13329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13330. }
  13331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13332. isKnowKey = TRUE;
  13333. }
  13334. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13335. {
  13336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13338. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13339. {
  13340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13341. }
  13342. else
  13343. {
  13344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13345. }
  13346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13347. isKnowKey = TRUE;
  13348. }
  13349. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13350. {
  13351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13353. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13354. {
  13355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13356. }
  13357. else
  13358. {
  13359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13360. }
  13361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13362. isKnowKey = TRUE;
  13363. }
  13364. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13365. {
  13366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13368. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13369. {
  13370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13371. }
  13372. else
  13373. {
  13374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13375. }
  13376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13377. isKnowKey = TRUE;
  13378. }
  13379. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13380. {
  13381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13383. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13384. {
  13385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13386. }
  13387. else
  13388. {
  13389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13390. }
  13391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13392. isKnowKey = TRUE;
  13393. }
  13394. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13395. {
  13396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13398. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13399. {
  13400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13401. }
  13402. else
  13403. {
  13404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13405. }
  13406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13407. isKnowKey = TRUE;
  13408. }
  13409. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13410. {
  13411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13413. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13414. {
  13415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13416. }
  13417. else
  13418. {
  13419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13420. }
  13421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13422. isKnowKey = TRUE;
  13423. }
  13424. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13425. {
  13426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13428. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13429. {
  13430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13431. }
  13432. else
  13433. {
  13434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13435. }
  13436. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13438. isKnowKey = TRUE;
  13439. }
  13440. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13441. {
  13442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13444. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13445. {
  13446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13447. }
  13448. else
  13449. {
  13450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13451. }
  13452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13453. isKnowKey = TRUE;
  13454. }
  13455. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13456. {
  13457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13459. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13460. {
  13461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13462. }
  13463. else
  13464. {
  13465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13466. }
  13467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13468. isKnowKey = TRUE;
  13469. }
  13470. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13471. {
  13472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13475. {
  13476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13477. }
  13478. else
  13479. {
  13480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13481. }
  13482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13483. isKnowKey = TRUE;
  13484. }
  13485. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13486. {
  13487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13490. {
  13491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13492. }
  13493. else
  13494. {
  13495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13496. }
  13497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13498. isKnowKey = TRUE;
  13499. }
  13500. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13501. {
  13502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13504. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13505. {
  13506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13507. }
  13508. else
  13509. {
  13510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13511. }
  13512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13513. isKnowKey = TRUE;
  13514. }
  13515. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13516. {
  13517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13519. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13520. {
  13521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13522. }
  13523. else
  13524. {
  13525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13526. }
  13527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13528. isKnowKey = TRUE;
  13529. }
  13530. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13531. {
  13532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13534. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13535. {
  13536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13537. }
  13538. else
  13539. {
  13540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13541. }
  13542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13543. isKnowKey = TRUE;
  13544. }
  13545. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13546. {
  13547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13549. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13550. {
  13551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13552. }
  13553. else
  13554. {
  13555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13556. }
  13557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13558. isKnowKey = TRUE;
  13559. }
  13560. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13561. {
  13562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13564. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13565. {
  13566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13567. }
  13568. else
  13569. {
  13570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13571. }
  13572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13573. isKnowKey = TRUE;
  13574. }
  13575. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13576. {
  13577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13579. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13580. {
  13581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13582. }
  13583. else
  13584. {
  13585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13586. }
  13587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13588. isKnowKey = TRUE;
  13589. }
  13590. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13591. {
  13592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13594. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13595. {
  13596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13597. }
  13598. else
  13599. {
  13600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13601. }
  13602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13603. isKnowKey = TRUE;
  13604. }
  13605. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13606. {
  13607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13609. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13610. {
  13611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13612. }
  13613. else
  13614. {
  13615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13616. }
  13617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13618. isKnowKey = TRUE;
  13619. }
  13620. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13621. {
  13622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13624. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13625. {
  13626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13627. }
  13628. else
  13629. {
  13630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13631. }
  13632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13633. isKnowKey = TRUE;
  13634. }
  13635. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13636. {
  13637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13639. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13640. {
  13641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13642. }
  13643. else
  13644. {
  13645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13646. }
  13647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13648. isKnowKey = TRUE;
  13649. }
  13650. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13651. {
  13652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13654. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13655. {
  13656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13657. }
  13658. else
  13659. {
  13660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13661. }
  13662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13663. isKnowKey = TRUE;
  13664. }
  13665. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13666. {
  13667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13669. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13670. {
  13671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13672. }
  13673. else
  13674. {
  13675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13676. }
  13677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13678. isKnowKey = TRUE;
  13679. }
  13680. /*
  13681. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13682. {
  13683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13685. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13686. {
  13687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13688. }
  13689. else
  13690. {
  13691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13692. }
  13693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13694. isKnowKey = TRUE;
  13695. }*/
  13696. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13697. {
  13698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13700. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13701. {
  13702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13703. }
  13704. else
  13705. {
  13706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13707. }
  13708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13709. isKnowKey = TRUE;
  13710. }
  13711. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13712. {
  13713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13716. {
  13717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13718. }
  13719. else
  13720. {
  13721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13722. }
  13723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13724. isKnowKey = TRUE;
  13725. }
  13726. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13727. {
  13728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13730. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13731. {
  13732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13733. }
  13734. else
  13735. {
  13736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13737. }
  13738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13739. isKnowKey = TRUE;
  13740. }
  13741. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13742. {
  13743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13745. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13746. {
  13747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13748. }
  13749. else
  13750. {
  13751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13752. }
  13753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13754. isKnowKey = TRUE;
  13755. }
  13756. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13757. {
  13758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13760. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13761. {
  13762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13763. }
  13764. else
  13765. {
  13766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13767. }
  13768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13769. isKnowKey = TRUE;
  13770. }
  13771. #if 1
  13772. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13773. {
  13774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13776. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13777. {
  13778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13779. }
  13780. else
  13781. {
  13782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13783. }
  13784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13785. isKnowKey = TRUE;
  13786. }
  13787. #endif
  13788. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13789. {
  13790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13792. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13793. {
  13794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13795. }
  13796. else
  13797. {
  13798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13799. }
  13800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13801. isKnowKey = TRUE;
  13802. }
  13803. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13804. {
  13805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13807. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13808. {
  13809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13810. }
  13811. else
  13812. {
  13813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13814. }
  13815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13816. isKnowKey = TRUE;
  13817. }
  13818. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13819. {
  13820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13822. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13823. {
  13824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13825. }
  13826. else
  13827. {
  13828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13829. }
  13830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13831. isKnowKey = TRUE;
  13832. }
  13833. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13834. {
  13835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13837. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13838. {
  13839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13840. }
  13841. else
  13842. {
  13843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13844. }
  13845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13846. isKnowKey = TRUE;
  13847. }
  13848. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13849. {
  13850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13852. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13853. {
  13854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13855. }
  13856. else
  13857. {
  13858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13859. }
  13860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13861. isKnowKey = TRUE;
  13862. }
  13863. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13864. {
  13865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13867. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13868. {
  13869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13870. }
  13871. else
  13872. {
  13873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13874. }
  13875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13876. isKnowKey = TRUE;
  13877. }
  13878. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13879. {
  13880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13882. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13883. {
  13884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13885. }
  13886. else
  13887. {
  13888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13889. }
  13890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13891. isKnowKey = TRUE;
  13892. }
  13893. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13894. {
  13895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13897. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13898. {
  13899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13900. }
  13901. else
  13902. {
  13903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13904. }
  13905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13906. isKnowKey = TRUE;
  13907. }
  13908. //=========================================================
  13909. if(!isEmpty && !isKnowKey)
  13910. {
  13911. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13912. strcpy(unknownkey[UnknownKeynum], keyReq);
  13913. UnknownKeynum = UnknownKeynum + 1;
  13914. }
  13915. }
  13916. void processUnkownKey(void)
  13917. {
  13918. DEBUG_INFO("processUnkownKey...\n");
  13919. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13920. for(int index=0; index < UnknownKeynum; index++)
  13921. {
  13922. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13923. {
  13924. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13925. }
  13926. }
  13927. }
  13928. int setKeyValue(char *key, char *value)
  13929. {
  13930. int isSuccess = NotSupported;
  13931. int check_ascii=0;
  13932. char str[256]={0};
  13933. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13934. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13935. {
  13936. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13937. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13938. {
  13939. strcpy(str, (const char*)value);
  13940. for(int i = 0; str[i]; i++){
  13941. str[i] = tolower(str[i]);
  13942. }
  13943. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13944. isSuccess = ConfigurationStatus_Accepted;
  13945. }
  13946. else
  13947. {
  13948. isSuccess = ConfigurationStatus_Rejected;
  13949. }
  13950. }
  13951. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13952. {
  13953. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13954. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13955. {
  13956. strcpy(str, (const char*)value);
  13957. for(int i = 0; str[i]; i++){
  13958. str[i] = tolower(str[i]);
  13959. }
  13960. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13961. isSuccess = ConfigurationStatus_Accepted;
  13962. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13963. }
  13964. else
  13965. {
  13966. isSuccess = ConfigurationStatus_Rejected;
  13967. }
  13968. }
  13969. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13970. {
  13971. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13972. {
  13973. strcpy(str, (const char*)value);
  13974. for(int i = 0; str[i]; i++)
  13975. {
  13976. str[i] = tolower(str[i]);
  13977. }
  13978. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13979. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13980. isSuccess = ConfigurationStatus_Accepted;
  13981. }
  13982. else
  13983. {
  13984. isSuccess = ConfigurationStatus_Rejected;
  13985. }
  13986. }
  13987. if(strcmp(key, "BlinkRepeat") == 0)
  13988. {
  13989. //Charger.BlinkRepeat = Integer.parseInt(value);
  13990. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13991. {
  13992. check_ascii = value[0];
  13993. if( (check_ascii < 48) || (check_ascii > 57) )
  13994. {
  13995. isSuccess = ConfigurationStatus_Rejected;
  13996. }
  13997. else
  13998. {
  13999. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14000. isSuccess = ConfigurationStatus_Accepted;
  14001. }
  14002. }
  14003. else
  14004. {
  14005. isSuccess = ConfigurationStatus_Rejected;
  14006. }
  14007. }
  14008. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14009. {
  14010. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14011. {
  14012. check_ascii = value[0];
  14013. if( (check_ascii < 48) || (check_ascii > 57) )
  14014. {
  14015. isSuccess = ConfigurationStatus_Rejected;
  14016. }
  14017. else
  14018. {
  14019. if((atoi(value) == 0) || (atoi(value) >= 10))
  14020. {
  14021. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14022. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14023. isSuccess = ConfigurationStatus_Accepted;
  14024. }
  14025. else
  14026. isSuccess = ConfigurationStatus_Rejected;
  14027. }
  14028. }
  14029. else
  14030. {
  14031. isSuccess = ConfigurationStatus_Rejected;
  14032. }
  14033. }
  14034. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14035. {
  14036. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14037. {
  14038. check_ascii = value[0];
  14039. if( (check_ascii < 48) || (check_ascii > 57) )
  14040. {
  14041. isSuccess = ConfigurationStatus_Rejected;
  14042. }
  14043. else
  14044. {
  14045. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14046. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14047. isSuccess = ConfigurationStatus_Accepted;
  14048. }
  14049. }
  14050. else
  14051. {
  14052. isSuccess = ConfigurationStatus_Rejected;
  14053. }
  14054. }
  14055. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14056. {
  14057. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14058. {
  14059. check_ascii = value[0];
  14060. if( (check_ascii < 48) || (check_ascii > 57) )
  14061. {
  14062. isSuccess = ConfigurationStatus_Rejected;
  14063. }
  14064. else
  14065. {
  14066. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14067. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14068. isSuccess = ConfigurationStatus_Accepted;
  14069. }
  14070. }
  14071. else
  14072. {
  14073. isSuccess = ConfigurationStatus_Rejected;
  14074. }
  14075. }
  14076. if(strcmp(key, "HeartbeatInterval") == 0)
  14077. {
  14078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14079. {
  14080. check_ascii = value[0];
  14081. if( (check_ascii < 48) || (check_ascii > 57) )
  14082. {
  14083. isSuccess = ConfigurationStatus_Rejected;
  14084. }
  14085. else
  14086. {
  14087. if((atoi(value) == 0) || (atoi(value) >= 10))
  14088. {
  14089. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14090. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14091. HeartBeatWaitTime = atoi(value);
  14092. isSuccess = ConfigurationStatus_Accepted;
  14093. }
  14094. else
  14095. {
  14096. isSuccess = ConfigurationStatus_Rejected;
  14097. }
  14098. }
  14099. }
  14100. else
  14101. {
  14102. isSuccess = ConfigurationStatus_Rejected;
  14103. }
  14104. }
  14105. if(strcmp(key, "LightIntensity") == 0)
  14106. {
  14107. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14108. {
  14109. check_ascii = value[0];
  14110. if( (check_ascii < 48) || (check_ascii > 57) )
  14111. {
  14112. isSuccess = ConfigurationStatus_Rejected;
  14113. }
  14114. else
  14115. {
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14117. isSuccess = ConfigurationStatus_Accepted;
  14118. }
  14119. }
  14120. else
  14121. {
  14122. isSuccess = ConfigurationStatus_Rejected;
  14123. }
  14124. }
  14125. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14126. {
  14127. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14128. {
  14129. strcpy(str, (const char*)value);
  14130. for(int i = 0; str[i]; i++)
  14131. {
  14132. str[i] = tolower(str[i]);
  14133. }
  14134. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14135. isSuccess = ConfigurationStatus_Accepted;
  14136. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14137. }
  14138. else
  14139. {
  14140. isSuccess = ConfigurationStatus_Rejected;
  14141. }
  14142. }
  14143. if(strcmp(key, "LocalPreAuthorize") == 0)
  14144. {
  14145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14146. {
  14147. strcpy(str, (const char*)value);
  14148. for(int i = 0; str[i]; i++)
  14149. {
  14150. str[i] = tolower(str[i]);
  14151. }
  14152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14153. isSuccess = ConfigurationStatus_Accepted;
  14154. }
  14155. else
  14156. {
  14157. isSuccess = ConfigurationStatus_Rejected;
  14158. }
  14159. }
  14160. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14161. {
  14162. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14163. {
  14164. check_ascii = value[0];
  14165. if( (check_ascii < 48) || (check_ascii > 57) )
  14166. {
  14167. isSuccess = ConfigurationStatus_Rejected;
  14168. }
  14169. else
  14170. {
  14171. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14172. isSuccess = ConfigurationStatus_Accepted;
  14173. }
  14174. }
  14175. else
  14176. {
  14177. isSuccess = ConfigurationStatus_Rejected;
  14178. }
  14179. }
  14180. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14181. {
  14182. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14183. {
  14184. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14185. isSuccess = ConfigurationStatus_Accepted;
  14186. }
  14187. else
  14188. {
  14189. isSuccess = ConfigurationStatus_Rejected;
  14190. }
  14191. }
  14192. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14193. {
  14194. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14195. {
  14196. check_ascii = value[0];
  14197. if( (check_ascii < 48) || (check_ascii > 57) )
  14198. {
  14199. isSuccess = ConfigurationStatus_Rejected;
  14200. }
  14201. else
  14202. {
  14203. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14204. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14205. isSuccess = ConfigurationStatus_Accepted;
  14206. }
  14207. }
  14208. else
  14209. {
  14210. isSuccess = ConfigurationStatus_Rejected;
  14211. }
  14212. }
  14213. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14214. {
  14215. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14216. {
  14217. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14218. isSuccess = ConfigurationStatus_Accepted;
  14219. }
  14220. else
  14221. {
  14222. isSuccess = ConfigurationStatus_Rejected;
  14223. }
  14224. }
  14225. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14226. {
  14227. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14228. {
  14229. check_ascii = value[0];
  14230. if( (check_ascii < 48) || (check_ascii > 57) )
  14231. {
  14232. isSuccess = ConfigurationStatus_Rejected;
  14233. }
  14234. else
  14235. {
  14236. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14237. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14238. isSuccess = ConfigurationStatus_Accepted;
  14239. }
  14240. }
  14241. else
  14242. {
  14243. isSuccess = ConfigurationStatus_Rejected;
  14244. }
  14245. }
  14246. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14247. {
  14248. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14249. {
  14250. check_ascii = value[0];
  14251. if( (check_ascii < 48) || (check_ascii > 57) )
  14252. {
  14253. isSuccess = ConfigurationStatus_Rejected;
  14254. }
  14255. else
  14256. {
  14257. if((atoi(value) == 0) || (atoi(value) >= 10))
  14258. {
  14259. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14260. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14261. isSuccess = ConfigurationStatus_Accepted;
  14262. }
  14263. else
  14264. {
  14265. isSuccess = ConfigurationStatus_Rejected;
  14266. }
  14267. }
  14268. }
  14269. else
  14270. {
  14271. isSuccess = ConfigurationStatus_Rejected;
  14272. }
  14273. }
  14274. if(strcmp(key, "MinimumStatusDuration") == 0)
  14275. {
  14276. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14277. {
  14278. check_ascii = value[0];
  14279. if( (check_ascii < 48) || (check_ascii > 57) )
  14280. {
  14281. isSuccess = ConfigurationStatus_Rejected;
  14282. }
  14283. else
  14284. {
  14285. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14286. {
  14287. isSuccess = ConfigurationStatus_Rejected;
  14288. }
  14289. else
  14290. {
  14291. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14293. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14294. isSuccess = ConfigurationStatus_Accepted;
  14295. }
  14296. }
  14297. }
  14298. else
  14299. {
  14300. isSuccess = ConfigurationStatus_Rejected;
  14301. }
  14302. }
  14303. if(strcmp(key, "NumberOfConnectors") == 0)
  14304. {
  14305. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14306. {
  14307. check_ascii = value[0];
  14308. if( (check_ascii < 48) || (check_ascii > 57) )
  14309. {
  14310. isSuccess = ConfigurationStatus_Rejected;
  14311. }
  14312. else
  14313. {
  14314. //Charger.ResetRetries = Integer.parseInt(value);
  14315. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14316. isSuccess = ConfigurationStatus_Accepted;
  14317. }
  14318. }
  14319. else
  14320. {
  14321. isSuccess = ConfigurationStatus_Rejected;
  14322. }
  14323. }
  14324. if(strcmp(key, "ResetRetries") == 0)
  14325. {
  14326. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14327. {
  14328. check_ascii = value[0];
  14329. if( (check_ascii < 48) || (check_ascii > 57) )
  14330. {
  14331. isSuccess = ConfigurationStatus_Rejected;
  14332. }
  14333. else
  14334. {
  14335. //Charger.ResetRetries = Integer.parseInt(value);
  14336. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14337. isSuccess = ConfigurationStatus_Accepted;
  14338. }
  14339. }
  14340. else
  14341. {
  14342. isSuccess = ConfigurationStatus_Rejected;
  14343. }
  14344. }
  14345. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14346. {
  14347. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14348. {
  14349. strcpy(str, (const char*)value);
  14350. for(int i = 0; str[i]; i++)
  14351. {
  14352. str[i] = tolower(str[i]);
  14353. }
  14354. if(strcmp(str, "notapplicable")== 0)
  14355. {
  14356. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14357. isSuccess = ConfigurationStatus_Accepted;
  14358. }
  14359. else if(strcmp(str, "unknown")== 0)
  14360. {
  14361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14362. isSuccess = ConfigurationStatus_Accepted;
  14363. }
  14364. else if(strcmp(str, "rst")== 0)
  14365. {
  14366. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14367. isSuccess = ConfigurationStatus_Accepted;
  14368. }
  14369. else if(strcmp(str, "rts")== 0)
  14370. {
  14371. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14372. isSuccess = ConfigurationStatus_Accepted;
  14373. }
  14374. else if(strcmp(str, "srt")== 0)
  14375. {
  14376. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14377. isSuccess = ConfigurationStatus_Accepted;
  14378. }
  14379. else if(strcmp(str, "str")== 0)
  14380. {
  14381. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14382. isSuccess = ConfigurationStatus_Accepted;
  14383. }
  14384. else if(strcmp(str, "trs")== 0)
  14385. {
  14386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14387. isSuccess = ConfigurationStatus_Accepted;
  14388. }
  14389. else if(strcmp(str, "tsr")== 0)
  14390. {
  14391. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14392. isSuccess = ConfigurationStatus_Accepted;
  14393. }
  14394. else
  14395. {
  14396. isSuccess = ConfigurationStatus_Rejected;
  14397. }
  14398. }
  14399. else
  14400. {
  14401. isSuccess = ConfigurationStatus_Rejected;
  14402. }
  14403. }
  14404. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14405. {
  14406. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14407. {
  14408. check_ascii = value[0];
  14409. if( (check_ascii < 48) || (check_ascii > 57) )
  14410. {
  14411. isSuccess = ConfigurationStatus_Rejected;
  14412. }
  14413. else
  14414. {
  14415. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14416. isSuccess = ConfigurationStatus_Accepted;
  14417. }
  14418. }
  14419. else
  14420. {
  14421. isSuccess = ConfigurationStatus_Rejected;
  14422. }
  14423. }
  14424. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14425. {
  14426. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14427. {
  14428. strcpy(str, (const char*)value);
  14429. for(int i = 0; str[i]; i++)
  14430. {
  14431. str[i] = tolower(str[i]);
  14432. }
  14433. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14434. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14435. isSuccess = ConfigurationStatus_Accepted;
  14436. }
  14437. else
  14438. {
  14439. isSuccess = ConfigurationStatus_Rejected;
  14440. }
  14441. }
  14442. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14443. {
  14444. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14445. {
  14446. strcpy(str, (const char*)value);
  14447. for(int i = 0; str[i]; i++)
  14448. {
  14449. str[i] = tolower(str[i]);
  14450. }
  14451. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14452. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14453. isSuccess = ConfigurationStatus_Accepted;
  14454. }
  14455. else
  14456. {
  14457. isSuccess = ConfigurationStatus_Rejected;
  14458. }
  14459. }
  14460. if(strcmp(key, "StopTxnAlignedData") == 0)
  14461. {
  14462. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14463. {
  14464. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14465. isSuccess = ConfigurationStatus_Accepted;
  14466. }
  14467. else
  14468. {
  14469. isSuccess = ConfigurationStatus_Rejected;
  14470. }
  14471. }
  14472. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14473. {
  14474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14475. {
  14476. check_ascii = value[0];
  14477. if( (check_ascii < 48) || (check_ascii > 57) )
  14478. {
  14479. isSuccess = ConfigurationStatus_Rejected;
  14480. }
  14481. else
  14482. {
  14483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14484. isSuccess = ConfigurationStatus_Accepted;
  14485. }
  14486. }
  14487. else
  14488. {
  14489. isSuccess = ConfigurationStatus_Rejected;
  14490. }
  14491. }
  14492. if(strcmp(key, "StopTxnSampledData") == 0)
  14493. {
  14494. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14495. {
  14496. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14497. isSuccess = ConfigurationStatus_Accepted;
  14498. }
  14499. else
  14500. {
  14501. isSuccess = ConfigurationStatus_Rejected;
  14502. }
  14503. }
  14504. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14505. {
  14506. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14507. {
  14508. check_ascii = value[0];
  14509. if( (check_ascii < 48) || (check_ascii > 57) )
  14510. {
  14511. isSuccess = ConfigurationStatus_Rejected;
  14512. }
  14513. else
  14514. {
  14515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14516. isSuccess = ConfigurationStatus_Accepted;
  14517. }
  14518. }
  14519. else
  14520. {
  14521. isSuccess = ConfigurationStatus_Rejected;
  14522. }
  14523. }
  14524. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14525. {
  14526. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14527. {
  14528. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14529. isSuccess = ConfigurationStatus_Accepted;
  14530. }
  14531. else
  14532. {
  14533. isSuccess = ConfigurationStatus_Rejected;
  14534. }
  14535. }
  14536. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14537. {
  14538. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14539. {
  14540. check_ascii = value[0];
  14541. if( (check_ascii < 48) || (check_ascii > 57) )
  14542. {
  14543. isSuccess = ConfigurationStatus_Rejected;
  14544. }
  14545. else
  14546. {
  14547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14548. isSuccess = ConfigurationStatus_Accepted;
  14549. }
  14550. }
  14551. else
  14552. {
  14553. isSuccess = ConfigurationStatus_Rejected;
  14554. }
  14555. }
  14556. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14557. {
  14558. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14559. {
  14560. check_ascii = value[0];
  14561. if( (check_ascii < 48) || (check_ascii > 57) )
  14562. {
  14563. isSuccess = ConfigurationStatus_Rejected;
  14564. }
  14565. else
  14566. {
  14567. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14569. TransactionMessageAttemptsValue = atoi(value);
  14570. isSuccess = ConfigurationStatus_Accepted;
  14571. }
  14572. }
  14573. else
  14574. {
  14575. isSuccess = ConfigurationStatus_Rejected;
  14576. }
  14577. }
  14578. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14579. {
  14580. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14581. {
  14582. check_ascii = value[0];
  14583. if( (check_ascii < 48) || (check_ascii > 57) )
  14584. {
  14585. isSuccess = ConfigurationStatus_Rejected;
  14586. }
  14587. else
  14588. {
  14589. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14591. TransactionMessageRetryIntervalValue = atoi(value);
  14592. isSuccess = ConfigurationStatus_Accepted;
  14593. }
  14594. }
  14595. else
  14596. {
  14597. isSuccess = ConfigurationStatus_Rejected;
  14598. }
  14599. }
  14600. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14601. {
  14602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14603. {
  14604. strcpy(str, (const char*)value);
  14605. for(int i = 0; str[i]; i++)
  14606. {
  14607. str[i] = tolower(str[i]);
  14608. }
  14609. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14610. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14611. isSuccess = ConfigurationStatus_Accepted;
  14612. }
  14613. else
  14614. {
  14615. isSuccess = ConfigurationStatus_Rejected;
  14616. }
  14617. }
  14618. if(strcmp(key, "WebSocketPingInterval") == 0)
  14619. {
  14620. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14621. {
  14622. check_ascii = value[0];
  14623. if( (check_ascii < 48) || (check_ascii > 57) )
  14624. {
  14625. isSuccess = ConfigurationStatus_Rejected;
  14626. }
  14627. else
  14628. {
  14629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14630. isSuccess = ConfigurationStatus_Accepted;
  14631. }
  14632. }
  14633. else
  14634. {
  14635. isSuccess = ConfigurationStatus_Rejected;
  14636. }
  14637. }
  14638. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14639. {
  14640. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14641. {
  14642. strcpy(str, (const char*)value);
  14643. for(int i = 0; str[i]; i++)
  14644. {
  14645. str[i] = tolower(str[i]);
  14646. }
  14647. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14648. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14649. isSuccess = ConfigurationStatus_Accepted;
  14650. }
  14651. else
  14652. {
  14653. isSuccess = ConfigurationStatus_Rejected;
  14654. }
  14655. }
  14656. if(strcmp(key, "AuthorizationKey") == 0)
  14657. {
  14658. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14659. {
  14660. strcpy(str, (const char*)value);
  14661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14662. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14663. isSuccess = ConfigurationStatus_Accepted;
  14664. }
  14665. else
  14666. {
  14667. isSuccess = ConfigurationStatus_Rejected;
  14668. }
  14669. }
  14670. if(strcmp(key, "SecurityProfile") == 0)
  14671. {
  14672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14673. {
  14674. check_ascii = value[0];
  14675. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14676. {
  14677. isSuccess = ConfigurationStatus_Rejected;
  14678. }
  14679. else if(check_ascii == 0x33)
  14680. {
  14681. isSuccess = NotSupported;
  14682. }
  14683. else
  14684. {
  14685. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14686. {
  14687. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14688. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14689. isSuccess = ConfigurationStatus_Accepted;
  14690. }
  14691. else
  14692. isSuccess = ConfigurationStatus_Rejected;
  14693. }
  14694. }
  14695. else
  14696. {
  14697. isSuccess = ConfigurationStatus_Rejected;
  14698. }
  14699. }
  14700. if(strcmp(key, "DefaultPrice") == 0)
  14701. {
  14702. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14703. {
  14704. strcpy(str, (const char*)value);
  14705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14706. isSuccess = ConfigurationStatus_Accepted;
  14707. }
  14708. else
  14709. {
  14710. isSuccess = ConfigurationStatus_Rejected;
  14711. }
  14712. }
  14713. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14714. {
  14715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14716. {
  14717. strcpy(str, (const char*)value);
  14718. for(int i = 0; str[i]; i++)
  14719. {
  14720. str[i] = tolower(str[i]);
  14721. }
  14722. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14724. isSuccess = ConfigurationStatus_Accepted;
  14725. }
  14726. else
  14727. {
  14728. isSuccess = ConfigurationStatus_Rejected;
  14729. }
  14730. }
  14731. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14732. {
  14733. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14734. {
  14735. strcpy(str, (const char*)value);
  14736. for(int i = 0; str[i]; i++)
  14737. {
  14738. str[i] = tolower(str[i]);
  14739. }
  14740. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14741. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14742. isSuccess = ConfigurationStatus_Accepted;
  14743. }
  14744. else
  14745. {
  14746. isSuccess = ConfigurationStatus_Rejected;
  14747. }
  14748. }
  14749. #if 0
  14750. //For OCPP Test Case
  14751. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14752. {
  14753. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14754. {
  14755. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14756. isSuccess = ConfigurationStatus_Accepted;
  14757. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14758. }
  14759. else
  14760. {
  14761. isSuccess = ConfigurationStatus_Rejected;
  14762. }
  14763. }
  14764. #endif
  14765. #if 1
  14766. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14767. {
  14768. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14769. {
  14770. strcpy(str, (const char*)value);
  14771. for(int i = 0; str[i]; i++)
  14772. {
  14773. str[i] = tolower(str[i]);
  14774. }
  14775. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14776. isSuccess = ConfigurationStatus_Accepted;
  14777. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14778. }
  14779. else
  14780. {
  14781. isSuccess = ConfigurationStatus_Rejected;
  14782. }
  14783. }
  14784. #endif
  14785. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14786. {
  14787. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14788. {
  14789. check_ascii = value[0];
  14790. if( (check_ascii < 48) || (check_ascii > 57) )
  14791. {
  14792. isSuccess = ConfigurationStatus_Rejected;
  14793. }
  14794. else
  14795. {
  14796. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14797. isSuccess = ConfigurationStatus_Accepted;
  14798. }
  14799. }
  14800. else
  14801. {
  14802. isSuccess = ConfigurationStatus_Rejected;
  14803. }
  14804. }
  14805. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14806. {
  14807. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14808. {
  14809. check_ascii = value[0];
  14810. if( (check_ascii < 48) || (check_ascii > 57) )
  14811. {
  14812. isSuccess = ConfigurationStatus_Rejected;
  14813. }
  14814. else
  14815. {
  14816. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14817. isSuccess = ConfigurationStatus_Accepted;
  14818. }
  14819. }
  14820. else
  14821. {
  14822. isSuccess = ConfigurationStatus_Rejected;
  14823. }
  14824. }
  14825. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14826. {
  14827. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14828. {
  14829. strcpy(str, (const char*)value);
  14830. for(int i = 0; str[i]; i++)
  14831. {
  14832. str[i] = tolower(str[i]);
  14833. }
  14834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14835. isSuccess = ConfigurationStatus_Accepted;
  14836. }
  14837. else
  14838. {
  14839. isSuccess = ConfigurationStatus_Rejected;
  14840. }
  14841. }
  14842. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14843. {
  14844. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14845. {
  14846. check_ascii = value[0];
  14847. if( (check_ascii < 48) || (check_ascii > 57) )
  14848. {
  14849. isSuccess = ConfigurationStatus_Rejected;
  14850. }
  14851. else
  14852. {
  14853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14854. isSuccess = ConfigurationStatus_Accepted;
  14855. }
  14856. }
  14857. else
  14858. {
  14859. isSuccess = ConfigurationStatus_Rejected;
  14860. }
  14861. }
  14862. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14863. {
  14864. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14865. {
  14866. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14867. isSuccess = ConfigurationStatus_Accepted;
  14868. }
  14869. else
  14870. {
  14871. isSuccess = ConfigurationStatus_Rejected;
  14872. }
  14873. }
  14874. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14875. {
  14876. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14877. {
  14878. check_ascii = value[0];
  14879. if( (check_ascii < 48) || (check_ascii > 57) )
  14880. {
  14881. isSuccess = ConfigurationStatus_Rejected;
  14882. }
  14883. else
  14884. {
  14885. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14886. isSuccess = ConfigurationStatus_Accepted;
  14887. }
  14888. }
  14889. else
  14890. {
  14891. isSuccess = ConfigurationStatus_Rejected;
  14892. }
  14893. }
  14894. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14895. {
  14896. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14897. {
  14898. strcpy(str, (const char*)value);
  14899. for(int i = 0; str[i]; i++)
  14900. {
  14901. str[i] = tolower(str[i]);
  14902. }
  14903. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14904. isSuccess = ConfigurationStatus_Accepted;
  14905. }
  14906. else
  14907. {
  14908. isSuccess = ConfigurationStatus_Rejected;
  14909. }
  14910. }
  14911. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14912. {
  14913. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14914. {
  14915. check_ascii = value[0];
  14916. if( (check_ascii < 48) || (check_ascii > 57) )
  14917. {
  14918. isSuccess = ConfigurationStatus_Rejected;
  14919. }
  14920. else
  14921. {
  14922. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14923. isSuccess = ConfigurationStatus_Accepted;
  14924. }
  14925. }
  14926. else
  14927. {
  14928. isSuccess = ConfigurationStatus_Rejected;
  14929. }
  14930. }
  14931. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14932. return isSuccess;
  14933. }
  14934. int TransactionMessageAttemptsGet(void)
  14935. {
  14936. return TransactionMessageAttemptsValue;
  14937. }
  14938. int FirstHeartBeatResponse(void)
  14939. {
  14940. return FirstHeartBeat;
  14941. }
  14942. int TransactionMessageRetryIntervalGet(void)
  14943. {
  14944. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14945. }
  14946. int ReadHttpStatus(int sock)
  14947. {
  14948. //char c;
  14949. char buff[1024]="",*ptr=buff+1;
  14950. int bytes_received, status;
  14951. DEBUG_INFO("Begin Response ..\n");
  14952. while((bytes_received = recv(sock, ptr, 1, 0))){
  14953. if(bytes_received==-1){
  14954. perror("ReadHttpStatus");
  14955. exit(1);
  14956. }
  14957. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14958. ptr++;
  14959. }
  14960. *ptr=0;
  14961. ptr=buff+1;
  14962. sscanf(ptr,"%*s %d ", &status);
  14963. DEBUG_INFO("%s\n",ptr);
  14964. DEBUG_INFO("status=%d\n",status);
  14965. DEBUG_INFO("End Response ..\n");
  14966. return (bytes_received>0)?status:0;
  14967. }
  14968. //the only filed that it parsed is 'Content-Length'
  14969. int ParseHeader(int sock)
  14970. {
  14971. //char c;
  14972. char buff[1024]="",*ptr=buff+4;
  14973. int bytes_received;
  14974. DEBUG_INFO("Begin HEADER ..\n");
  14975. while((bytes_received = recv(sock, ptr, 1, 0))){
  14976. if(bytes_received==-1){
  14977. perror("Parse Header");
  14978. exit(1);
  14979. }
  14980. if(
  14981. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14982. (ptr[-1]=='\r') && (*ptr=='\n' )
  14983. ) break;
  14984. ptr++;
  14985. }
  14986. *ptr=0;
  14987. ptr=buff+4;
  14988. //printf("%s",ptr);
  14989. if(bytes_received){
  14990. ptr=strstr(ptr,"Content-Length:");
  14991. if(ptr){
  14992. sscanf(ptr,"%*s %d",&bytes_received);
  14993. }else
  14994. bytes_received=-1; //unknown size
  14995. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14996. }
  14997. DEBUG_INFO("End HEADER ..\n");
  14998. return bytes_received ;
  14999. }
  15000. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15001. {
  15002. int result = TRUE;
  15003. char rmFileCmd[100]={0};
  15004. char FilePath[100]={0};
  15005. char ftpbuf[200];
  15006. int systemresult;
  15007. sprintf(FilePath,"/mnt/%s",filename);
  15008. system("ping 8.8.8.8 &");
  15009. if((access(FilePath,F_OK))!=-1)
  15010. {
  15011. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15012. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15013. system(rmFileCmd);
  15014. }
  15015. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15016. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15017. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15018. systemresult = system(ftpbuf);
  15019. if(systemresult != 0)
  15020. {
  15021. DEBUG_INFO("http DownLoad error!\n");
  15022. result = FALSE;
  15023. }
  15024. system("pkill ping");
  15025. return result;
  15026. }
  15027. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15028. {
  15029. int result = TRUE;
  15030. char rmFileCmd[100]={0};
  15031. char FilePath[100]={0};
  15032. char ftpbuf[200];
  15033. int systemresult;
  15034. sprintf(FilePath,"/mnt/%s",filename);
  15035. system("ping 8.8.8.8 &");
  15036. if((access(FilePath,F_OK))!=-1)
  15037. {
  15038. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15039. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15040. system(rmFileCmd);
  15041. }
  15042. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15043. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15044. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15045. systemresult = system(ftpbuf);
  15046. if(systemresult != 0)
  15047. {
  15048. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15049. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15050. systemresult = system(ftpbuf);
  15051. if(systemresult != 0)
  15052. {
  15053. DEBUG_WARN("wget error!\n");
  15054. result = FALSE;
  15055. }
  15056. }
  15057. system("pkill ping");
  15058. return result;
  15059. }
  15060. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15061. {
  15062. char rmFileCmd[100]={0};
  15063. char FilePath[100]={0};
  15064. char buf[512];
  15065. int systemresult = 0;
  15066. //DEBUG_INFO("filename=%s\n",filename);
  15067. //DEBUG_INFO("url=%s\n",url);
  15068. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15069. if((access(FilePath,F_OK))!=-1)
  15070. {
  15071. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15072. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15073. system(rmFileCmd);
  15074. }
  15075. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15076. if(fp == NULL)
  15077. {
  15078. DEBUG_INFO("log is NULL\n");
  15079. return FALSE;
  15080. }
  15081. else
  15082. {
  15083. fprintf(fp, "%s\n", url);
  15084. fprintf(fp, "%s\n", filename);
  15085. fclose(fp);
  15086. }
  15087. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15088. if(phpFP == NULL)
  15089. {
  15090. DEBUG_INFO("PHP upload fail.\n");
  15091. return FALSE;
  15092. }
  15093. else
  15094. {
  15095. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15096. {
  15097. if(strstr(buf, "result") != NULL)
  15098. {
  15099. sscanf(buf, "result: %d", &systemresult);
  15100. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15101. }
  15102. }
  15103. pclose(phpFP);
  15104. }
  15105. if(systemresult != 1)
  15106. {
  15107. DEBUG_INFO("HTTP upload error!\n");
  15108. return FALSE;
  15109. }
  15110. return TRUE;
  15111. }
  15112. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15113. {
  15114. struct hostent* server;
  15115. char *IPbuffer;
  15116. char ftpbuf[200];
  15117. int systemresult;
  15118. // To retrieve host information
  15119. server = gethostbyname(location);
  15120. // To convert an Internet network
  15121. // address into ASCII string
  15122. IPbuffer = inet_ntoa(*((struct in_addr*)
  15123. server->h_addr_list[0]));
  15124. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15125. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15126. /* format : ftpput -u username -p passwd IP target source*/
  15127. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15128. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15129. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15130. systemresult = system(ftpbuf);
  15131. DEBUG_INFO("systemresult=%d\n",systemresult);
  15132. if(systemresult != 0)
  15133. {
  15134. DEBUG_INFO("ftpput error!\n");
  15135. return FALSE;
  15136. }
  15137. return TRUE;
  15138. }
  15139. int GetOcppServerURL()
  15140. {
  15141. int result = FALSE;
  15142. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15143. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15144. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15145. struct yuarel url;
  15146. char urlStr[512];
  15147. // OCPPPH only
  15148. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  15149. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  15150. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  15151. {
  15152. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  15153. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15154. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15155. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  15156. if(yuarel_parse(&url, urlStr) != -1)
  15157. {
  15158. sprintf(OcppProtocol, "%s", url.scheme);
  15159. sprintf(OcppHost, "%s", url.host);
  15160. if(url.path == NULL)
  15161. OcppTempPath[0] = '\0';
  15162. else
  15163. sprintf(OcppTempPath, "%s", url.path);
  15164. if(url.port == 0)
  15165. {
  15166. if(strcmp(OcppProtocol, "wss") == 0)
  15167. OcppPort = 443;
  15168. else
  15169. OcppPort = 80;
  15170. }
  15171. else
  15172. OcppPort = url.port;
  15173. result = TRUE;
  15174. }
  15175. }
  15176. else
  15177. {
  15178. strcpy(OcppHost,"");
  15179. }
  15180. return result;
  15181. }
  15182. int GetOcppPath()
  15183. {
  15184. int result = FALSE;
  15185. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  15186. {
  15187. if(OcppTempPath == NULL)
  15188. {
  15189. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  15190. }
  15191. else
  15192. {
  15193. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  15194. }
  15195. result = TRUE;
  15196. goto End;
  15197. }
  15198. else
  15199. {
  15200. strcpy(OcppPath,"");
  15201. }
  15202. End:
  15203. return result;
  15204. }
  15205. int GetOcppPort()
  15206. {
  15207. return OcppPort;
  15208. }
  15209. int GetOcppConnStatus(void)
  15210. {
  15211. return ShmOCPP16DataPH->OcppConnStatus;
  15212. }
  15213. void SetOcppConnStatus(uint8_t status)
  15214. {
  15215. ShmOCPP16DataPH->OcppConnStatus = status;
  15216. }
  15217. int GetHeartBeatWithNOResponse(void)
  15218. {
  15219. return HeartBeatWithNOResponse;
  15220. }
  15221. void SetHeartBeatWithNOResponse(void)
  15222. {
  15223. HeartBeatWithNOResponse = 0;
  15224. }
  15225. void GetStartTransactionIdTag(int gun_index)
  15226. {
  15227. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15228. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15229. }
  15230. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15231. {
  15232. char ch;
  15233. FILE *fptr1;
  15234. int temptransactionId;
  15235. char str[100]={0};
  15236. temptransactionId = 0;
  15237. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15238. {
  15239. DEBUG_INFO("IdTag is empty.\n");
  15240. return temptransactionId;
  15241. }
  15242. /*------ Read the file ----------------*/
  15243. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  15244. if (!fptr1)
  15245. {
  15246. DEBUG_INFO("QueueTransactionId file open error.\n");
  15247. //printf(" File not found or unable to open the input file!!\n");
  15248. return temptransactionId;
  15249. }
  15250. ch=fgetc(fptr1);
  15251. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  15252. rewind(fptr1);
  15253. if(ch!=EOF)
  15254. {
  15255. // printf("%c",ch);
  15256. while (fgets(str, 100, fptr1) != NULL)
  15257. {
  15258. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15259. if(str[0]=='\0')
  15260. {
  15261. break;
  15262. }
  15263. char *revbuf[8] = {0}; // Variable store string split
  15264. int num = 0;// Quantity after string split
  15265. DEBUG_INFO("Transaction queue data= %s\n", str);
  15266. splitstring(str,",",revbuf,&num); // String split
  15267. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15268. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15269. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15270. DEBUG_INFO("------------------------------\n");
  15271. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15272. {
  15273. if(isStopTransaction)
  15274. {
  15275. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15276. {
  15277. temptransactionId = atoi(revbuf[2]);
  15278. //break;
  15279. }
  15280. }
  15281. else
  15282. {
  15283. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15284. {
  15285. temptransactionId = atoi(revbuf[2]);
  15286. //break;
  15287. }
  15288. }
  15289. }
  15290. }
  15291. }
  15292. else
  15293. DEBUG_INFO("EOF\n");
  15294. fclose(fptr1);
  15295. /*------- End of reading ---------------*/
  15296. return temptransactionId;
  15297. }
  15298. void SetTransactionIdZero(int transactionId)
  15299. {
  15300. char ch;
  15301. FILE *fptr1, *fptr2;
  15302. int temptransactionId = 0;
  15303. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15304. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15305. if (!fptr1)
  15306. {
  15307. //printf(" File not found or unable to open the input file!!\n");
  15308. return ;
  15309. }
  15310. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15311. if (!fptr2)
  15312. {
  15313. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15314. fclose(fptr1);
  15315. return ;
  15316. }
  15317. ch=fgetc(fptr1);
  15318. rewind(fptr1);
  15319. if(ch!=EOF)
  15320. {
  15321. // copy all contents to the temporary file except the specific line
  15322. while (fgets(str, 100, fptr1) != NULL)
  15323. {
  15324. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15325. if(str[0]=='\0')
  15326. {
  15327. break;
  15328. }
  15329. char *revbuf[8] = {0};
  15330. int num = 0;
  15331. strcpy(strtemp, str);
  15332. splitstring(str,",",revbuf,&num);
  15333. if(revbuf[2][0] != '\0')
  15334. {
  15335. temptransactionId = atoi(revbuf[2]);
  15336. if(transactionId != temptransactionId)
  15337. {
  15338. fprintf(fptr2, "%s\n", strtemp);
  15339. }
  15340. }
  15341. }
  15342. }
  15343. fclose(fptr1);
  15344. fclose(fptr2);
  15345. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15346. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15347. /*------ Read the file ----------------*/
  15348. }
  15349. int InternetDisconnect(void)
  15350. {
  15351. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15352. }
  15353. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15354. void storeTempStopTransaction(int gun_index)
  15355. {
  15356. char guid[37]={0};
  15357. int tempIndex = 0;
  15358. char TempStopTransaction[256];
  15359. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15360. DEBUG_INFO("storeTempStopTransaction...\n");
  15361. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15362. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15363. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15364. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15365. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15366. {
  15367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15368. {
  15369. tempIndex = ((gun_index==2) ? 1: 0);
  15370. }
  15371. else
  15372. {
  15373. tempIndex = gun_index;
  15374. }
  15375. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15376. {
  15377. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15378. {
  15379. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15380. }
  15381. }// END OF CHAdeMO_QUANTITY
  15382. }
  15383. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15384. {
  15385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15386. {
  15387. tempIndex = ((gun_index==2) ? 1: 0);
  15388. }
  15389. else
  15390. {
  15391. tempIndex = gun_index;
  15392. }
  15393. for (int index = 0; index < CCS_QUANTITY; index++)
  15394. {
  15395. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15396. {
  15397. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15398. }
  15399. }// END OF CCS_QUANTITY
  15400. }
  15401. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15402. {
  15403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15404. {
  15405. tempIndex = ((gun_index==2) ? 1: 0);
  15406. }
  15407. else
  15408. {
  15409. tempIndex = gun_index;
  15410. }
  15411. for (int index = 0; index < GB_QUANTITY; index++)
  15412. {
  15413. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15414. {
  15415. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15416. }
  15417. }// END OF GB_QUANTITY
  15418. }
  15419. else if(gunType[gun_index] == GUN_TYPE_DO)
  15420. {
  15421. tempIndex = gun_index;
  15422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15423. {
  15424. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15425. {
  15426. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15427. }
  15428. }
  15429. }
  15430. else
  15431. {
  15432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15433. {
  15434. tempIndex = 2;
  15435. }
  15436. else
  15437. {
  15438. tempIndex = gun_index;
  15439. }
  15440. for (int index = 0; index < AC_QUANTITY; index++)
  15441. {
  15442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15443. {
  15444. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15445. }
  15446. }// END OF AC_QUANTITY
  15447. }
  15448. //Stop Transaction Time
  15449. struct timeval tmnow;
  15450. struct tm *tm;
  15451. char buf[28];//, usec_buf[6];
  15452. gettimeofday(&tmnow, NULL);
  15453. time_t t;
  15454. t = time(NULL);
  15455. /*UTC time and date*/
  15456. tm = gmtime(&t);
  15457. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15458. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15459. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15461. random_uuid(guid);
  15462. /***********************************transactionData******************************************************/
  15463. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15465. //=================================
  15466. //1. Transaction_Begin
  15467. //=================================
  15468. //============================== Energy.Active.Import.Interval ===========================================
  15469. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15470. {
  15471. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15472. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15473. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15474. 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*/]);
  15475. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15476. 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))
  15477. {
  15478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15479. }
  15480. else
  15481. {
  15482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15483. }
  15484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15486. }
  15487. //=================================
  15488. //2. Transaction_End
  15489. //=================================
  15490. //2.1====================================== Current.Import L1 ==============================================
  15491. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15492. {
  15493. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15494. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15495. {
  15496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15497. {
  15498. tempIndex = ((gun_index==2) ? 1: 0);
  15499. }
  15500. else
  15501. {
  15502. tempIndex = gun_index;
  15503. }
  15504. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15505. {
  15506. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15507. {
  15508. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15509. }
  15510. }// End of for CHAdeMO_QUANTITY
  15511. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15512. }
  15513. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15514. {
  15515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15516. {
  15517. tempIndex = ((gun_index==2) ? 1: 0);
  15518. }
  15519. else
  15520. {
  15521. tempIndex = gun_index;
  15522. }
  15523. for (int index = 0; index < CCS_QUANTITY; index++)
  15524. {
  15525. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15526. {
  15527. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15528. }
  15529. }// End of for CCS_QUANTITY
  15530. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15531. }
  15532. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15533. {
  15534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15535. {
  15536. tempIndex = ((gun_index==2) ? 1: 0);
  15537. }
  15538. else
  15539. {
  15540. tempIndex = gun_index;
  15541. }
  15542. for (int index = 0; index < GB_QUANTITY; index++)
  15543. {
  15544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15545. {
  15546. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15547. }
  15548. }// End of for GB_QUANTITY
  15549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15550. }
  15551. else if(gunType[gun_index] == GUN_TYPE_DO)
  15552. {
  15553. tempIndex = gun_index;
  15554. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15555. {
  15556. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15557. {
  15558. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15559. }
  15560. }
  15561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15562. }
  15563. else
  15564. {
  15565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15566. {
  15567. tempIndex = 2;
  15568. }
  15569. else
  15570. {
  15571. tempIndex = gun_index;
  15572. }
  15573. for (int index = 0; index < AC_QUANTITY; index++)
  15574. {
  15575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15576. {
  15577. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15578. }
  15579. }// End of for AC_QUANTITY
  15580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15581. }
  15582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15585. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15587. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15588. }
  15589. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15590. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15591. {
  15592. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15593. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15594. {
  15595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15596. {
  15597. tempIndex = ((gun_index==2) ? 1: 0);
  15598. }
  15599. else
  15600. {
  15601. tempIndex = gun_index;
  15602. }
  15603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15604. {
  15605. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15606. {
  15607. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15608. }
  15609. }// END OF CHAdeMO_QUANTITY
  15610. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15611. }
  15612. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15613. {
  15614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15615. {
  15616. tempIndex = ((gun_index==2) ? 1: 0);
  15617. }
  15618. else
  15619. {
  15620. tempIndex = gun_index;
  15621. }
  15622. for (int index = 0; index < CCS_QUANTITY; index++)
  15623. {
  15624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15625. {
  15626. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15627. }
  15628. }// END OF CCS_QUANTITY
  15629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15630. }
  15631. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15632. {
  15633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15634. {
  15635. tempIndex = ((gun_index==2) ? 1: 0);
  15636. }
  15637. else
  15638. {
  15639. tempIndex = gun_index;
  15640. }
  15641. for (int index = 0; index < GB_QUANTITY; index++)
  15642. {
  15643. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15644. {
  15645. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15646. }
  15647. }// END OF GB_QUANTITY
  15648. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15649. }
  15650. else if(gunType[gun_index] == GUN_TYPE_DO)
  15651. {
  15652. tempIndex = gun_index;
  15653. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15654. {
  15655. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15656. {
  15657. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15658. }
  15659. }
  15660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15661. }
  15662. else
  15663. {
  15664. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15665. {
  15666. tempIndex = 2;
  15667. }
  15668. else
  15669. {
  15670. tempIndex = gun_index;
  15671. }
  15672. for (int index = 0; index < AC_QUANTITY; index++)
  15673. {
  15674. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15675. {
  15676. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15677. }
  15678. }// END OF AC_QUANTITY
  15679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15680. }
  15681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15684. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15687. }
  15688. //2.3====================================== Power.Active.Import =========================================
  15689. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15690. {
  15691. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15692. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15693. {
  15694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15695. {
  15696. tempIndex = ((gun_index==2) ? 1: 0);
  15697. }
  15698. else
  15699. {
  15700. tempIndex = gun_index;
  15701. }
  15702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15703. {
  15704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15705. {
  15706. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15707. }
  15708. } // End for CHAdeMO_QUANTITY
  15709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15710. }
  15711. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15712. {
  15713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15714. {
  15715. tempIndex = ((gun_index==2) ? 1: 0);
  15716. }
  15717. else
  15718. {
  15719. tempIndex = gun_index;
  15720. }
  15721. for (int index = 0; index < CCS_QUANTITY; index++)
  15722. {
  15723. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15724. {
  15725. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15726. }
  15727. } // END for CCS_QUANTITY
  15728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15729. }
  15730. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15731. {
  15732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15733. {
  15734. tempIndex = ((gun_index==2) ? 1: 0);
  15735. }
  15736. else
  15737. {
  15738. tempIndex = gun_index;
  15739. }
  15740. for (int index = 0; index < GB_QUANTITY; index++)
  15741. {
  15742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15743. {
  15744. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15745. }
  15746. }// END for GB_QUANTITY
  15747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15748. }
  15749. else if(gunType[gun_index] == GUN_TYPE_DO)
  15750. {
  15751. tempIndex = gun_index;
  15752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15753. {
  15754. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15755. {
  15756. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15757. }
  15758. }
  15759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15760. }
  15761. else
  15762. {
  15763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15764. {
  15765. tempIndex = 2;
  15766. }
  15767. else
  15768. {
  15769. tempIndex = gun_index;
  15770. }
  15771. for (int index = 0; index < AC_QUANTITY; index++)
  15772. {
  15773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15774. {
  15775. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15776. }
  15777. } // END for AC_QUANTITY
  15778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15779. }
  15780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15783. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15786. }
  15787. //2.4====================================== Voltage L1 ====================================================
  15788. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15789. {
  15790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15792. {
  15793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15794. {
  15795. tempIndex = ((gun_index==2) ? 1: 0);
  15796. }
  15797. else
  15798. {
  15799. tempIndex = gun_index;
  15800. }
  15801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15802. {
  15803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15804. {
  15805. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15806. }
  15807. } // END OF FOR CHAdeMO_QUANTITY
  15808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15809. }
  15810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15811. {
  15812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15813. {
  15814. tempIndex = ((gun_index==2) ? 1: 0);
  15815. }
  15816. else
  15817. {
  15818. tempIndex = gun_index;
  15819. }
  15820. for (int index = 0; index < CCS_QUANTITY; index++)
  15821. {
  15822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15823. {
  15824. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15825. }
  15826. } // END OF FOR CCS_QUANTITY
  15827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15828. }
  15829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15830. {
  15831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15832. {
  15833. tempIndex = ((gun_index==2) ? 1: 0);
  15834. }
  15835. else
  15836. {
  15837. tempIndex = gun_index;
  15838. }
  15839. for (int index = 0; index < GB_QUANTITY; index++)
  15840. {
  15841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15842. {
  15843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15844. }
  15845. } // END OF FOR GB_QUANTITY
  15846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15847. }
  15848. else if(gunType[gun_index] == GUN_TYPE_DO)
  15849. {
  15850. tempIndex = gun_index;
  15851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15852. {
  15853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15854. {
  15855. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15856. }
  15857. }
  15858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15859. }
  15860. else
  15861. {
  15862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15863. {
  15864. tempIndex = 2;
  15865. }
  15866. else
  15867. {
  15868. tempIndex = gun_index;
  15869. }
  15870. for (int index = 0; index < AC_QUANTITY; index++)
  15871. {
  15872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15873. {
  15874. 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
  15875. }
  15876. } // END OF FOR AC_QUANTITY
  15877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15878. }
  15879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15882. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15883. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15884. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15885. }
  15886. //2.5============================================== End SoC =========================================================
  15887. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15888. {
  15889. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15890. 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))
  15891. {
  15892. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15893. {
  15894. tempIndex = ((gun_index==2) ? 1: 0);
  15895. }
  15896. else
  15897. {
  15898. tempIndex = gun_index;
  15899. }
  15900. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15901. {
  15902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15903. {
  15904. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15905. {
  15906. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15907. }
  15908. }
  15909. }
  15910. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15911. {
  15912. for (int index = 0; index < CCS_QUANTITY; index++)
  15913. {
  15914. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15915. {
  15916. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15917. }
  15918. }
  15919. }
  15920. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15921. {
  15922. for (int index = 0; index < GB_QUANTITY; index++)
  15923. {
  15924. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15925. {
  15926. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15927. }
  15928. }
  15929. }
  15930. else if(gunType[gun_index] == GUN_TYPE_DO)
  15931. {
  15932. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15933. {
  15934. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15935. {
  15936. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15937. }
  15938. }
  15939. }
  15940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15946. } // END FOR DC CASE
  15947. }
  15948. //2.6====================================== Current.Import L2 ==============================================
  15949. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15950. {
  15951. // AC 3 phase L2 current
  15952. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15953. {
  15954. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15955. {
  15956. tempIndex = 2;
  15957. }
  15958. else
  15959. {
  15960. tempIndex = gun_index;
  15961. }
  15962. for (int index = 0; index < AC_QUANTITY; index++)
  15963. {
  15964. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15965. {
  15966. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15967. }
  15968. }// End of for AC_QUANTITY
  15969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15970. }
  15971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15976. }
  15977. //2.7====================================== Current.Import L3 ==============================================
  15978. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15979. {
  15980. // AC 3 phase L3 current
  15981. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15982. {
  15983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15984. {
  15985. tempIndex = 2;
  15986. }
  15987. else
  15988. {
  15989. tempIndex = gun_index;
  15990. }
  15991. for (int index = 0; index < AC_QUANTITY; index++)
  15992. {
  15993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15994. {
  15995. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15996. }
  15997. }// End of for AC_QUANTITY
  15998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15999. }
  16000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16005. }
  16006. //2.9====================================== Voltage L2 ====================================================
  16007. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16008. {
  16009. // AC 3 phase L2 volatge
  16010. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16011. {
  16012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16013. {
  16014. tempIndex = 2;
  16015. }
  16016. else
  16017. {
  16018. tempIndex = gun_index;
  16019. }
  16020. for (int index = 0; index < AC_QUANTITY; index++)
  16021. {
  16022. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16023. {
  16024. 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
  16025. }
  16026. } // END OF FOR AC_QUANTITY
  16027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16028. }
  16029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16033. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16034. }
  16035. //2.10====================================== Voltage L3 ====================================================
  16036. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16037. {
  16038. // AC 3 phase L3 volatge
  16039. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16040. {
  16041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16042. {
  16043. tempIndex = 2;
  16044. }
  16045. else
  16046. {
  16047. tempIndex = gun_index;
  16048. }
  16049. for (int index = 0; index < AC_QUANTITY; index++)
  16050. {
  16051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16052. {
  16053. 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
  16054. }
  16055. } // END OF FOR AC_QUANTITY
  16056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16057. }
  16058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16063. }
  16064. //====================== Start SoC ================================
  16065. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16066. {
  16067. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16068. 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))
  16069. {
  16070. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16071. {
  16072. tempIndex = ((gun_index==2) ? 1: 0);
  16073. }
  16074. else
  16075. {
  16076. tempIndex = gun_index;
  16077. }
  16078. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16079. {
  16080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16081. {
  16082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16083. {
  16084. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16085. }
  16086. }
  16087. }
  16088. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16089. {
  16090. for (int index = 0; index < CCS_QUANTITY; index++)
  16091. {
  16092. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16093. {
  16094. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16095. }
  16096. }
  16097. }
  16098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16099. {
  16100. for (int index = 0; index < GB_QUANTITY; index++)
  16101. {
  16102. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16103. {
  16104. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16105. }
  16106. }
  16107. }
  16108. else if(gunType[gun_index] == GUN_TYPE_DO)
  16109. {
  16110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16111. {
  16112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16113. {
  16114. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16115. }
  16116. }
  16117. }
  16118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16123. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16124. } // END FOR DC CASE
  16125. }
  16126. //======================================== Message create ==============================================
  16127. json_object *StopTransaction = json_object_new_object();
  16128. json_object *transactionDatas = json_object_new_array();
  16129. json_object *sampledValues = json_object_new_array();
  16130. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  16131. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16132. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16133. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16134. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16135. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16136. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16137. {
  16138. json_object *transactionData = json_object_new_object();
  16139. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16140. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16141. {
  16142. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16143. {
  16144. json_object *sampledValue = json_object_new_object();
  16145. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16146. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16147. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16148. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16149. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16150. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16151. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16152. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16153. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16154. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16155. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16156. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16157. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16158. json_object_array_add(sampledValues, sampledValue);
  16159. }
  16160. }
  16161. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16162. json_object_array_add(transactionDatas, transactionData);
  16163. }
  16164. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16165. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16166. ,MESSAGE_TYPE_CALL
  16167. ,guid
  16168. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16169. json_object_put(StopTransaction);
  16170. // Check File "TempStopTransaction" Exist
  16171. if((access(TempStopTransaction,F_OK))!=-1)
  16172. {
  16173. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16174. fclose(fopen(TempStopTransaction, "w"));
  16175. }
  16176. else
  16177. {
  16178. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16179. FILE *log = fopen(TempStopTransaction, "w+");
  16180. if(log == NULL)
  16181. {
  16182. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16183. return ;
  16184. }
  16185. else
  16186. {
  16187. fclose(log);
  16188. }
  16189. }
  16190. //Add TempStopTransaction | Update TempStopTransaction
  16191. // open file for writing
  16192. FILE *outfile;
  16193. outfile = fopen (TempStopTransaction, "a");
  16194. //DEBUG_INFO("data = %s\n", queuedata);
  16195. fputs(queuedata, outfile);
  16196. fputs("\n", outfile);
  16197. fclose (outfile);
  16198. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16199. }
  16200. void checkTempStopTransaction(int gun_index)
  16201. {
  16202. FILE *fptr1;
  16203. char ch;
  16204. char str[QUEUE_MESSAGE_LENGTH]={0};
  16205. char guid[37]={0};
  16206. char tempdata[65]={0};
  16207. char connectorStr[2]={0};
  16208. char TempStopTransaction[256];
  16209. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16210. fptr1 = fopen(TempStopTransaction, "r");
  16211. //TempStopTransaction格式: 槍號,StopTransaction封包
  16212. if (!fptr1)
  16213. {
  16214. //printf(" File not found or unable to open the input file!!\n");
  16215. return ;
  16216. }
  16217. ch=fgetc(fptr1);
  16218. //printf(" Now the content of the file %s is : \n",fname);
  16219. rewind(fptr1);
  16220. if(ch!=EOF)
  16221. {
  16222. // copy all contents to the temporary file except the specific line
  16223. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16224. {
  16225. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16226. if(str[0]=='\0')
  16227. {
  16228. break;
  16229. }
  16230. //TempStopTransaction格式: 槍號,StopTransaction封包
  16231. strncpy(connectorStr, str, 1);
  16232. if(atoi(connectorStr) != (gun_index+1))
  16233. {
  16234. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16235. fclose(fptr1);
  16236. return ;
  16237. }
  16238. //random_uuid(guid);
  16239. strncpy(guid, str+6, 36); //copy guid
  16240. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16241. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16242. {
  16243. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16244. }
  16245. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16246. OCPP_insert_transaction_msg(NO, str);
  16247. memset(str,0,ARRAY_SIZE(str));
  16248. }
  16249. }
  16250. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16251. fclose(fptr1);
  16252. remove(TempStopTransaction); // remove the original file
  16253. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16254. }
  16255. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16256. {
  16257. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16258. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16259. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16260. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16261. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16262. }
  16263. int GetWebSocketPingInterval(void)
  16264. {
  16265. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16266. }
  16267. int GetServerSign(void)
  16268. {
  16269. return server_sign;
  16270. }
  16271. uint8_t GetOcppSecurityProfile()
  16272. {
  16273. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16274. }
  16275. void GetOcppChargerBoxId(uint8_t *data)
  16276. {
  16277. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16278. }
  16279. void GetOcppSecurityPassword(uint8_t *data)
  16280. {
  16281. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16282. }
  16283. void SetOcppVersion(uint8_t *version)
  16284. {
  16285. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16286. DEBUG_INFO("ocpp version: %s\n", version);
  16287. if(strstr((char*)version, "ocpp1.6") != NULL)
  16288. {
  16289. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16290. }
  16291. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16292. {
  16293. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16294. system("pkill OcppBackend");
  16295. }
  16296. }
  16297. void SetServerSign(int value)
  16298. {
  16299. server_sign = value;
  16300. }
  16301. int GetBootNotificationInterval(void)
  16302. {
  16303. return BootNotificationInterval;
  16304. }
  16305. int GetInternetConn(void)
  16306. {
  16307. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16308. }
  16309. int GetBackendConnectionTimeout(void)
  16310. {
  16311. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16312. }
  16313. int isConnectorInitMode(int gun_index)
  16314. {
  16315. int tempIndex = 0;
  16316. int result = TRUE;
  16317. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16318. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16319. {
  16320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16321. {
  16322. tempIndex = ((gun_index==2) ? 1: 0);
  16323. }
  16324. else
  16325. {
  16326. tempIndex = gun_index;
  16327. }
  16328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16329. {
  16330. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16331. {
  16332. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16333. } //end of the same index
  16334. }//end of for CHAdeMO_QUANTITY
  16335. }
  16336. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16337. {
  16338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16339. {
  16340. tempIndex = ((gun_index==2) ? 1: 0);
  16341. }
  16342. else
  16343. {
  16344. tempIndex = gun_index;
  16345. }
  16346. for (int index = 0; index < CCS_QUANTITY; index++)
  16347. {
  16348. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16349. {
  16350. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16351. } //end of the same index
  16352. } // end of for CCS_QUANTITY
  16353. }
  16354. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16355. {
  16356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16357. {
  16358. tempIndex = ((gun_index==2) ? 1: 0);
  16359. }
  16360. else
  16361. {
  16362. tempIndex = gun_index;
  16363. }
  16364. for (int index = 0; index < GB_QUANTITY; index++)
  16365. {
  16366. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16367. {
  16368. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16369. } //end of the same index
  16370. } // end of for GB_QUANTITY
  16371. }
  16372. else if(gunType[gun_index] == GUN_TYPE_DO)
  16373. {
  16374. tempIndex = gun_index;
  16375. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16376. {
  16377. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16378. {
  16379. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16380. } //end of the same index
  16381. }
  16382. }
  16383. else
  16384. {
  16385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16386. {
  16387. tempIndex = 2;
  16388. }
  16389. else
  16390. {
  16391. tempIndex = gun_index;
  16392. }
  16393. for (int index = 0; index < AC_QUANTITY; index++)
  16394. {
  16395. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16396. {
  16397. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16398. }//end of the same index
  16399. }//end of for AC_QUANTITY
  16400. }
  16401. return result;
  16402. }
  16403. void refreshProcDogTimer()
  16404. {
  16405. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16406. }
  16407. void InitialSystemValue(void)
  16408. {
  16409. int connectorIndex = 0;
  16410. //int valueASCII = 0;
  16411. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16412. gunTotalNumber=0;
  16413. SystemInitial = 0;
  16414. locallistVersion=0;
  16415. BootNotificationInterval = 0;
  16416. authorizeRetryTimes = 0;
  16417. GunStatusInterval = 10;
  16418. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16419. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16420. //Hear Beat
  16421. HeartBeatWithNOResponse = 0;
  16422. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16423. FirstHeartBeat = 0;
  16424. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16425. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16426. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16427. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16428. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16429. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16430. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16431. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16432. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16433. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16434. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16435. memset(gunType, 0, ARRAY_SIZE(gunType));
  16436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16437. {
  16438. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16439. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16440. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16441. {
  16442. // DO series
  16443. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16444. {
  16445. SystemInitial = SystemInitial + 1;
  16446. gunTotalNumber = gunTotalNumber + 1;
  16447. gunType[connectorIndex] = GUN_TYPE_DO;
  16448. connectorIndex = connectorIndex + 1;
  16449. }
  16450. }
  16451. else
  16452. {
  16453. // DM, DW, DS series
  16454. //check connector / socket type (index: 8, 9, 10)
  16455. for(int index=7; index <10 ; index++)
  16456. {
  16457. if(index != 8)
  16458. {
  16459. // DC Connector
  16460. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16461. {
  16462. SystemInitial = SystemInitial + 1;
  16463. gunTotalNumber = gunTotalNumber + 1;
  16464. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16465. connectorIndex = connectorIndex + 1;
  16466. }
  16467. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16468. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16469. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16470. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16471. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16472. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16473. {
  16474. SystemInitial = SystemInitial + 1;
  16475. gunTotalNumber = gunTotalNumber + 1;
  16476. gunType[connectorIndex] = GUN_TYPE_CCS;
  16477. connectorIndex = connectorIndex + 1;
  16478. }
  16479. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16480. {
  16481. SystemInitial = SystemInitial + 1;
  16482. gunTotalNumber = gunTotalNumber + 1;
  16483. gunType[connectorIndex] = GUN_TYPE_GBT;
  16484. connectorIndex = connectorIndex + 1;
  16485. }
  16486. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16487. {
  16488. SystemInitial = SystemInitial + 1;
  16489. gunTotalNumber = gunTotalNumber + 1;
  16490. gunType[connectorIndex] = GUN_TYPE_DO;
  16491. connectorIndex = connectorIndex + 1;
  16492. }
  16493. }
  16494. else
  16495. {
  16496. // AC Connector
  16497. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16498. {
  16499. SystemInitial = SystemInitial + 1;
  16500. gunTotalNumber = gunTotalNumber + 1;
  16501. gunType[connectorIndex] = GUN_TYPE_AC;
  16502. connectorIndex = connectorIndex + 1;
  16503. }
  16504. }
  16505. }
  16506. }
  16507. //DEBUG_INFO("DC ...\n");
  16508. }
  16509. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16510. {
  16511. //check connector / socket type (index: 8, 9, 10)
  16512. for(int index=7; index <10 ; index++)
  16513. {
  16514. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16515. {
  16516. SystemInitial = SystemInitial + 1;
  16517. gunTotalNumber = gunTotalNumber + 1;
  16518. gunType[connectorIndex] = GUN_TYPE_AC;
  16519. connectorIndex = connectorIndex + 1;
  16520. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16521. }
  16522. }
  16523. }
  16524. //Status && ConnectorPlugIn Setting
  16525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16526. {
  16527. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16528. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16529. }
  16530. for (int index = 0; index < CCS_QUANTITY; index++)
  16531. {
  16532. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16533. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16534. }
  16535. for (int index = 0; index < GB_QUANTITY; index++)
  16536. {
  16537. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16538. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16539. }
  16540. for (int index = 0; index < AC_QUANTITY; index++)
  16541. {
  16542. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16543. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16544. }
  16545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16546. {
  16547. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16548. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16549. }
  16550. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16551. {
  16552. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16553. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16554. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16555. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16556. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16557. }
  16558. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16559. clientTime.Heartbeat=time((time_t*)NULL);
  16560. sleep(1);
  16561. }
  16562. void LWS_Send(char *str)
  16563. {
  16564. //=====================================================
  16565. // Check InternetConn 0: disconnected, 1: connected
  16566. //====================================================
  16567. if(GetOcppConnStatus() == 0)
  16568. {
  16569. DEBUG_INFO("offline now !!!\n");
  16570. return;
  16571. }
  16572. // Only disable isWebsocketSendable operation initiated by charger
  16573. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16574. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16575. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16576. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16577. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16578. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16579. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16580. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16581. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16582. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16583. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16584. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16585. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16586. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16587. {
  16588. isWebsocketSendable = 0;
  16589. }
  16590. pthread_mutex_lock(&lock_send);
  16591. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16592. sprintf((char *)SendBuffer, "%s", str);
  16593. SendBufLen = strlen(str);
  16594. pthread_mutex_unlock(&lock_send);
  16595. lws_callback_on_writable(wsi_client);
  16596. //lws_service(context, 0);
  16597. //sleep(1);
  16598. }
  16599. void LWS_SendNow(char *str)
  16600. {
  16601. //=====================================================
  16602. // Check InternetConn 0: disconnected, 1: connected
  16603. //====================================================
  16604. if(GetOcppConnStatus() == 0)
  16605. {
  16606. DEBUG_INFO("offline now !!!\n");
  16607. return;
  16608. }
  16609. // Only disable isWebsocketSendable operation initiated by charger
  16610. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16611. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16612. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16613. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16614. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16615. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16616. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16617. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16618. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16619. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16620. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16621. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16622. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16623. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16624. {
  16625. isWebsocketSendable = 0;
  16626. }
  16627. pthread_mutex_lock(&lock_send);
  16628. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16629. sprintf((char *)SendBuffer, "%s", str);
  16630. SendBufLen = strlen(str);
  16631. pthread_mutex_unlock(&lock_send);
  16632. lws_callback_on_writable(wsi_client);
  16633. lws_service(context, 0);
  16634. //sleep(1);
  16635. }