MessageHandler.c 888 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4.
  123. unsigned char :3; //bit 5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // Save configuration
  363. //=========================================
  364. int runShellCmd(const char*cmd)
  365. {
  366. int result = FAIL;
  367. char buf[256];
  368. FILE *fp;
  369. fp = popen(cmd, "r");
  370. if(fp != NULL)
  371. {
  372. while(fgets(buf, sizeof(buf), fp) != NULL)
  373. {
  374. DEBUG_INFO("%s\n", buf);
  375. }
  376. result = PASS;
  377. }
  378. pclose(fp);
  379. return result;
  380. }
  381. int StoreUsrConfigData(struct SysConfigData *UsrData)
  382. {
  383. int result = PASS;
  384. int fd,wrd;
  385. unsigned int i,Chk;
  386. unsigned char *ptr, *BufTmp;
  387. int MtdBlockSize = 0x300000;
  388. Chk=0;
  389. ptr=(unsigned char *)UsrData;
  390. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  391. {
  392. memset(BufTmp,0,MtdBlockSize);
  393. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  394. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  395. Chk+=*(BufTmp+i);
  396. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  397. // Output configuration to file.
  398. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  399. if (fd < 0)
  400. {
  401. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  402. free(BufTmp);
  403. return 0;
  404. }
  405. wrd=write(fd, BufTmp, MtdBlockSize);
  406. close(fd);
  407. if(wrd<MtdBlockSize)
  408. {
  409. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  410. free(BufTmp);
  411. return 0;
  412. }
  413. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  414. DEBUG_INFO("Erase /dev/mtd10.\n");
  415. runShellCmd("flash_erase /dev/mtd10 0 0");
  416. DEBUG_INFO("Write /dev/mtd10.\n");
  417. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  418. DEBUG_INFO("Erase /dev/mtd11.\n");
  419. runShellCmd("flash_erase /dev/mtd11 0 0");
  420. DEBUG_INFO("Write /dev/mtd11.\n");
  421. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  422. system("rm -f /mnt/EvseConfig.bin");
  423. DEBUG_INFO("EvseConfig write to flash OK\n");
  424. }
  425. else
  426. {
  427. DEBUG_ERROR("alloc BlockSize NG\r\n");
  428. result = FAIL;
  429. }
  430. if(BufTmp!=NULL)
  431. free(BufTmp);
  432. return result;
  433. }
  434. //=========================================
  435. // Sqlite3 related function
  436. //=========================================
  437. static int selectSqlCount = 0;
  438. static int callback(void *data, int argc, char **argv, char **azColName){
  439. int i;
  440. //printf("%s: ", (const char*)data);
  441. selectSqlCount = argc;
  442. for(i = 0; i<argc; i++){
  443. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  444. }
  445. //printf("\n");
  446. return 0;
  447. }
  448. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  449. //int i;
  450. //printf("%s:\n", (const char*)data);
  451. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  452. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  453. return 0;
  454. }
  455. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  456. //printf("%s:\n", (const char*)data);
  457. //idTag
  458. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  459. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. //parentIdTag
  461. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  462. //expir_date
  463. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  464. //status
  465. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  466. //version
  467. if(columenCount > 5)
  468. idTagQuery.listVersionInt = atoi(columnValue[5]);
  469. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  470. return 0;
  471. }
  472. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  473. {
  474. // localversion = argv[5] ? atoi(argv[5]) : 0;
  475. // printf("localversion=%d\n", localversion);
  476. return 0;
  477. }
  478. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  479. {
  480. for (int i = 0; i < n_columns; i++)
  481. {
  482. DEBUG_INFO("%s\t", col_values[i]);
  483. }
  484. DEBUG_INFO("\n");
  485. return 0;
  486. }
  487. int OCPP_cleanLocalCache()
  488. {
  489. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  490. char *errMsg = 0;
  491. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  492. if (SQLITE_OK != rc)
  493. {
  494. DEBUG_INFO("SQL error: %s\n",errMsg);
  495. return FALSE;
  496. }
  497. return TRUE;
  498. }
  499. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  500. {
  501. int isSuccess = TRUE;
  502. int ret = 0;
  503. //const char* data = "Callback function called";
  504. char sql[300];
  505. char zErrMsg[200];
  506. memset(sql, 0, 300);
  507. memset(zErrMsg, 0, 200);
  508. 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);
  509. //* Execute SQL statement */
  510. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  511. if( ret != SQLITE_OK )
  512. {
  513. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  514. isSuccess = FALSE;
  515. }
  516. return isSuccess;
  517. }
  518. void OCPP_getIdTagFromLocalCache(char idTag[])
  519. {
  520. int rc = 0;
  521. char sql[100];
  522. char zErrMsg[100];
  523. memset(sql, 0, 100);
  524. memset(zErrMsg, 0, 100);
  525. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  526. memset(&idTagQuery, 0, sizeof(idTagQuery));
  527. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  528. /* Execute SQL statement */
  529. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  530. if( rc != SQLITE_OK )
  531. {
  532. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  533. }
  534. }
  535. void OCPP_getListVerion()
  536. {
  537. int rc = 0;
  538. // const char* data = "Callback function called";
  539. char sql[100];
  540. char zErrMsg[100];
  541. memset(sql, 0, 100);
  542. memset(zErrMsg, 0, 100);
  543. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  544. /* Execute SQL statement */
  545. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  546. if( rc != SQLITE_OK )
  547. {
  548. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  549. }
  550. }
  551. void OCPP_get_TableAuthlocalAllData(void)
  552. {
  553. int rc = 0;
  554. char sql[100];
  555. char zErrMsg[100];
  556. memset(sql, 0, 100);
  557. memset(zErrMsg, 0, 100);
  558. sprintf(sql,"select * from ocpp_auth_local ");
  559. /* Execute SQL statement */
  560. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  561. if( rc != SQLITE_OK )
  562. {
  563. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  564. }
  565. //return ver;
  566. }
  567. int OCPP_cleanLocalList()
  568. {
  569. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  570. char *errMsg = 0;
  571. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  572. if (SQLITE_OK != rc)
  573. {
  574. DEBUG_INFO("%s\n",errMsg);
  575. return FALSE;
  576. }
  577. return TRUE;
  578. }
  579. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  580. {
  581. int isSuccess = FALSE;
  582. int ret = 0;
  583. //const char* data = "Callback function called";
  584. char sql[300];
  585. char zErrMsg[200];
  586. memset(sql, 0, 300);
  587. memset(zErrMsg, 0, 200);
  588. 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);
  589. //* Execute SQL statement */
  590. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  591. if( ret != SQLITE_OK )
  592. {
  593. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  594. return isSuccess;
  595. }
  596. memset(sql, 0, 300);
  597. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  598. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  599. if( ret != SQLITE_OK )
  600. {
  601. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  602. return isSuccess;
  603. }
  604. isSuccess = TRUE;
  605. return isSuccess;
  606. }
  607. void OCPP_getIdTagFromLocalList(char idTag[])
  608. {
  609. int rc = 0;
  610. // const char* data = "Callback function called";
  611. char sql[100];
  612. char zErrMsg[100];
  613. memset(sql, 0, 100);
  614. memset(zErrMsg, 0, 100);
  615. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  616. memset(&idTagQuery, 0, sizeof(idTagQuery));
  617. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  618. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  619. /* Execute SQL statement */
  620. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  621. if( rc != SQLITE_OK )
  622. {
  623. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  624. }
  625. //return ver;
  626. }
  627. void OCPP_deleteIdTagFromLocalList(char idTag[])
  628. {
  629. //int ver = 0;
  630. //int isSuccess = FALSE;
  631. int rc = 0;
  632. char sql[100];
  633. char zErrMsg[100];
  634. memset(sql, 0, 100);
  635. memset(zErrMsg, 0, 100);
  636. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  637. //* Execute SQL statement */
  638. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  639. if( rc != SQLITE_OK )
  640. {
  641. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  642. }
  643. }
  644. int getCurrentYear()
  645. {
  646. int result = 0;
  647. time_t CurrentTime;
  648. struct tm *tm;
  649. CurrentTime = time(NULL);
  650. tm=localtime(&CurrentTime);
  651. result = (tm->tm_year + 1900);
  652. return result;
  653. }
  654. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  655. {
  656. int result = PASS;
  657. char* errMsg = NULL;
  658. char sqlStr[8192];
  659. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  664. }
  665. 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));
  666. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  667. {
  668. result = FAIL;
  669. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  670. }
  671. return result;
  672. }
  673. //==========================================
  674. // Check time passed since today
  675. //==========================================
  676. long long DiffTimebWithNow(struct timeb ST)
  677. {
  678. //return milli-second
  679. struct timeb ET;
  680. long long StartTime,StopTime;
  681. ftime(&ET);
  682. StartTime=(long long)ST.time;
  683. StopTime=(long long)ET.time;
  684. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  685. }
  686. int getTimePassSinceToday(uint8_t gun_index)
  687. {
  688. int result = -1;
  689. static time_t lastTime[4];
  690. time_t t;
  691. struct tm *tmStartToday;
  692. struct timeb tbStartToday;
  693. t=time(NULL);
  694. if(difftime(t, lastTime[gun_index])>0)
  695. {
  696. tmStartToday=localtime(&t);
  697. tmStartToday->tm_hour = 0;
  698. tmStartToday->tm_min = 0;
  699. tmStartToday->tm_sec = 0;
  700. tbStartToday.time = mktime(tmStartToday);
  701. tbStartToday.millitm = 0;
  702. result = DiffTimebWithNow(tbStartToday)/1000;
  703. lastTime[gun_index] = t;
  704. }
  705. return result;
  706. }
  707. void getNowDatetime(uint8_t *data)
  708. {
  709. time_t t = time(NULL);
  710. struct tm tm = *localtime(&t);
  711. 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);
  712. }
  713. int syncDateTimeRTC(uint8_t *data)
  714. {
  715. struct ParsingResult
  716. {
  717. int result;
  718. int scanedElement;
  719. int year;
  720. int month;
  721. int mday;
  722. int hour;
  723. int min;
  724. int sec;
  725. int tz_hour;
  726. int tz_min;
  727. float minSec;
  728. }result;
  729. struct tm tmOrg;
  730. struct tm *tmTarget;
  731. struct timeb tbTarget;
  732. char buf[128];
  733. memset(&result, 0x00, sizeof(struct ParsingResult));
  734. result.result = PASS;
  735. if(strstr((char*)data, ".") != NULL)
  736. {
  737. // Original data with mini second
  738. if(strstr((char*)data, "Z") != NULL)
  739. {
  740. // Original data with Z
  741. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  742. &result.year,
  743. &result.month,
  744. &result.mday,
  745. &result.hour,
  746. &result.min,
  747. &result.sec,
  748. &result.minSec);
  749. }
  750. else
  751. {
  752. // Original data without Z
  753. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  754. &result.year,
  755. &result.month,
  756. &result.mday,
  757. &result.hour,
  758. &result.min,
  759. &result.sec,
  760. &result.minSec,
  761. &result.tz_hour,
  762. &result.tz_min);
  763. }
  764. }
  765. else
  766. {
  767. // Original data without mini second
  768. if(strstr((char*)data, "Z") != NULL)
  769. {
  770. // Original data with Z
  771. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  772. &result.year,
  773. &result.month,
  774. &result.mday,
  775. &result.hour,
  776. &result.min,
  777. &result.sec);
  778. }
  779. else
  780. {
  781. // Original data without Z
  782. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  783. &result.year,
  784. &result.month,
  785. &result.mday,
  786. &result.hour,
  787. &result.min,
  788. &result.sec,
  789. &result.tz_hour,
  790. &result.tz_min);
  791. }
  792. }
  793. tmOrg.tm_year = result.year - 1900;
  794. tmOrg.tm_mon = result.month - 1;
  795. tmOrg.tm_mday = result.mday;
  796. tmOrg.tm_hour = result.hour;
  797. tmOrg.tm_min = result.min;
  798. tmOrg.tm_sec = result.sec;
  799. tmOrg.tm_gmtoff = 0;
  800. tbTarget.time = mktime(&tmOrg);
  801. tbTarget.timezone = 0;
  802. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  803. tmTarget = gmtime(&tbTarget.time);
  804. 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);
  805. //DEBUG_INFO(" org date time: %s\n", data);
  806. //DEBUG_INFO("parse date time: %s\n", buf);
  807. system(buf);
  808. system("/sbin/hwclock -w --systohc");
  809. if(result.scanedElement < 6)
  810. result.result = FAIL;
  811. return result.result;
  812. }
  813. //==========================================
  814. // GetCompositeSchedule logic related function
  815. //==========================================
  816. int DiffTimebSec(struct timeb ST, struct timeb ET)
  817. {
  818. //return milli-second
  819. unsigned int StartTime,StopTime;
  820. StartTime=(unsigned int)ST.time;
  821. StopTime=(unsigned int)ET.time;
  822. return (StopTime-StartTime);
  823. }
  824. int DiffTimebWithNowSec(struct timeb ST)
  825. {
  826. //return milli-second
  827. struct timeb ET;
  828. unsigned int StartTime,StopTime;
  829. ftime(&ET);
  830. StartTime=(unsigned int)ST.time;
  831. StopTime=(unsigned int)ET.time;
  832. return (StopTime-StartTime);
  833. }
  834. int getStartStop(uint8_t *start, uint8_t *stop)
  835. {
  836. int result = -1;
  837. struct tm tmStart;
  838. struct timeb tbStart;
  839. struct tm tmStop;
  840. struct timeb tbStop;
  841. 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) &&
  842. (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))
  843. {
  844. //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);
  845. //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);
  846. tmStart.tm_year -= 1900;
  847. tmStart.tm_mon -= 1;
  848. tbStart.time = mktime(&tmStart);
  849. tbStart.millitm = 0;
  850. tmStop.tm_year -= 1900;
  851. tmStop.tm_mon -= 1;
  852. tbStop.time = mktime(&tmStop);
  853. tbStop.millitm = 0;
  854. result = DiffTimebSec(tbStart, tbStop);
  855. //DEBUG_INFO("getStartStop(): %d\n", result);
  856. }
  857. else
  858. {
  859. DEBUG_WARN("Start or stop date parsing error.\r\n");
  860. }
  861. return result;
  862. }
  863. int isOvertNow(uint8_t *start)
  864. {
  865. int result = NO;
  866. struct ParsingResult
  867. {
  868. int result;
  869. int scanedElement;
  870. int year;
  871. int month;
  872. int mday;
  873. int hour;
  874. int min;
  875. int sec;
  876. int tz_hour;
  877. int tz_min;
  878. float minSec;
  879. }parsingResult;
  880. struct tm tmStart;
  881. struct timeb tbStart;
  882. if(strstr((char*)start, ".") != NULL)
  883. {
  884. // Original data with mini second
  885. if(strstr((char*)start, "Z") != NULL)
  886. {
  887. // Original data with Z
  888. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  889. &parsingResult.year,
  890. &parsingResult.month,
  891. &parsingResult.mday,
  892. &parsingResult.hour,
  893. &parsingResult.min,
  894. &parsingResult.sec,
  895. &parsingResult.minSec);
  896. }
  897. else
  898. {
  899. // Original data without Z
  900. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  901. &parsingResult.year,
  902. &parsingResult.month,
  903. &parsingResult.mday,
  904. &parsingResult.hour,
  905. &parsingResult.min,
  906. &parsingResult.sec,
  907. &parsingResult.minSec,
  908. &parsingResult.tz_hour,
  909. &parsingResult.tz_min);
  910. }
  911. }
  912. else
  913. {
  914. // Original data without mini second
  915. if(strstr((char*)start, "Z") != NULL)
  916. {
  917. // Original data with Z
  918. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  919. &parsingResult.year,
  920. &parsingResult.month,
  921. &parsingResult.mday,
  922. &parsingResult.hour,
  923. &parsingResult.min,
  924. &parsingResult.sec);
  925. }
  926. else
  927. {
  928. // Original data without Z
  929. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  930. &parsingResult.year,
  931. &parsingResult.month,
  932. &parsingResult.mday,
  933. &parsingResult.hour,
  934. &parsingResult.min,
  935. &parsingResult.sec,
  936. &parsingResult.tz_hour,
  937. &parsingResult.tz_min);
  938. }
  939. }
  940. if(parsingResult.scanedElement >= 6)
  941. {
  942. tmStart.tm_year = parsingResult.year - 1900;
  943. tmStart.tm_mon = parsingResult.month - 1;
  944. tmStart.tm_mday = parsingResult.mday;
  945. tmStart.tm_hour = parsingResult.hour;
  946. tmStart.tm_min = parsingResult.min;
  947. tmStart.tm_sec = parsingResult.sec;
  948. tmStart.tm_gmtoff = 0;
  949. tbStart.time = mktime(&tmStart);
  950. tbStart.timezone = 0;
  951. tbStart.millitm = 0;
  952. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  953. if(DiffTimebWithNowSec(tbStart) <= 0)
  954. result = NO;
  955. else
  956. result = YES;
  957. }
  958. else
  959. {
  960. DEBUG_WARN("Start date parsing error.\n");
  961. }
  962. return result;
  963. }
  964. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  965. {
  966. int result = -1;
  967. struct tm tmStart;
  968. struct timeb tbStart;
  969. struct tm tmStop;
  970. struct timeb tbStop;
  971. 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) &&
  972. (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))
  973. {
  974. tmStart.tm_year -= 1900;
  975. tmStart.tm_mon -= 1;
  976. tbStart.time = mktime(&tmStart);
  977. tbStart.millitm = 0;
  978. tmStop.tm_year -= 1900;
  979. tmStop.tm_mon -= 1;
  980. tbStop.time = mktime(&tmStop);
  981. tbStop.millitm = 0;
  982. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  983. }
  984. return result;
  985. }
  986. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  987. {
  988. FILE *fp;
  989. char profileFileName[128];
  990. char *line = NULL;
  991. size_t len = 0;
  992. time_t CurrentTime;
  993. struct tm *tmComposite;
  994. struct StructChargingProfile maxProfile;
  995. uint8_t limitMax=0;
  996. int compositePeriodIdx = 0;
  997. CurrentTime = time(NULL);
  998. tmComposite=localtime(&CurrentTime);
  999. 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);
  1000. if(isUnitA)
  1001. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1002. else
  1003. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1004. compositeProfile->ChargingSchedule.Duration = durationReq;
  1005. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1006. {
  1007. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1008. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1009. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1010. }
  1011. compositeProfile->ChargingProfileId = 0;
  1012. compositeProfile->StackLevel = 99 ;
  1013. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1014. maxProfile.ChargingProfileId = -1;
  1015. maxProfile.ChargingSchedule.Duration = -1;
  1016. system("rm -f /tmp/*.json");
  1017. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1018. // Search max profile
  1019. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1020. if((access(profileFileName, F_OK))!=-1)
  1021. {
  1022. fp = fopen(profileFileName, "r");
  1023. while(getline(&line, &len, fp) != -1)
  1024. {
  1025. json_object *obj = NULL;
  1026. obj = json_tokener_parse(line);
  1027. if(is_error(obj))
  1028. {
  1029. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1030. }
  1031. else
  1032. {
  1033. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1034. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1035. )
  1036. {
  1037. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1038. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1039. )
  1040. {
  1041. struct tm tmFrom, tmTo;
  1042. struct timeb tbFrom, tbTo;
  1043. 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) &&
  1044. (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))
  1045. {
  1046. tmFrom.tm_year -= 1900;
  1047. tmFrom.tm_mon -= 1;
  1048. tbFrom.time = mktime(&tmFrom);
  1049. tmTo.tm_year -= 1900;
  1050. tmTo.tm_mon -= 1;
  1051. tbTo.time = mktime(&tmTo);
  1052. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1053. {
  1054. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1055. {
  1056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1057. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1059. }
  1060. maxProfile.ChargingProfileId = -1;
  1061. maxProfile.StackLevel = -1;
  1062. if(maxProfile.ChargingProfileId == -1)
  1063. DEBUG_INFO("MaxProfile found.\n");
  1064. else
  1065. DEBUG_INFO("MaxProfile updated.\n");
  1066. // Required item
  1067. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1068. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1069. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1070. if(isUnitA)
  1071. {
  1072. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1073. 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++)
  1074. {
  1075. 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"));
  1076. 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?
  1077. 3:
  1078. 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")));
  1079. 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")));
  1080. }
  1081. }
  1082. else
  1083. {
  1084. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1085. 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++)
  1086. {
  1087. 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"));
  1088. 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?
  1089. 3:
  1090. 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")));
  1091. 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));
  1092. }
  1093. }
  1094. // Optional item
  1095. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1096. {
  1097. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1098. }
  1099. else
  1100. {
  1101. sprintf((char*)maxProfile.ValidFrom, " ");
  1102. }
  1103. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1104. {
  1105. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1106. }
  1107. else
  1108. {
  1109. sprintf((char*)maxProfile.ValidTo, " ");
  1110. }
  1111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1112. {
  1113. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1114. }
  1115. else
  1116. {
  1117. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1118. }
  1119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1120. {
  1121. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1122. }
  1123. else
  1124. {
  1125. maxProfile.TransactionId = -1;
  1126. }
  1127. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1128. {
  1129. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1130. }
  1131. else
  1132. {
  1133. maxProfile.ChargingSchedule.Duration = 86400;
  1134. }
  1135. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1136. {
  1137. 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")));
  1138. }
  1139. else
  1140. {
  1141. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1142. }
  1143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1144. {
  1145. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1146. }
  1147. else
  1148. {
  1149. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1150. }
  1151. }
  1152. }
  1153. }
  1154. else
  1155. {
  1156. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1157. {
  1158. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1159. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1160. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1161. }
  1162. maxProfile.ChargingProfileId = -1;
  1163. maxProfile.StackLevel = -1;
  1164. if(maxProfile.ChargingProfileId == -1)
  1165. DEBUG_INFO("MaxProfile found.\n");
  1166. else
  1167. DEBUG_INFO("MaxProfile updated.\n");
  1168. // Required item
  1169. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1170. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1171. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1172. if(isUnitA)
  1173. {
  1174. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1175. 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++)
  1176. {
  1177. 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"));
  1178. 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?
  1179. 3:
  1180. 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")));
  1181. 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")));
  1182. }
  1183. }
  1184. else
  1185. {
  1186. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1187. 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++)
  1188. {
  1189. 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"));
  1190. 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?
  1191. 3:
  1192. 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")));
  1193. 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));
  1194. }
  1195. }
  1196. // Optional item
  1197. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1198. {
  1199. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1200. }
  1201. else
  1202. {
  1203. sprintf((char*)maxProfile.ValidFrom, " ");
  1204. }
  1205. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1206. {
  1207. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1208. }
  1209. else
  1210. {
  1211. sprintf((char*)maxProfile.ValidTo, " ");
  1212. }
  1213. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1214. {
  1215. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1216. }
  1217. else
  1218. {
  1219. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1220. }
  1221. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1222. {
  1223. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1224. }
  1225. else
  1226. {
  1227. maxProfile.TransactionId = -1;
  1228. }
  1229. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1230. {
  1231. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1232. }
  1233. else
  1234. {
  1235. maxProfile.ChargingSchedule.Duration = 86400;
  1236. }
  1237. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1238. {
  1239. 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")));
  1240. }
  1241. else
  1242. {
  1243. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1244. }
  1245. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1246. {
  1247. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1248. }
  1249. else
  1250. {
  1251. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1252. }
  1253. }
  1254. }
  1255. }
  1256. json_object_put(obj);
  1257. }
  1258. fclose(fp);
  1259. /*
  1260. if(maxProfile.ChargingProfileId !=-1)
  1261. {
  1262. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1263. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1264. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1265. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1266. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1267. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1268. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1269. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1270. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1271. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1272. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1274. {
  1275. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1276. {
  1277. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1278. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1279. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1280. }
  1281. }
  1282. }
  1283. else
  1284. DEBUG_INFO("MaxProfile not found.\n");
  1285. DEBUG_INFO("------------------------------------\n");*/
  1286. }
  1287. if(maxProfile.ChargingProfileId != -1)
  1288. {
  1289. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1290. {
  1291. if(maxProfile.ChargingSchedule.Duration != -1)
  1292. {
  1293. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1294. 0:
  1295. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1296. }
  1297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1298. {
  1299. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1300. {
  1301. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1302. 0:
  1303. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1304. if(idxPeriod > 0)
  1305. {
  1306. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1307. {
  1308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1309. }
  1310. }
  1311. }
  1312. }
  1313. }
  1314. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1315. {
  1316. if(maxProfile.ChargingSchedule.Duration != -1)
  1317. {
  1318. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1319. }
  1320. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1321. {
  1322. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1323. {
  1324. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1325. if(idxPeriod > 0)
  1326. {
  1327. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1328. {
  1329. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1330. }
  1331. }
  1332. }
  1333. }
  1334. }
  1335. else
  1336. {
  1337. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1338. {
  1339. if(maxProfile.ChargingSchedule.Duration != -1)
  1340. {
  1341. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1342. 0:
  1343. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1344. }
  1345. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1346. {
  1347. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1348. {
  1349. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1350. 0:
  1351. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1352. if(idxPeriod > 0)
  1353. {
  1354. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1355. {
  1356. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1357. }
  1358. }
  1359. }
  1360. }
  1361. }
  1362. else
  1363. {
  1364. if(maxProfile.ChargingSchedule.Duration != -1)
  1365. {
  1366. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1367. 0:
  1368. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1369. }
  1370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1371. {
  1372. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1373. {
  1374. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1375. 0:
  1376. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1377. if(idxPeriod > 0)
  1378. {
  1379. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1380. {
  1381. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1382. }
  1383. }
  1384. }
  1385. }
  1386. }
  1387. }
  1388. /*
  1389. DEBUG_INFO("MaxProfile after align.\n");
  1390. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1391. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1392. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1393. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1394. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1395. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1396. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1397. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1398. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1399. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1400. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1401. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1402. {
  1403. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1404. {
  1405. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1406. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1407. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1408. }
  1409. }
  1410. DEBUG_INFO("------------------------------------\n");*/
  1411. }
  1412. // Find each profile period quantity
  1413. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1414. {
  1415. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1416. limitMax = idx+1;
  1417. }
  1418. if(maxProfile.ChargingProfileId != -1)
  1419. {
  1420. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1421. {
  1422. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1423. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1424. (maxProfile.ChargingSchedule.Duration > 0))
  1425. {
  1426. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1427. {
  1428. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1429. compositePeriodIdx++;
  1430. }
  1431. else
  1432. {
  1433. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1434. }
  1435. }
  1436. }
  1437. }
  1438. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1439. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1440. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1441. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1442. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1443. {
  1444. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1445. {
  1446. compositeProfile->ChargingProfileId = 1;
  1447. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1448. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1449. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1450. }
  1451. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1452. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1453. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1454. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1455. }
  1456. if(line)
  1457. free(line);
  1458. }
  1459. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1460. {
  1461. FILE *fp;
  1462. char profileFileName[128];
  1463. char *line = NULL;
  1464. size_t len = 0;
  1465. time_t CurrentTime;
  1466. struct tm *tmComposite;
  1467. struct StructChargingProfile maxProfile;
  1468. struct StructChargingProfile defaultTxProfile;
  1469. struct StructChargingProfile txProfile;
  1470. struct StructChargingSchedulePeriod tmpPeriod;
  1471. uint8_t limitMax=0;
  1472. uint8_t limitDef=0;
  1473. uint8_t limitTx=0;
  1474. int compositePeriodIdx = 0;
  1475. CurrentTime = time(NULL);
  1476. tmComposite=localtime(&CurrentTime);
  1477. 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);
  1478. if(isUnitA)
  1479. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1480. else
  1481. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1482. compositeProfile->ChargingSchedule.Duration = durationReq;
  1483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1484. {
  1485. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1486. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1487. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1488. }
  1489. compositeProfile->ChargingProfileId = 0;
  1490. compositeProfile->StackLevel = 99 ;
  1491. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1492. maxProfile.ChargingProfileId = -1;
  1493. defaultTxProfile.ChargingProfileId = -1;
  1494. txProfile.ChargingProfileId = -1;
  1495. maxProfile.ChargingSchedule.Duration = -1;
  1496. defaultTxProfile.ChargingSchedule.Duration = -1;
  1497. txProfile.ChargingSchedule.Duration = -1;
  1498. system("rm -f /tmp/*.json");
  1499. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1500. /*
  1501. * Search valid charging profile
  1502. */
  1503. //DEBUG_INFO("====================================\n");
  1504. // Search tx profile
  1505. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1506. if((access(profileFileName, F_OK))!=-1)
  1507. {
  1508. fp = fopen(profileFileName, "r");
  1509. while(getline(&line, &len, fp) != -1)
  1510. {
  1511. json_object *obj = NULL;
  1512. obj = json_tokener_parse(line);
  1513. if(is_error(obj))
  1514. {
  1515. DEBUG_ERROR("Parse txProfile from file error.\n");
  1516. }
  1517. else
  1518. {
  1519. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1520. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1521. )
  1522. {
  1523. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1524. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1525. )
  1526. {
  1527. struct tm tmFrom, tmTo;
  1528. struct timeb tbFrom, tbTo;
  1529. 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) &&
  1530. (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))
  1531. {
  1532. tmFrom.tm_year -= 1900;
  1533. tmFrom.tm_mon -= 1;
  1534. tbFrom.time = mktime(&tmFrom);
  1535. tmTo.tm_year -= 1900;
  1536. tmTo.tm_mon -= 1;
  1537. tbTo.time = mktime(&tmTo);
  1538. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1539. {
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1543. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1544. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1545. }
  1546. txProfile.ChargingProfileId = -1;
  1547. txProfile.StackLevel = -1;
  1548. if(txProfile.ChargingProfileId == -1)
  1549. DEBUG_INFO("TxProfile found.\n");
  1550. else
  1551. DEBUG_INFO("TxProfile updated.\n");
  1552. // Required item
  1553. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1554. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1555. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1556. if(isUnitA)
  1557. {
  1558. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1559. 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++)
  1560. {
  1561. 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"));
  1562. 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?
  1563. 3:
  1564. 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")));
  1565. 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")));
  1566. }
  1567. }
  1568. else
  1569. {
  1570. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1571. 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++)
  1572. {
  1573. 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"));
  1574. 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?
  1575. 3:
  1576. 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")));
  1577. 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));
  1578. }
  1579. }
  1580. // Optional item
  1581. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1582. {
  1583. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1584. }
  1585. else
  1586. {
  1587. sprintf((char*)txProfile.ValidFrom, " ");
  1588. }
  1589. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1590. {
  1591. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1592. }
  1593. else
  1594. {
  1595. sprintf((char*)txProfile.ValidTo, " ");
  1596. }
  1597. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1598. {
  1599. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1600. }
  1601. else
  1602. {
  1603. sprintf((char*)txProfile.RecurrencyKind, " ");
  1604. }
  1605. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1606. {
  1607. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1608. }
  1609. else
  1610. {
  1611. txProfile.TransactionId = -1;
  1612. }
  1613. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1614. {
  1615. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1616. }
  1617. else
  1618. {
  1619. txProfile.ChargingSchedule.Duration = 86400;
  1620. }
  1621. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1622. {
  1623. 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")));
  1624. }
  1625. else
  1626. {
  1627. 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));
  1628. }
  1629. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1630. {
  1631. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1632. }
  1633. else
  1634. {
  1635. txProfile.ChargingSchedule.MinChargingRate = -1;
  1636. }
  1637. }
  1638. }
  1639. }
  1640. else
  1641. {
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1645. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1646. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1647. }
  1648. txProfile.ChargingProfileId = -1;
  1649. txProfile.StackLevel = -1;
  1650. if(txProfile.ChargingProfileId == -1)
  1651. DEBUG_INFO("TxProfile found.\n");
  1652. else
  1653. DEBUG_INFO("TxProfile updated.\n");
  1654. // Required item
  1655. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1656. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1657. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1658. if(isUnitA)
  1659. {
  1660. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1661. 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++)
  1662. {
  1663. 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"));
  1664. 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?
  1665. 3:
  1666. 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")));
  1667. 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")));
  1668. }
  1669. }
  1670. else
  1671. {
  1672. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1673. 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++)
  1674. {
  1675. 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"));
  1676. 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?
  1677. 3:
  1678. 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")));
  1679. 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));
  1680. }
  1681. }
  1682. // Optional item
  1683. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1684. {
  1685. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1686. }
  1687. else
  1688. {
  1689. sprintf((char*)txProfile.ValidFrom, " ");
  1690. }
  1691. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1692. {
  1693. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1694. }
  1695. else
  1696. {
  1697. sprintf((char*)txProfile.ValidTo, " ");
  1698. }
  1699. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1700. {
  1701. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1702. }
  1703. else
  1704. {
  1705. sprintf((char*)txProfile.RecurrencyKind, " ");
  1706. }
  1707. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1708. {
  1709. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1710. }
  1711. else
  1712. {
  1713. txProfile.TransactionId = -1;
  1714. }
  1715. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1716. {
  1717. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1718. }
  1719. else
  1720. {
  1721. txProfile.ChargingSchedule.Duration = 86400;
  1722. }
  1723. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1724. {
  1725. 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")));
  1726. }
  1727. else
  1728. {
  1729. 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));
  1730. }
  1731. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1732. {
  1733. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1734. }
  1735. else
  1736. {
  1737. txProfile.ChargingSchedule.MinChargingRate = -1;
  1738. }
  1739. }
  1740. }
  1741. }
  1742. json_object_put(obj);
  1743. }
  1744. fclose(fp);
  1745. /*
  1746. if(txProfile.ChargingProfileId != -1)
  1747. {
  1748. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1749. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1750. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1751. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1752. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1753. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1754. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1755. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1756. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1757. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1758. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1760. {
  1761. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1762. {
  1763. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1764. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1765. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1766. }
  1767. }
  1768. }
  1769. else
  1770. DEBUG_INFO("TxProfile not found.\n");*/
  1771. }
  1772. // Search default tx profile
  1773. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1774. if((access(profileFileName, F_OK))==-1)
  1775. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1776. if((access(profileFileName, F_OK))!=-1)
  1777. {
  1778. fp = fopen(profileFileName, "r");
  1779. while(getline(&line, &len, fp) != -1)
  1780. {
  1781. json_object *obj = NULL;
  1782. obj = json_tokener_parse(line);
  1783. if(is_error(obj))
  1784. {
  1785. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1786. }
  1787. else
  1788. {
  1789. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1790. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1791. )
  1792. {
  1793. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1794. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1795. )
  1796. {
  1797. struct tm tmFrom, tmTo;
  1798. struct timeb tbFrom, tbTo;
  1799. 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) &&
  1800. (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))
  1801. {
  1802. tmFrom.tm_year -= 1900;
  1803. tmFrom.tm_mon -= 1;
  1804. tbFrom.time = mktime(&tmFrom);
  1805. tmTo.tm_year -= 1900;
  1806. tmTo.tm_mon -= 1;
  1807. tbTo.time = mktime(&tmTo);
  1808. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1809. {
  1810. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1811. {
  1812. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1813. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1814. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1815. }
  1816. defaultTxProfile.ChargingProfileId = -1;
  1817. defaultTxProfile.StackLevel = -1;
  1818. if(defaultTxProfile.ChargingProfileId == -1)
  1819. DEBUG_INFO("TxDefaultProfile found.\n");
  1820. else
  1821. DEBUG_INFO("TxDefaultProfile updated.\n");
  1822. // Required item
  1823. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1824. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1825. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1826. if(isUnitA)
  1827. {
  1828. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1829. 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++)
  1830. {
  1831. 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"));
  1832. 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?
  1833. 3:
  1834. 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")));
  1835. 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")));
  1836. }
  1837. }
  1838. else
  1839. {
  1840. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1841. 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++)
  1842. {
  1843. 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"));
  1844. 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?
  1845. 3:
  1846. 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")));
  1847. 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));
  1848. }
  1849. }
  1850. // Optional item
  1851. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1852. {
  1853. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1854. }
  1855. else
  1856. {
  1857. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1858. }
  1859. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1860. {
  1861. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1862. }
  1863. else
  1864. {
  1865. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1866. }
  1867. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1868. {
  1869. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1870. }
  1871. else
  1872. {
  1873. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1874. }
  1875. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1876. {
  1877. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1878. }
  1879. else
  1880. {
  1881. defaultTxProfile.TransactionId = -1;
  1882. }
  1883. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1884. {
  1885. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1886. }
  1887. else
  1888. {
  1889. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1890. }
  1891. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1892. {
  1893. 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")));
  1894. }
  1895. else
  1896. {
  1897. 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));
  1898. }
  1899. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1900. {
  1901. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1902. }
  1903. else
  1904. {
  1905. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1906. }
  1907. }
  1908. }
  1909. }
  1910. else
  1911. {
  1912. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1913. {
  1914. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1915. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1916. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1917. }
  1918. defaultTxProfile.ChargingProfileId = -1;
  1919. defaultTxProfile.StackLevel = -1;
  1920. if(defaultTxProfile.ChargingProfileId == -1)
  1921. DEBUG_INFO("TxDefaultProfile found.\n");
  1922. else
  1923. DEBUG_INFO("TxDefaultProfile updated.\n");
  1924. // Required item
  1925. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1926. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1927. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1928. if(isUnitA)
  1929. {
  1930. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1931. 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++)
  1932. {
  1933. 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"));
  1934. 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?
  1935. 3:
  1936. 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")));
  1937. 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")));
  1938. }
  1939. }
  1940. else
  1941. {
  1942. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1943. 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++)
  1944. {
  1945. 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"));
  1946. 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?
  1947. 3:
  1948. 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")));
  1949. 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));
  1950. }
  1951. }
  1952. // Optional item
  1953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1954. {
  1955. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1956. }
  1957. else
  1958. {
  1959. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1960. }
  1961. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1962. {
  1963. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1964. }
  1965. else
  1966. {
  1967. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1968. }
  1969. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1970. {
  1971. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1972. }
  1973. else
  1974. {
  1975. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1976. }
  1977. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1978. {
  1979. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1980. }
  1981. else
  1982. {
  1983. defaultTxProfile.TransactionId = -1;
  1984. }
  1985. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1986. {
  1987. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1988. }
  1989. else
  1990. {
  1991. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1992. }
  1993. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1994. {
  1995. 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")));
  1996. }
  1997. else
  1998. {
  1999. 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));
  2000. }
  2001. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2002. {
  2003. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2004. }
  2005. else
  2006. {
  2007. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2008. }
  2009. }
  2010. }
  2011. }
  2012. json_object_put(obj);
  2013. }
  2014. fclose(fp);
  2015. /*
  2016. if(defaultTxProfile.ChargingProfileId != -1)
  2017. {
  2018. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2019. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2020. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2021. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2022. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2023. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2024. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2025. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2026. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2027. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2028. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2029. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2030. {
  2031. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2032. {
  2033. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2034. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2035. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2036. }
  2037. }
  2038. }
  2039. else
  2040. DEBUG_INFO("TxDefaultProfile not found.\n");
  2041. DEBUG_INFO("------------------------------------\n");*/
  2042. }
  2043. // Search max profile
  2044. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2045. if((access(profileFileName, F_OK))!=-1)
  2046. {
  2047. fp = fopen(profileFileName, "r");
  2048. while(getline(&line, &len, fp) != -1)
  2049. {
  2050. json_object *obj = NULL;
  2051. obj = json_tokener_parse(line);
  2052. if(is_error(obj))
  2053. {
  2054. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2055. }
  2056. else
  2057. {
  2058. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2059. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2060. )
  2061. {
  2062. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2063. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2064. )
  2065. {
  2066. struct tm tmFrom, tmTo;
  2067. struct timeb tbFrom, tbTo;
  2068. 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) &&
  2069. (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))
  2070. {
  2071. tmFrom.tm_year -= 1900;
  2072. tmFrom.tm_mon -= 1;
  2073. tbFrom.time = mktime(&tmFrom);
  2074. tmTo.tm_year -= 1900;
  2075. tmTo.tm_mon -= 1;
  2076. tbTo.time = mktime(&tmTo);
  2077. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2078. {
  2079. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2080. {
  2081. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2082. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2083. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2084. }
  2085. maxProfile.ChargingProfileId = -1;
  2086. maxProfile.StackLevel = -1;
  2087. if(maxProfile.ChargingProfileId == -1)
  2088. DEBUG_INFO("MaxProfile found.\n");
  2089. else
  2090. DEBUG_INFO("MaxProfile updated.\n");
  2091. // Required item
  2092. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2093. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2094. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2095. if(isUnitA)
  2096. {
  2097. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2098. 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++)
  2099. {
  2100. 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"));
  2101. 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?
  2102. 3:
  2103. 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")));
  2104. 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")));
  2105. }
  2106. }
  2107. else
  2108. {
  2109. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2110. 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++)
  2111. {
  2112. 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"));
  2113. 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?
  2114. 3:
  2115. 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")));
  2116. 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));
  2117. }
  2118. }
  2119. // Optional item
  2120. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2121. {
  2122. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2123. }
  2124. else
  2125. {
  2126. sprintf((char*)maxProfile.ValidFrom, " ");
  2127. }
  2128. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2129. {
  2130. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2131. }
  2132. else
  2133. {
  2134. sprintf((char*)maxProfile.ValidTo, " ");
  2135. }
  2136. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2137. {
  2138. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2139. }
  2140. else
  2141. {
  2142. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2143. }
  2144. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2145. {
  2146. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2147. }
  2148. else
  2149. {
  2150. maxProfile.TransactionId = -1;
  2151. }
  2152. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2153. {
  2154. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2155. }
  2156. else
  2157. {
  2158. maxProfile.ChargingSchedule.Duration = 86400;
  2159. }
  2160. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2161. {
  2162. 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")));
  2163. }
  2164. else
  2165. {
  2166. 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));
  2167. }
  2168. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2169. {
  2170. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2171. }
  2172. else
  2173. {
  2174. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2175. }
  2176. }
  2177. }
  2178. }
  2179. else
  2180. {
  2181. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2182. {
  2183. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2184. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2185. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2186. }
  2187. maxProfile.ChargingProfileId = -1;
  2188. maxProfile.StackLevel = -1;
  2189. if(maxProfile.ChargingProfileId == -1)
  2190. DEBUG_INFO("MaxProfile found.\n");
  2191. else
  2192. DEBUG_INFO("MaxProfile updated.\n");
  2193. // Required item
  2194. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2195. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2196. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2197. if(isUnitA)
  2198. {
  2199. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2200. 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++)
  2201. {
  2202. 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"));
  2203. 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?
  2204. 3:
  2205. 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")));
  2206. 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")));
  2207. }
  2208. }
  2209. else
  2210. {
  2211. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2212. 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++)
  2213. {
  2214. 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"));
  2215. 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?
  2216. 3:
  2217. 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")));
  2218. 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));
  2219. }
  2220. }
  2221. // Optional item
  2222. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2223. {
  2224. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2225. }
  2226. else
  2227. {
  2228. sprintf((char*)maxProfile.ValidFrom, " ");
  2229. }
  2230. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2231. {
  2232. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2233. }
  2234. else
  2235. {
  2236. sprintf((char*)maxProfile.ValidTo, " ");
  2237. }
  2238. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2239. {
  2240. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2241. }
  2242. else
  2243. {
  2244. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2245. }
  2246. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2247. {
  2248. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2249. }
  2250. else
  2251. {
  2252. maxProfile.TransactionId = -1;
  2253. }
  2254. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2255. {
  2256. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2257. }
  2258. else
  2259. {
  2260. maxProfile.ChargingSchedule.Duration = 86400;
  2261. }
  2262. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2263. {
  2264. 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")));
  2265. }
  2266. else
  2267. {
  2268. 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));
  2269. }
  2270. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2271. {
  2272. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2273. }
  2274. else
  2275. {
  2276. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2277. }
  2278. }
  2279. }
  2280. }
  2281. json_object_put(obj);
  2282. }
  2283. fclose(fp);
  2284. /*
  2285. if(maxProfile.ChargingProfileId !=-1)
  2286. {
  2287. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2288. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2289. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2290. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2291. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2292. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2293. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2294. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2295. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2296. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2297. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2299. {
  2300. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2301. {
  2302. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2303. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2304. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2305. }
  2306. }
  2307. }
  2308. else
  2309. DEBUG_INFO("MaxProfile not found.\n");
  2310. DEBUG_INFO("------------------------------------\n");*/
  2311. }
  2312. /*
  2313. * Align found profile start schedule & periods
  2314. */
  2315. //DEBUG_INFO("====================================\n");
  2316. /*
  2317. // For local test usage, force modify found profile start schedule info
  2318. 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);
  2319. 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);
  2320. 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);
  2321. */
  2322. if(txProfile.ChargingProfileId != -1)
  2323. {
  2324. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2325. {
  2326. if(txProfile.ChargingSchedule.Duration != -1)
  2327. {
  2328. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2329. 0:
  2330. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2331. }
  2332. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2333. {
  2334. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2335. {
  2336. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2337. 0:
  2338. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2339. if(idxPeriod > 0)
  2340. {
  2341. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2342. {
  2343. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2350. {
  2351. if(txProfile.ChargingSchedule.Duration != -1)
  2352. {
  2353. 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?
  2354. 0:
  2355. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2356. }
  2357. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2358. {
  2359. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2360. {
  2361. 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?
  2362. 0:
  2363. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2364. if(idxPeriod > 0)
  2365. {
  2366. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2367. {
  2368. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2369. }
  2370. }
  2371. }
  2372. }
  2373. }
  2374. else
  2375. {
  2376. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2377. {
  2378. if(txProfile.ChargingSchedule.Duration != -1)
  2379. {
  2380. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2381. 0:
  2382. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2383. }
  2384. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2385. {
  2386. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2387. {
  2388. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2389. 0:
  2390. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2391. if(idxPeriod > 0)
  2392. {
  2393. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2394. {
  2395. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2396. }
  2397. }
  2398. }
  2399. }
  2400. }
  2401. else
  2402. {
  2403. if(txProfile.ChargingSchedule.Duration != -1)
  2404. {
  2405. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2406. 0:
  2407. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2408. }
  2409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2410. {
  2411. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2412. {
  2413. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2414. 0:
  2415. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2416. if(idxPeriod > 0)
  2417. {
  2418. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2419. {
  2420. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. /*
  2428. DEBUG_INFO("txProfile after align.\n");
  2429. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2430. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2431. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2432. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2433. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2434. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2435. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2436. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2437. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2438. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2439. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2440. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2441. {
  2442. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2443. {
  2444. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2445. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2446. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2447. }
  2448. }*/
  2449. }
  2450. if(defaultTxProfile.ChargingProfileId != -1)
  2451. {
  2452. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2453. {
  2454. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2455. {
  2456. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2457. 0:
  2458. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2459. }
  2460. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2461. {
  2462. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2463. {
  2464. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2465. 0:
  2466. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2468. {
  2469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2470. }
  2471. if(idxPeriod > 0)
  2472. {
  2473. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2474. {
  2475. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2476. }
  2477. }
  2478. }
  2479. }
  2480. }
  2481. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2482. {
  2483. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2484. {
  2485. 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?
  2486. 0:
  2487. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2488. }
  2489. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2490. {
  2491. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2492. {
  2493. 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?
  2494. 0:
  2495. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2497. {
  2498. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2499. }
  2500. if(idxPeriod > 0)
  2501. {
  2502. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2503. {
  2504. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2505. }
  2506. }
  2507. }
  2508. }
  2509. }
  2510. else
  2511. {
  2512. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2513. {
  2514. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2515. {
  2516. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2517. 0:
  2518. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2519. }
  2520. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2521. {
  2522. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2523. {
  2524. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2525. 0:
  2526. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2528. {
  2529. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2530. }
  2531. if(idxPeriod > 0)
  2532. {
  2533. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2534. {
  2535. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2536. }
  2537. }
  2538. }
  2539. }
  2540. }
  2541. else
  2542. {
  2543. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2544. {
  2545. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2546. 0:
  2547. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2548. }
  2549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2550. {
  2551. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2552. {
  2553. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2554. 0:
  2555. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2557. {
  2558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2559. }
  2560. if(idxPeriod > 0)
  2561. {
  2562. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2563. {
  2564. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. }
  2571. /*
  2572. DEBUG_INFO("defaultTxProfile after align.\n");
  2573. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2574. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2575. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2576. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2577. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2578. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2579. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2580. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2581. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2582. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2583. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2584. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2585. {
  2586. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2587. {
  2588. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2589. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2590. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2591. }
  2592. }
  2593. DEBUG_INFO("------------------------------------\n");*/
  2594. }
  2595. if(maxProfile.ChargingProfileId != -1)
  2596. {
  2597. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2598. {
  2599. if(maxProfile.ChargingSchedule.Duration != -1)
  2600. {
  2601. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2602. 0:
  2603. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2604. }
  2605. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2606. {
  2607. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2608. {
  2609. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2610. 0:
  2611. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2612. if(idxPeriod > 0)
  2613. {
  2614. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2615. {
  2616. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2617. }
  2618. }
  2619. }
  2620. }
  2621. }
  2622. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2623. {
  2624. if(maxProfile.ChargingSchedule.Duration != -1)
  2625. {
  2626. 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?
  2627. 0:
  2628. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2629. }
  2630. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2631. {
  2632. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2633. {
  2634. 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?
  2635. 0:
  2636. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2637. if(idxPeriod > 0)
  2638. {
  2639. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2640. {
  2641. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2642. }
  2643. }
  2644. }
  2645. }
  2646. }
  2647. else
  2648. {
  2649. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2650. {
  2651. if(maxProfile.ChargingSchedule.Duration != -1)
  2652. {
  2653. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2654. 0:
  2655. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2656. }
  2657. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2658. {
  2659. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2660. {
  2661. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2662. 0:
  2663. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2664. if(idxPeriod > 0)
  2665. {
  2666. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2667. {
  2668. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2669. }
  2670. }
  2671. }
  2672. }
  2673. }
  2674. else
  2675. {
  2676. if(maxProfile.ChargingSchedule.Duration != -1)
  2677. {
  2678. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2679. 0:
  2680. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2681. }
  2682. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2683. {
  2684. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2685. {
  2686. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2687. 0:
  2688. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2689. if(idxPeriod > 0)
  2690. {
  2691. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2692. {
  2693. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2694. }
  2695. }
  2696. }
  2697. }
  2698. }
  2699. }
  2700. /*
  2701. DEBUG_INFO("MaxProfile after align.\n");
  2702. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2703. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2704. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2705. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2706. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2707. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2708. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2709. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2710. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2711. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2712. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2713. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2714. {
  2715. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2716. {
  2717. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2718. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2719. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2720. }
  2721. }
  2722. DEBUG_INFO("------------------------------------\n");*/
  2723. }
  2724. /*
  2725. * Merge to conposite schedule
  2726. */
  2727. //DEBUG_INFO("====================================\n");
  2728. // Find each profile period quantity
  2729. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2730. {
  2731. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2732. limitMax = idx+1;
  2733. }
  2734. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2735. {
  2736. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2737. limitDef = idx+1;
  2738. }
  2739. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2740. {
  2741. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2742. limitTx = idx+1;
  2743. }
  2744. // TxProfile found, composite schedule based on it
  2745. if(txProfile.ChargingProfileId != -1)
  2746. {
  2747. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2748. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2749. {
  2750. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2751. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2752. (txProfile.ChargingSchedule.Duration > 0))
  2753. {
  2754. if(maxProfile.ChargingProfileId != -1)
  2755. {
  2756. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2757. {
  2758. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2759. {
  2760. if((maxProfile.ChargingSchedule.Duration > 0))
  2761. {
  2762. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2763. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2764. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2765. }
  2766. else
  2767. {
  2768. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2769. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2770. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2771. }
  2772. }
  2773. if(idxMaxPeriod == (limitMax-1))
  2774. {
  2775. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2776. {
  2777. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2778. {
  2779. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2780. compositePeriodIdx++;
  2781. }
  2782. else
  2783. {
  2784. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2785. }
  2786. }
  2787. }
  2788. }
  2789. }
  2790. else
  2791. {
  2792. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2793. {
  2794. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2795. compositePeriodIdx++;
  2796. }
  2797. else
  2798. {
  2799. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2800. }
  2801. }
  2802. }
  2803. if(idxTxPeriod == (limitTx-1))
  2804. {
  2805. if(defaultTxProfile.ChargingProfileId != -1)
  2806. {
  2807. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2808. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2809. {
  2810. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2811. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2812. (defaultTxProfile.ChargingSchedule.Duration>0))
  2813. {
  2814. if(maxProfile.ChargingProfileId != -1)
  2815. {
  2816. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2817. {
  2818. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2819. {
  2820. if((maxProfile.ChargingSchedule.Duration > 0))
  2821. {
  2822. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2823. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2824. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2825. }
  2826. else
  2827. {
  2828. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2829. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2830. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2831. }
  2832. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2833. {
  2834. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2835. {
  2836. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2837. compositePeriodIdx++;
  2838. }
  2839. else
  2840. {
  2841. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2842. }
  2843. }
  2844. // Delete duplicate period
  2845. if(compositePeriodIdx > 1)
  2846. {
  2847. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2848. {
  2849. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2850. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2851. compositePeriodIdx -= 1;
  2852. }
  2853. }
  2854. }
  2855. else
  2856. {
  2857. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2858. {
  2859. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2860. compositePeriodIdx++;
  2861. }
  2862. else
  2863. {
  2864. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2865. }
  2866. break;
  2867. }
  2868. }
  2869. }
  2870. else
  2871. {
  2872. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2873. {
  2874. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2875. compositePeriodIdx++;
  2876. }
  2877. else
  2878. {
  2879. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2880. }
  2881. }
  2882. }
  2883. }
  2884. }
  2885. }
  2886. }
  2887. }
  2888. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2889. else if(defaultTxProfile.ChargingProfileId != -1)
  2890. {
  2891. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2892. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2893. {
  2894. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2895. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2896. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2897. {
  2898. if(maxProfile.ChargingProfileId != -1)
  2899. {
  2900. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2901. {
  2902. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2903. {
  2904. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2905. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2906. if((maxProfile.ChargingSchedule.Duration > 0))
  2907. {
  2908. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2909. }
  2910. else
  2911. {
  2912. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2913. }
  2914. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2915. {
  2916. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2919. compositePeriodIdx++;
  2920. }
  2921. else
  2922. {
  2923. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2924. }
  2925. }
  2926. // Delete duplicate period
  2927. if(compositePeriodIdx > 1)
  2928. {
  2929. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2930. {
  2931. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2932. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2933. compositePeriodIdx -= 1;
  2934. }
  2935. }
  2936. }
  2937. else
  2938. {
  2939. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2940. {
  2941. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2942. compositePeriodIdx++;
  2943. }
  2944. else
  2945. {
  2946. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2947. }
  2948. break;
  2949. }
  2950. }
  2951. }
  2952. else
  2953. {
  2954. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2955. {
  2956. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2957. compositePeriodIdx++;
  2958. }
  2959. else
  2960. {
  2961. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2962. }
  2963. }
  2964. }
  2965. }
  2966. }
  2967. // Fill other period by MaxProfile
  2968. if(maxProfile.ChargingProfileId != -1)
  2969. {
  2970. if(compositePeriodIdx==0)
  2971. {
  2972. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2973. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2974. {
  2975. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2976. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2977. (maxProfile.ChargingSchedule.Duration > 0))
  2978. {
  2979. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2980. {
  2981. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2982. compositePeriodIdx++;
  2983. }
  2984. else
  2985. {
  2986. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2987. }
  2988. }
  2989. }
  2990. }
  2991. else
  2992. {
  2993. int lastCompositePeriodIdx = compositePeriodIdx;
  2994. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2995. {
  2996. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2997. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2998. (maxProfile.ChargingSchedule.Duration > 0))
  2999. {
  3000. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3001. {
  3002. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3003. {
  3004. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3005. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3006. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3007. }
  3008. else
  3009. {
  3010. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3011. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3012. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3013. }
  3014. }
  3015. if(tmpPeriod.Limit != -1)
  3016. {
  3017. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3018. {
  3019. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3020. {
  3021. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3022. compositePeriodIdx++;
  3023. }
  3024. else
  3025. {
  3026. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3027. }
  3028. }
  3029. // Delete duplicate period
  3030. if(compositePeriodIdx > 1)
  3031. {
  3032. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3033. {
  3034. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3035. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3036. compositePeriodIdx -= 1;
  3037. }
  3038. }
  3039. }
  3040. }
  3041. }
  3042. }
  3043. }
  3044. compositeProfile->ChargingSchedule.Duration = durationReq;
  3045. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3046. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3047. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3048. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3049. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3050. {
  3051. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3052. {
  3053. compositeProfile->ChargingProfileId = 1;
  3054. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3055. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3056. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3057. }
  3058. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3059. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3060. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3061. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3062. }
  3063. if(line)
  3064. free(line);
  3065. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3066. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3067. }
  3068. //==========================================
  3069. // Init all share memory
  3070. //==========================================
  3071. int InitShareMemory()
  3072. {
  3073. int result = PASS;
  3074. int MeterSMId;
  3075. //creat ShmSysConfigAndInfo
  3076. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3077. {
  3078. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3079. result = FAIL;
  3080. }
  3081. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3082. {
  3083. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3084. result = FAIL;
  3085. }
  3086. else
  3087. {}
  3088. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3089. {
  3090. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3091. result = FAIL;
  3092. }
  3093. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3094. {
  3095. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3096. result = FAIL;
  3097. }
  3098. else
  3099. {}
  3100. //creat ShmPsuData
  3101. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3102. {
  3103. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3104. result = FAIL;
  3105. }
  3106. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3107. {
  3108. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3109. result = FAIL;
  3110. }
  3111. else
  3112. {}
  3113. //link ShmOCPP16Data
  3114. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3115. {
  3116. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3117. result = FAIL;
  3118. }
  3119. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3120. {
  3121. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3122. result = FAIL;
  3123. }
  3124. else
  3125. {}
  3126. //creat ShmOCPP16DataPH
  3127. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3128. {
  3129. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3130. result = FAIL;
  3131. }
  3132. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3133. {
  3134. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3135. result = FAIL;
  3136. }
  3137. else
  3138. {}
  3139. /****************************** For Initial Settings************************************************/
  3140. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3141. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3142. // allocate Configuration memory address
  3143. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3144. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3145. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3146. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3147. //offline MeterValue Interval
  3148. TempMeterValueInterval = 0;
  3149. return result;
  3150. }
  3151. int ProcessShareMemory()
  3152. {
  3153. int result = PASS;
  3154. if(InitShareMemory() == FAIL)
  3155. {
  3156. DEBUG_ERROR("InitShareMemory NG\n");
  3157. if(ShmStatusCodeData!=NULL)
  3158. {
  3159. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3160. }
  3161. result = FAIL;
  3162. }
  3163. // Model name parsing
  3164. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3165. {
  3166. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3167. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3168. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3169. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3170. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3171. ) // 'D' means DC
  3172. {
  3173. // DO series
  3174. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3175. {
  3176. SystemInitial += 1;
  3177. gunTotalNumber += 1;
  3178. gunType[gun_index] = GUN_TYPE_DO;
  3179. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3180. {
  3181. case Gun_Type_Chademo:
  3182. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3183. break;
  3184. case Gun_Type_CCS_2:
  3185. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3186. break;
  3187. case Gun_Type_GB:
  3188. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3189. break;
  3190. case Gun_Type_AC:
  3191. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3192. break;
  3193. default:
  3194. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3195. break;
  3196. }
  3197. }
  3198. }
  3199. else
  3200. {
  3201. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3202. {
  3203. SystemInitial += 1;
  3204. gunTotalNumber += 1;
  3205. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3206. {
  3207. case Gun_Type_Chademo:
  3208. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3209. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3210. break;
  3211. case Gun_Type_CCS_2:
  3212. gunType[gun_index] = GUN_TYPE_CCS;
  3213. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3214. break;
  3215. case Gun_Type_GB:
  3216. gunType[gun_index] = GUN_TYPE_GBT;
  3217. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3218. break;
  3219. case Gun_Type_AC:
  3220. gunType[gun_index] = GUN_TYPE_AC;
  3221. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3222. break;
  3223. default:
  3224. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3225. break;
  3226. }
  3227. }
  3228. }
  3229. }
  3230. else
  3231. {
  3232. DEBUG_ERROR("Model name parsing fail.\n");
  3233. result = FAIL;
  3234. }
  3235. if(result != PASS)sleep(5);
  3236. return result;
  3237. }
  3238. void checkRemoteStart(uint8_t connectorIdInt)
  3239. {
  3240. uint8_t tempIndex;
  3241. int result = PASS;
  3242. char cmdBuf[512];
  3243. //check Transaction active
  3244. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3245. {
  3246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3247. {
  3248. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3249. }
  3250. else
  3251. {
  3252. tempIndex = connectorIdInt -1;
  3253. }
  3254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3255. {
  3256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3257. {
  3258. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3259. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3260. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3261. {
  3262. //Reserved
  3263. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3264. }
  3265. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3266. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3267. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3268. {
  3269. //Reserved
  3270. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3271. result = FAIL;
  3272. goto end;
  3273. }
  3274. else
  3275. {
  3276. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3277. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3278. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3279. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3280. {
  3281. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3282. result = FAIL;
  3283. goto end;
  3284. }
  3285. }//END FOR ELSE
  3286. }
  3287. }// END FOR CHAdeMO_QUANTITY
  3288. }
  3289. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3290. {
  3291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3292. {
  3293. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3294. }
  3295. else
  3296. {
  3297. tempIndex = connectorIdInt -1;
  3298. }
  3299. for (int index = 0; index < CCS_QUANTITY; index++)
  3300. {
  3301. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3302. {
  3303. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3304. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3305. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3306. {
  3307. //Reserved
  3308. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3309. }
  3310. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3311. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3312. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3313. {
  3314. //Reserved
  3315. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3316. result = FAIL;
  3317. goto end;
  3318. }
  3319. else
  3320. {
  3321. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3322. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3323. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3324. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3325. {
  3326. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3327. result = FAIL;
  3328. goto end;
  3329. }
  3330. }// END FOR ELSE
  3331. }
  3332. }// END FOR CCS_QUANTITY
  3333. }
  3334. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3335. {
  3336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3337. {
  3338. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3339. }
  3340. else
  3341. {
  3342. tempIndex = connectorIdInt -1;
  3343. }
  3344. for (int index = 0; index < GB_QUANTITY; index++)
  3345. {
  3346. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3347. {
  3348. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3349. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3350. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3351. {
  3352. //Reserved
  3353. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3354. }
  3355. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3356. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3357. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3358. {
  3359. //Reserved
  3360. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3361. result = FAIL;
  3362. goto end;
  3363. }
  3364. else
  3365. {
  3366. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3367. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3368. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3369. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3370. {
  3371. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3372. result = FAIL;
  3373. goto end;
  3374. }
  3375. }// END FOR ELSE
  3376. }
  3377. } // END FOR GB_QUANTITY
  3378. }
  3379. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3380. {
  3381. tempIndex = connectorIdInt -1;
  3382. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3383. {
  3384. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3385. {
  3386. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3387. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3388. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3389. {
  3390. //Reserved
  3391. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3392. }
  3393. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3394. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3395. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3396. {
  3397. //Reserved
  3398. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3399. result = FAIL;
  3400. goto end;
  3401. }
  3402. else
  3403. {
  3404. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3405. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3406. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3407. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3408. {
  3409. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3410. result = FAIL;
  3411. goto end;
  3412. }
  3413. }// END FOR ELSE
  3414. }
  3415. } // END FOR GB_QUANTITY
  3416. }
  3417. else
  3418. {
  3419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3420. {
  3421. tempIndex = 2;
  3422. }
  3423. else
  3424. {
  3425. tempIndex = connectorIdInt -1;
  3426. }
  3427. for (int index = 0; index < AC_QUANTITY; index++)
  3428. {
  3429. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3430. {
  3431. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3432. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3433. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3434. {
  3435. //Reserved
  3436. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3437. }
  3438. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3439. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3440. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3441. {
  3442. //Reserved
  3443. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3444. result = FAIL;
  3445. goto end;
  3446. }
  3447. else
  3448. {
  3449. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3450. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3451. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3452. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3453. {
  3454. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3455. result = FAIL;
  3456. goto end;
  3457. }
  3458. }//END FOR ELSE
  3459. }
  3460. }// END FOR AC_QUANTITY
  3461. }
  3462. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3463. {
  3464. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3465. {
  3466. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3467. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3468. {
  3469. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3470. system(cmdBuf);
  3471. }
  3472. }
  3473. else
  3474. {
  3475. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3476. result = FAIL;
  3477. }
  3478. }
  3479. end:
  3480. if(result == PASS)
  3481. {
  3482. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3483. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3484. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3485. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3487. }
  3488. }
  3489. void CheckSystemValue(void)
  3490. {
  3491. char filenmae[100]={0};
  3492. char str[100]={0};
  3493. int tempIndex = 0;
  3494. //===============================
  3495. // send Heartbeat
  3496. //===============================
  3497. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3498. {
  3499. //parameter for test
  3500. sendHeartbeatRequest(0);
  3501. //==============================================
  3502. // Reset Waiting Time
  3503. //==============================================
  3504. HeartBeatWithNOResponse += 2;
  3505. }
  3506. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3507. {
  3508. // ClockAlign MeterValue
  3509. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3510. {
  3511. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3512. {
  3513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3514. {
  3515. tempIndex = ((gun_index==2) ? 1: 0);
  3516. }
  3517. else
  3518. {
  3519. tempIndex = gun_index;
  3520. }
  3521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3522. {
  3523. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3524. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3525. {
  3526. reqClockAlignMeter[gun_index] = 1;
  3527. }
  3528. }// End for CHAdeMO
  3529. }
  3530. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3531. {
  3532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3533. {
  3534. tempIndex = ((gun_index==2) ? 1: 0);
  3535. }
  3536. else
  3537. {
  3538. tempIndex = gun_index;
  3539. }
  3540. for (int index = 0; index < CCS_QUANTITY; index++)
  3541. {
  3542. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3543. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3544. {
  3545. reqClockAlignMeter[gun_index] = 1;
  3546. }
  3547. } // End for CCS
  3548. }
  3549. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3550. {
  3551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3552. {
  3553. tempIndex = ((gun_index==2) ? 1: 0);
  3554. }
  3555. else
  3556. {
  3557. tempIndex = gun_index;
  3558. }
  3559. for (int index = 0; index < GB_QUANTITY; index++)
  3560. {
  3561. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3562. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3563. {
  3564. reqClockAlignMeter[gun_index] = 1;
  3565. }
  3566. }// End for GB
  3567. }
  3568. else if(gunType[gun_index] == GUN_TYPE_DO)
  3569. {
  3570. tempIndex = gun_index;
  3571. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3572. {
  3573. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3574. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3575. {
  3576. reqClockAlignMeter[gun_index] = 1;
  3577. }
  3578. }
  3579. }
  3580. else
  3581. {
  3582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3583. {
  3584. tempIndex = 2;
  3585. }
  3586. else
  3587. {
  3588. tempIndex = gun_index;
  3589. }
  3590. for (int index = 0; index < AC_QUANTITY; index++)
  3591. {
  3592. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3593. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3594. {
  3595. reqClockAlignMeter[gun_index] = 1;
  3596. }
  3597. }//End for AC
  3598. }
  3599. }
  3600. }
  3601. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3602. {
  3603. //==========================================
  3604. // Check remote start without connector id
  3605. //==========================================
  3606. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3607. {
  3608. int connectorIdInt = -1;
  3609. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3610. {
  3611. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3612. {
  3613. connectorIdInt = (gun_index+1);
  3614. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3615. checkRemoteStart(connectorIdInt);
  3616. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3617. break;
  3618. }
  3619. }
  3620. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3621. {
  3622. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3623. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3624. }
  3625. }
  3626. //==========================================
  3627. // csu trigger DataTransferReq
  3628. //==========================================
  3629. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3630. {
  3631. sendDataTransferRequest(gun_index);
  3632. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3633. }
  3634. //===============================
  3635. // CSU Trigger Authorize Request
  3636. //===============================
  3637. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3638. {
  3639. sendAuthorizeRequest(0);
  3640. authorizeRetryTimes = authorizeRetryTimes + 1;
  3641. if(authorizeRetryTimes < 3)
  3642. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3643. }
  3644. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3645. {
  3646. authorizeRetryTimes = 0;
  3647. SetOcppConnStatus(FALSE);
  3648. server_sign = FALSE;
  3649. }
  3650. 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))
  3651. {
  3652. sendAuthorizeRequest(0);
  3653. }
  3654. //==============================================
  3655. // Charger start transaction
  3656. //==============================================
  3657. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3658. {
  3659. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3660. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3661. sendStartTransactionRequest(gun_index);
  3662. refreshStartTimer(&clientTime.StartTransaction);
  3663. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3664. //storeTempStopTransaction(gun_index);
  3665. }
  3666. //==============================================
  3667. // Charger stop transaction
  3668. //==============================================
  3669. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3670. {
  3671. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3672. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3673. sendStopTransactionRequest(gun_index);
  3674. refreshStartTimer(&clientTime.StopTransaction);
  3675. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3676. }
  3677. //==============================================
  3678. // Charger status report
  3679. //==============================================
  3680. //--- Check Mode Change ---//
  3681. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3682. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3683. {
  3684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3685. {
  3686. tempIndex = ((gun_index==2) ? 1: 0);
  3687. }
  3688. else
  3689. {
  3690. tempIndex = gun_index;
  3691. }
  3692. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3693. {
  3694. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3695. {
  3696. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3697. {
  3698. // Sent unplug message for California pricing logic
  3699. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3700. {
  3701. uint8_t ts[20];
  3702. getNowDatetime(ts);
  3703. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3704. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3705. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3706. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3707. }
  3708. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3709. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3710. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3711. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3712. {
  3713. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3714. if((access(filenmae,F_OK))!=-1)
  3715. {
  3716. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3717. sprintf(str,"rm -f %s",filenmae);
  3718. system(str);
  3719. }
  3720. }
  3721. }
  3722. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3723. #if 1 // for TempStopTransaction
  3724. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3725. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3726. {
  3727. checkTempStopTransaction(gun_index);
  3728. }
  3729. #endif
  3730. }
  3731. }
  3732. }
  3733. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3734. {
  3735. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3736. {
  3737. tempIndex = ((gun_index==2) ? 1: 0);
  3738. }
  3739. else
  3740. {
  3741. tempIndex = gun_index;
  3742. }
  3743. for (int index = 0; index < CCS_QUANTITY; index++)
  3744. {
  3745. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3746. {
  3747. 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]*/ )
  3748. {
  3749. // Sent unplug message for California pricing logic
  3750. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3751. {
  3752. uint8_t ts[20];
  3753. getNowDatetime(ts);
  3754. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3755. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3756. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3757. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3758. }
  3759. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3760. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3761. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3762. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3763. {
  3764. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3765. if((access(filenmae,F_OK))!=-1)
  3766. {
  3767. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3768. sprintf(str,"rm -f %s",filenmae);
  3769. system(str);
  3770. }
  3771. }
  3772. }
  3773. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3774. #if 1 // for TempStopTransaction
  3775. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3776. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3777. {
  3778. checkTempStopTransaction(gun_index);
  3779. }
  3780. #endif
  3781. }
  3782. }
  3783. }
  3784. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3785. {
  3786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3787. {
  3788. tempIndex = ((gun_index==2) ? 1: 0);
  3789. }
  3790. else
  3791. {
  3792. tempIndex = gun_index;
  3793. }
  3794. for (int index = 0; index < GB_QUANTITY; index++)
  3795. {
  3796. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3797. {
  3798. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3799. {
  3800. // Sent unplug message for California pricing logic
  3801. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3802. {
  3803. uint8_t ts[20];
  3804. getNowDatetime(ts);
  3805. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3806. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3807. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3808. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3809. }
  3810. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3811. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3812. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3813. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3814. {
  3815. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3816. if((access(filenmae,F_OK))!=-1)
  3817. {
  3818. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3819. sprintf(str,"rm -f %s",filenmae);
  3820. system(str);
  3821. }
  3822. }
  3823. }
  3824. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3825. #if 1 // for TempStopTransaction
  3826. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3827. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3828. {
  3829. checkTempStopTransaction(gun_index);
  3830. }
  3831. #endif
  3832. }
  3833. }
  3834. }
  3835. else if(gunType[gun_index] == GUN_TYPE_DO)
  3836. {
  3837. tempIndex = gun_index;
  3838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3839. {
  3840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3841. {
  3842. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3843. {
  3844. // Sent unplug message for California pricing logic
  3845. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3846. {
  3847. uint8_t ts[20];
  3848. getNowDatetime(ts);
  3849. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3850. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3851. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3852. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3853. }
  3854. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3855. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3856. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3857. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  3858. {
  3859. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3860. if((access(filenmae,F_OK))!=-1)
  3861. {
  3862. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3863. sprintf(str,"rm -f %s",filenmae);
  3864. system(str);
  3865. }
  3866. }
  3867. }
  3868. 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);
  3869. #if 1 // for TempStopTransaction
  3870. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3871. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3872. {
  3873. checkTempStopTransaction(gun_index);
  3874. }
  3875. #endif
  3876. }
  3877. }
  3878. }
  3879. else
  3880. {
  3881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3882. {
  3883. tempIndex = 2;
  3884. }
  3885. else
  3886. {
  3887. tempIndex = gun_index;
  3888. }
  3889. for (int index = 0; index < AC_QUANTITY; index++)
  3890. {
  3891. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3892. {
  3893. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3894. {
  3895. // Sent unplug message for California pricing logic
  3896. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3897. {
  3898. uint8_t ts[20];
  3899. getNowDatetime(ts);
  3900. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3901. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3902. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3903. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3904. }
  3905. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3906. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3907. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3908. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3909. {
  3910. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3911. if((access(filenmae,F_OK))!=-1)
  3912. {
  3913. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3914. sprintf(str,"rm -f %s",filenmae);
  3915. system(str);
  3916. }
  3917. }
  3918. }
  3919. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3920. #if 1 // for TempStopTransaction
  3921. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3922. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3923. {
  3924. checkTempStopTransaction(gun_index);
  3925. }
  3926. #endif
  3927. }
  3928. }// END
  3929. }
  3930. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  3931. (
  3932. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3933. )
  3934. )
  3935. {
  3936. if(SystemInitial > 0)
  3937. SystemInitial -= 1;
  3938. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3939. sendStatusNotificationRequest(gun_index);
  3940. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  3941. }
  3942. //==============================================
  3943. // CSU Trigger Smart Charging Profilw
  3944. //==============================================
  3945. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3946. {
  3947. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3948. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3949. }
  3950. //==============================================
  3951. // Meter report
  3952. //==============================================
  3953. // Trigger MeterValue
  3954. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3955. {
  3956. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3957. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3958. }
  3959. // Clock-aligned Meter value
  3960. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  3961. {
  3962. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3963. reqClockAlignMeter[gun_index] = 0;
  3964. }
  3965. // Sample period MeterValue
  3966. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  3967. {
  3968. //check Transaction active
  3969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3970. {
  3971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3972. {
  3973. tempIndex = ((gun_index==2) ? 1: 0);
  3974. }
  3975. else
  3976. {
  3977. tempIndex = gun_index;
  3978. }
  3979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3980. {
  3981. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3982. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3983. {
  3984. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3985. {
  3986. reqSampleMeter[gun_index] = 1;
  3987. }
  3988. }
  3989. }// End for CHAdeMO
  3990. }
  3991. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3992. {
  3993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3994. {
  3995. tempIndex = ((gun_index==2) ? 1: 0);
  3996. }
  3997. else
  3998. {
  3999. tempIndex = gun_index;
  4000. }
  4001. for (int index = 0; index < CCS_QUANTITY; index++)
  4002. {
  4003. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4004. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4005. {
  4006. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4007. {
  4008. reqSampleMeter[gun_index] = 1;
  4009. }
  4010. }
  4011. } // End for CCS
  4012. }
  4013. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4014. {
  4015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4016. {
  4017. tempIndex = ((gun_index==2) ? 1: 0);
  4018. }
  4019. else
  4020. {
  4021. tempIndex = gun_index;
  4022. }
  4023. for (int index = 0; index < GB_QUANTITY; index++)
  4024. {
  4025. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4026. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4027. {
  4028. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4029. {
  4030. reqSampleMeter[gun_index] = 1;
  4031. }
  4032. }
  4033. }// End for GB
  4034. }
  4035. else if(gunType[gun_index] == GUN_TYPE_DO)
  4036. {
  4037. tempIndex = gun_index;
  4038. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4039. {
  4040. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4041. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4042. {
  4043. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4044. {
  4045. reqSampleMeter[gun_index] = 1;
  4046. }
  4047. }
  4048. }
  4049. }
  4050. else
  4051. {
  4052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4053. {
  4054. tempIndex = 2;
  4055. }
  4056. else
  4057. {
  4058. tempIndex = gun_index;
  4059. }
  4060. for (int index = 0; index < AC_QUANTITY; index++)
  4061. {
  4062. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4063. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4064. {
  4065. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4066. {
  4067. reqSampleMeter[gun_index] = 1;
  4068. }
  4069. }
  4070. }//End for AC
  4071. }
  4072. if(reqSampleMeter[gun_index] == 1)
  4073. {
  4074. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4075. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4076. //storeTempStopTransaction(gun_index);
  4077. reqSampleMeter[gun_index] = 0;
  4078. }
  4079. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4080. }
  4081. //==============================================
  4082. // Check Connector reserved
  4083. //==============================================
  4084. //===============================
  4085. // Check if Reserve is expired
  4086. //===============================
  4087. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4088. {
  4089. double diff_t;
  4090. struct tm tp;
  4091. // current time
  4092. time_t t = time(NULL);
  4093. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4094. tp.tm_isdst = -1;
  4095. time_t utc = mktime(&tp);
  4096. diff_t = difftime(utc, t);
  4097. if(diff_t <= 0)
  4098. {
  4099. DEBUG_INFO("reserve expired.\n");
  4100. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4101. }
  4102. }//END OF Check if Reserve is expired
  4103. //==========================================
  4104. // csu trigger FirmwareStatusNotificationReq
  4105. //==========================================
  4106. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4107. {
  4108. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4109. }
  4110. //==========================================
  4111. // csu trigger DiagnosticsStatusNotificationReq
  4112. //==========================================
  4113. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4114. {
  4115. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4116. }
  4117. //==========================================
  4118. // csu trigger CancelReservationConf
  4119. //==========================================
  4120. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4121. {
  4122. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4123. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4124. }
  4125. //==========================================
  4126. // csu trigger ChangeAvailabilityConf
  4127. //==========================================
  4128. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4129. {
  4130. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4131. }
  4132. //==========================================
  4133. // csu trigger UnlockConnectorConf
  4134. //==========================================
  4135. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4136. {
  4137. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4138. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4139. }
  4140. //==========================================
  4141. // csu trigger ReserveNowConf
  4142. //==========================================
  4143. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4144. {
  4145. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4146. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4147. }
  4148. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4149. {
  4150. sendSignCertificateRequest();
  4151. }
  4152. }
  4153. }
  4154. //==========================================
  4155. // send request routine
  4156. //==========================================
  4157. int sendAuthorizeRequest(int gun_index)
  4158. {
  4159. mtrace();
  4160. int result = FAIL;
  4161. char message[100]={0};
  4162. char guid[37];
  4163. char tempdata[65]={0};
  4164. DEBUG_INFO("sendAuthorizeRequest...\n");
  4165. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4166. //Local Authorize
  4167. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4168. {
  4169. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4170. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4171. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4172. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4173. result = PASS;
  4174. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4175. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4176. authorizeRetryTimes = 0;
  4177. return result;
  4178. }
  4179. 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))||
  4180. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4181. {
  4182. // Query from cache
  4183. DEBUG_INFO("Authorize from cache.\n");
  4184. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4185. // Query from list
  4186. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4187. {
  4188. DEBUG_INFO("Authorize from list.\n");
  4189. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4190. }
  4191. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4192. {
  4193. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4194. {
  4195. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4196. }
  4197. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4198. {
  4199. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4200. }
  4201. if(!GetOcppConnStatus())
  4202. {
  4203. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4204. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4205. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4206. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4207. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4208. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4209. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4210. authorizeRetryTimes = 0;
  4211. return result;
  4212. }
  4213. }
  4214. else
  4215. {
  4216. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4217. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4218. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4219. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4220. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4221. else
  4222. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4223. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4224. result = PASS;
  4225. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4226. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4227. authorizeRetryTimes = 0;
  4228. return result;
  4229. }
  4230. }
  4231. //initialize struct Authorize
  4232. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4233. //get data from shared memory
  4234. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4235. random_uuid(guid);
  4236. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4237. LWS_Send(message);
  4238. sprintf(tempdata, "Authorize,%d", gun_index);
  4239. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4240. {
  4241. result = PASS;
  4242. DEBUG_INFO("Authorize mapItem pass\n");
  4243. }
  4244. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4245. return result;
  4246. }
  4247. int sendBootNotificationRequest(void)
  4248. {
  4249. mtrace();
  4250. int result = FAIL;
  4251. char message[500]={0}, payload[700]={0};
  4252. char guid[37]={0};
  4253. char tempdata[65]={0};
  4254. // Fill BootNotification fields
  4255. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4256. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4257. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4258. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4259. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4260. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4261. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4262. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4263. ShmOCPP16DataPH->ChargeBoxId
  4264. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4265. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4266. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4267. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4268. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4269. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4270. random_uuid(guid);
  4271. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4272. LWS_Send(message);
  4273. sprintf(tempdata, "BootNotification,0");
  4274. 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*/)
  4275. {
  4276. result = PASS;
  4277. }
  4278. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4279. strcpy(queuedata,message);
  4280. return result;
  4281. }
  4282. int sendDataTransferRequest(int gun_index)
  4283. {
  4284. mtrace();
  4285. char message[1000]={0};
  4286. char guid[37]={0};
  4287. char tempdata[65]={0};
  4288. int result = FAIL;
  4289. random_uuid(guid);
  4290. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4291. MESSAGE_TYPE_CALL,
  4292. guid,
  4293. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4294. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4295. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4296. LWS_Send(message);
  4297. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4298. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4299. {
  4300. result = PASS;
  4301. DEBUG_INFO("DataTransfer mapItem pass\n");
  4302. }
  4303. return result;
  4304. }
  4305. int sendDiagnosticsStatusNotificationRequest(char *status)
  4306. {
  4307. mtrace();
  4308. int result = FAIL;
  4309. char message[110]={0};
  4310. char guid[37]={0};
  4311. char tempdata[65]={0};
  4312. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4313. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4314. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4315. random_uuid(guid);
  4316. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4317. LWS_SendNow(message);
  4318. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4319. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4320. {
  4321. result = PASS;
  4322. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4323. }
  4324. //#ifdef SystemLogMessage
  4325. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4326. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4327. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4328. //#endif
  4329. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4330. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4331. //record status
  4332. if(strcmp(status,"Idle")==0)
  4333. {
  4334. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4335. }
  4336. else if(strcmp(status,"Uploaded")==0)
  4337. {
  4338. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4339. }
  4340. else if(strcmp(status,"UploadFailed")==0)
  4341. {
  4342. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4343. }
  4344. else if(strcmp(status,"Uploading")==0)
  4345. {
  4346. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4347. }
  4348. return result;
  4349. }
  4350. int sendFirmwareStatusNotificationRequest(char *status)
  4351. {
  4352. mtrace();
  4353. int result = FAIL;
  4354. char message[110]={0};
  4355. char guid[37]={0};
  4356. char tempdata[65]={0};
  4357. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4358. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4359. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4360. random_uuid(guid);
  4361. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4362. LWS_SendNow(message);
  4363. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4364. 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*/)
  4365. {
  4366. result = PASS;
  4367. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4368. }
  4369. //#ifdef SystemLogMessage
  4370. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4371. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4372. //#endif
  4373. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4374. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4375. //record status
  4376. if(strcmp(status,"Downloaded")==0)
  4377. {
  4378. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4379. }
  4380. else if(strcmp(status,"DownloadFailed")==0)
  4381. {
  4382. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4383. }
  4384. else if(strcmp(status,"Downloading")==0)
  4385. {
  4386. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4387. }
  4388. else if(strcmp(status,"Idle")==0)
  4389. {
  4390. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4391. }
  4392. else if(strcmp(status,"InstallationFailed")==0)
  4393. {
  4394. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4395. }
  4396. else if(strcmp(status,"Installing")==0)
  4397. {
  4398. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4399. }
  4400. else if(strcmp(status,"Installed")==0)
  4401. {
  4402. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4403. }
  4404. return result;
  4405. }
  4406. int sendHeartbeatRequest(int gun_index)
  4407. {
  4408. mtrace();
  4409. int result = FAIL;
  4410. char message[80]={0};
  4411. char guid[37]={0};
  4412. char tempdata[65]={0};
  4413. random_uuid(guid);
  4414. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4415. , MESSAGE_TYPE_CALL
  4416. , guid );
  4417. LWS_Send(message);
  4418. sprintf(tempdata, "Heartbeat,%d", 0);
  4419. 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*/)
  4420. {
  4421. result = PASS;
  4422. }
  4423. return result;
  4424. }
  4425. int sendStartTransactionRequest(int gun_index)
  4426. {
  4427. mtrace();
  4428. int result = FAIL;
  4429. char message[250]={0};
  4430. char guid[37]={0};
  4431. struct timeval tmnow;
  4432. struct tm *tm;
  4433. char buf[28];//, usec_buf[6];
  4434. char tempdata[65]={0};
  4435. int tempIndex = 0;
  4436. DEBUG_INFO("sendStartTransactionRequest...\n");
  4437. gettimeofday(&tmnow, NULL);
  4438. time_t t;
  4439. t = time(NULL);
  4440. /*UTC time and date*/
  4441. tm = gmtime(&t);
  4442. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4443. #if 0 // remove temporally
  4444. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4445. strcat(buf,".");
  4446. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4447. strcat(buf,usec_buf);
  4448. #endif
  4449. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4450. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4451. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4452. // clear StartTransaction Response
  4453. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4454. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4455. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4456. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4457. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4458. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4459. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4460. {
  4461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4462. {
  4463. tempIndex = ((gun_index==2) ? 1: 0);
  4464. }
  4465. else
  4466. {
  4467. tempIndex = gun_index;
  4468. }
  4469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4470. {
  4471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4472. {
  4473. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4474. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4475. }
  4476. }
  4477. }
  4478. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4479. {
  4480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4481. {
  4482. tempIndex = ((gun_index==2) ? 1: 0);
  4483. }
  4484. else
  4485. {
  4486. tempIndex = gun_index;
  4487. }
  4488. for (int index = 0; index < CCS_QUANTITY; index++)
  4489. {
  4490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4491. {
  4492. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4493. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4494. }
  4495. }
  4496. }
  4497. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4498. {
  4499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4500. {
  4501. tempIndex = ((gun_index==2) ? 1: 0);
  4502. }
  4503. else
  4504. {
  4505. tempIndex = gun_index;
  4506. }
  4507. for (int index = 0; index < GB_QUANTITY; index++)
  4508. {
  4509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4510. {
  4511. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4512. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4513. }
  4514. }
  4515. }
  4516. else if(gunType[gun_index] == GUN_TYPE_DO)
  4517. {
  4518. tempIndex = gun_index;
  4519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4520. {
  4521. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4522. {
  4523. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4524. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4525. }
  4526. }
  4527. }
  4528. else
  4529. {
  4530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4531. {
  4532. tempIndex = 2;
  4533. }
  4534. else
  4535. {
  4536. tempIndex = gun_index;
  4537. }
  4538. for (int index = 0; index < AC_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4541. {
  4542. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4543. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4544. }
  4545. }
  4546. }
  4547. random_uuid(guid);
  4548. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4549. {
  4550. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4551. , gun_index +1
  4552. , MESSAGE_TYPE_CALL
  4553. , guid
  4554. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4555. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4556. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4557. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4558. }
  4559. else
  4560. {
  4561. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4562. , gun_index +1
  4563. , MESSAGE_TYPE_CALL
  4564. , guid
  4565. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4566. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4567. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4568. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4569. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4570. }
  4571. #if 1
  4572. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4573. 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*/)
  4574. {
  4575. result = PASS;
  4576. }
  4577. #endif
  4578. strcpy(queuedata, message);
  4579. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4580. OCPP_insert_transaction_msg(YES, queuedata);
  4581. return result;
  4582. }
  4583. int sendStatusNotificationRequest(int gun_index)
  4584. {
  4585. mtrace();
  4586. int result = FAIL;
  4587. char message[600]={0};
  4588. char guid[37];
  4589. int currentStatus = 0;
  4590. struct timeval tmnow;
  4591. struct tm *tm;
  4592. char buf[28];//, usec_buf[6];
  4593. char tempdata[65]={0};
  4594. int tempIndex = 0;
  4595. uint8_t isStateChanged = TRUE;
  4596. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4597. gettimeofday(&tmnow, NULL);
  4598. time_t t;
  4599. t = time(NULL);
  4600. /*UTC time and date*/
  4601. tm = gmtime(&t);
  4602. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4603. #if 0 // remove temporally
  4604. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4605. strcat(buf,".");
  4606. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4607. strcat(buf,usec_buf);
  4608. #endif
  4609. //printf("%s",buf);
  4610. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4611. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4612. // it's option
  4613. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4614. /*
  4615. enum _SYSTEM_STATUS
  4616. {
  4617. S_BOOTING = 0,
  4618. S_IDLE, = 1
  4619. S_AUTHORIZING, =2
  4620. S_REASSIGN_CHECK, =3
  4621. S_REASSIGN, =4
  4622. S_PRECHARGE, =5
  4623. S_PREPARING_FOR_EV, =6
  4624. S_PREPARING_FOR_EVSE, =7
  4625. S_CHARGING, =8
  4626. S_TERMINATING, =9
  4627. S_COMPLETE, =10
  4628. S_ALARM, =11
  4629. S_FAULT =12
  4630. }
  4631. */
  4632. //check Transaction active
  4633. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4634. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4635. {
  4636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4637. {
  4638. tempIndex = ((gun_index==2) ? 1: 0);
  4639. }
  4640. else
  4641. {
  4642. tempIndex = gun_index;
  4643. }
  4644. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4645. {
  4646. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4647. {
  4648. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4649. {
  4650. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4651. {
  4652. currentStatus = Preparing; //OCPP Status: Preparing
  4653. }
  4654. else
  4655. {
  4656. currentStatus = Available; //OCPP Status: Available
  4657. }
  4658. }
  4659. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4660. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4661. ) //S_PRECHARGE
  4662. {
  4663. currentStatus = Preparing; //OCPP Status: Preparing
  4664. }
  4665. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4666. {
  4667. currentStatus = Charging; //OCPP Status: Charging
  4668. }
  4669. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4670. {
  4671. currentStatus = Finishing; //OCPP Status: Finishing
  4672. }
  4673. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4674. {
  4675. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4676. }
  4677. 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
  4678. {
  4679. currentStatus = Unavailable; //OCPP Status: Unavailable
  4680. }
  4681. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4682. {
  4683. currentStatus = Faulted; //OCPP Status: Faulted
  4684. }
  4685. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4686. {
  4687. currentStatus = Reserved; //OCPP Status: Reserved
  4688. }
  4689. } //end of the same index
  4690. }//end of for CHAdeMO_QUANTITY
  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. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4707. {
  4708. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4709. {
  4710. currentStatus = Preparing; //OCPP Status: Preparing
  4711. }
  4712. else
  4713. {
  4714. currentStatus = Available; //OCPP Status: Available
  4715. }
  4716. }
  4717. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4718. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4719. ) //S_PRECHARGE
  4720. {
  4721. currentStatus = Preparing; //OCPP Status: Preparing
  4722. }
  4723. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4724. {
  4725. currentStatus = Charging; //OCPP Status: Charging
  4726. }
  4727. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4728. {
  4729. currentStatus = Finishing; //OCPP Status: Finishing
  4730. }
  4731. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4732. {
  4733. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4734. }
  4735. 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
  4736. {
  4737. currentStatus = Unavailable; //OCPP Status : Unavailable
  4738. }
  4739. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4740. {
  4741. currentStatus = Faulted; //OCPP Status: Faulted
  4742. }
  4743. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4744. {
  4745. currentStatus = Reserved; //OCPP Status: Reserved
  4746. }
  4747. } //end of the same index
  4748. } // end of for CCS_QUANTITY
  4749. }
  4750. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4751. {
  4752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4753. {
  4754. tempIndex = ((gun_index==2) ? 1: 0);
  4755. }
  4756. else
  4757. {
  4758. tempIndex = gun_index;
  4759. }
  4760. for (int index = 0; index < GB_QUANTITY; index++)
  4761. {
  4762. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4763. {
  4764. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4765. {
  4766. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4767. {
  4768. currentStatus = Preparing; //OCPP Status: Preparing
  4769. }
  4770. else
  4771. {
  4772. currentStatus = Available; //OCPP Status: Available
  4773. }
  4774. }
  4775. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4776. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4777. ) //S_PRECHARGE
  4778. {
  4779. currentStatus = Preparing; //OCPP Status: Preparing
  4780. }
  4781. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4782. {
  4783. currentStatus = Charging; //OCPP Status: Charging
  4784. }
  4785. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4786. {
  4787. currentStatus = Finishing; //OCPP Status: Finishing
  4788. }
  4789. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4790. {
  4791. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4792. }
  4793. 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
  4794. {
  4795. currentStatus = Unavailable; //OCPP Status: Unavailable
  4796. }
  4797. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4798. {
  4799. currentStatus = Faulted; //OCPP Status: Faulted
  4800. }
  4801. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4802. {
  4803. currentStatus = Reserved; //OCPP Status: Reserved
  4804. }
  4805. } //end of the same index
  4806. } // end of for GB_QUANTITY
  4807. }
  4808. else if(gunType[gun_index] == GUN_TYPE_DO)
  4809. {
  4810. tempIndex = gun_index;
  4811. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4812. {
  4813. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4814. {
  4815. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4816. {
  4817. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4818. {
  4819. currentStatus = Preparing; //OCPP Status: Preparing
  4820. }
  4821. else
  4822. {
  4823. currentStatus = Available; //OCPP Status: Available
  4824. }
  4825. }
  4826. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4827. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4828. ) //S_PRECHARGE
  4829. {
  4830. currentStatus = Preparing; //OCPP Status: Preparing
  4831. }
  4832. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4833. {
  4834. currentStatus = Charging; //OCPP Status: Charging
  4835. }
  4836. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4837. {
  4838. currentStatus = Finishing; //OCPP Status: Finishing
  4839. }
  4840. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4841. {
  4842. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4843. }
  4844. 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
  4845. {
  4846. currentStatus = Unavailable; //OCPP Status: Unavailable
  4847. }
  4848. 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
  4849. {
  4850. currentStatus = Faulted; //OCPP Status: Faulted
  4851. }
  4852. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4853. {
  4854. currentStatus = Reserved; //OCPP Status: Reserved
  4855. }
  4856. } //end of the same index
  4857. }
  4858. }
  4859. else
  4860. {
  4861. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4862. {
  4863. tempIndex = 2;
  4864. }
  4865. else
  4866. {
  4867. tempIndex = gun_index;
  4868. }
  4869. for (int index = 0; index < AC_QUANTITY; index++)
  4870. {
  4871. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4872. {
  4873. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4874. {
  4875. 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))
  4876. {
  4877. currentStatus = Preparing; //OCPP Status: Preparing
  4878. }
  4879. else
  4880. {
  4881. currentStatus = Available; //OCPP Status: Available
  4882. }
  4883. }
  4884. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4885. {
  4886. currentStatus = Preparing; //OCPP Status: Preparing
  4887. }
  4888. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4889. {
  4890. currentStatus = Charging; //OCPP Status: Charging
  4891. }
  4892. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4893. {
  4894. currentStatus = Finishing; //OCPP Status: Finishing
  4895. }
  4896. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4897. {
  4898. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4899. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4900. else
  4901. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4902. }
  4903. 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
  4904. {
  4905. currentStatus = Unavailable; //OCPP Status: Unavailable
  4906. }
  4907. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4908. {
  4909. currentStatus = Faulted; //OCPP Status: Faulted
  4910. }
  4911. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4912. {
  4913. currentStatus = Reserved; //OCPP Status: Reserved
  4914. }
  4915. }//end of the same index
  4916. }//end of for AC_QUANTITY
  4917. }
  4918. //it's option
  4919. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4920. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4921. {
  4922. isStateChanged = FALSE;
  4923. }
  4924. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4925. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4926. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4927. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4928. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4929. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4930. random_uuid(guid);
  4931. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4932. , MESSAGE_TYPE_CALL
  4933. , guid
  4934. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4935. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4936. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4937. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4938. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4939. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4940. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4941. if((server_sign == TRUE) && isStateChanged)
  4942. {
  4943. LWS_Send(message);
  4944. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4945. 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*/)
  4946. {
  4947. //DEBUG_ERROR("statusNotification mapitem pass");
  4948. result = PASS;
  4949. }
  4950. }
  4951. else
  4952. {
  4953. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4954. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4955. result = PASS;
  4956. }
  4957. return result;
  4958. }
  4959. int sendStopTransactionRequest(int gun_index)
  4960. {
  4961. mtrace();
  4962. int result = FAIL;
  4963. //char message[1500]={0};
  4964. char guid[37]={0};
  4965. char tempdata[65]={0};
  4966. int tempIndex = 0;
  4967. char TempStopTransaction[256];
  4968. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4969. //int idx_sample=0;
  4970. DEBUG_INFO("sendStopTransactionRequest \n");
  4971. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4972. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4973. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4974. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4975. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4976. {
  4977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4978. {
  4979. tempIndex = ((gun_index==2) ? 1: 0);
  4980. }
  4981. else
  4982. {
  4983. tempIndex = gun_index;
  4984. }
  4985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4986. {
  4987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4988. {
  4989. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4990. }
  4991. }// END OF CHAdeMO_QUANTITY
  4992. }
  4993. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4994. {
  4995. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4996. {
  4997. tempIndex = ((gun_index==2) ? 1: 0);
  4998. }
  4999. else
  5000. {
  5001. tempIndex = gun_index;
  5002. }
  5003. for (int index = 0; index < CCS_QUANTITY; index++)
  5004. {
  5005. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5006. {
  5007. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5008. }
  5009. }// END OF CCS_QUANTITY
  5010. }
  5011. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5012. {
  5013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5014. {
  5015. tempIndex = ((gun_index==2) ? 1: 0);
  5016. }
  5017. else
  5018. {
  5019. tempIndex = gun_index;
  5020. }
  5021. for (int index = 0; index < GB_QUANTITY; index++)
  5022. {
  5023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5024. {
  5025. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5026. }
  5027. }// END OF GB_QUANTITY
  5028. }
  5029. else if(gunType[gun_index] == GUN_TYPE_DO)
  5030. {
  5031. tempIndex = gun_index;
  5032. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5033. {
  5034. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5035. {
  5036. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5037. }
  5038. }// END OF GB_QUANTITY
  5039. }
  5040. else
  5041. {
  5042. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5043. {
  5044. tempIndex = 2;
  5045. }
  5046. else
  5047. {
  5048. tempIndex = gun_index;
  5049. }
  5050. for (int index = 0; index < AC_QUANTITY; index++)
  5051. {
  5052. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5053. {
  5054. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5055. }
  5056. }// END OF AC_QUANTITY
  5057. }
  5058. //====================================== Stop Transaction Time =====================================================
  5059. struct timeval tmnow;
  5060. struct tm *tm;
  5061. char buf[28];//, usec_buf[6];
  5062. gettimeofday(&tmnow, NULL);
  5063. time_t t;
  5064. t = time(NULL);
  5065. /*UTC time and date*/
  5066. tm = gmtime(&t);
  5067. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5069. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5070. random_uuid(guid);
  5071. /***********************************transactionData******************************************************/
  5072. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5074. //=================================
  5075. // Transaction_Begin
  5076. //=================================
  5077. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5078. {
  5079. //============================================ Energy.Active.Import.Interval ================================
  5080. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5083. 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*/]);
  5084. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5085. 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))
  5086. {
  5087. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5088. }
  5089. else
  5090. {
  5091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5092. }
  5093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5095. }
  5096. //=================================
  5097. // Transaction_End
  5098. //=================================
  5099. // ================================= Current.Import L1 ===============================================
  5100. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5101. {
  5102. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5103. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5104. {
  5105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5106. {
  5107. tempIndex = ((gun_index==2) ? 1: 0);
  5108. }
  5109. else
  5110. {
  5111. tempIndex = gun_index;
  5112. }
  5113. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5114. {
  5115. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5116. {
  5117. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5118. }
  5119. }// End of for CHAdeMO_QUANTITY
  5120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5121. }
  5122. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5123. {
  5124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5125. {
  5126. tempIndex = ((gun_index==2) ? 1: 0);
  5127. }
  5128. else
  5129. {
  5130. tempIndex = gun_index;
  5131. }
  5132. for (int index = 0; index < CCS_QUANTITY; index++)
  5133. {
  5134. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5135. {
  5136. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5137. }
  5138. }// End of for CCS_QUANTITY
  5139. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5140. }
  5141. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5142. {
  5143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5144. {
  5145. tempIndex = ((gun_index==2) ? 1: 0);
  5146. }
  5147. else
  5148. {
  5149. tempIndex = gun_index;
  5150. }
  5151. for (int index = 0; index < GB_QUANTITY; index++)
  5152. {
  5153. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5154. {
  5155. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5156. }
  5157. }// End of for GB_QUANTITY
  5158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5159. }
  5160. else if(gunType[gun_index] == GUN_TYPE_DO)
  5161. {
  5162. tempIndex = gun_index;
  5163. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5164. {
  5165. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5166. {
  5167. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5168. }
  5169. }
  5170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5171. }
  5172. else
  5173. {
  5174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5175. {
  5176. tempIndex = 2;
  5177. }
  5178. else
  5179. {
  5180. tempIndex = gun_index;
  5181. }
  5182. for (int index = 0; index < AC_QUANTITY; index++)
  5183. {
  5184. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5185. {
  5186. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5187. }
  5188. }// End of for AC_QUANTITY
  5189. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5190. }
  5191. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5192. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5193. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5194. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5196. }
  5197. // ================================= Energy.Active.Import.Interval ==============================================
  5198. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5199. {
  5200. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5201. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5202. {
  5203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5204. {
  5205. tempIndex = ((gun_index==2) ? 1: 0);
  5206. }
  5207. else
  5208. {
  5209. tempIndex = gun_index;
  5210. }
  5211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5212. {
  5213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5214. {
  5215. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5216. }
  5217. }// END OF CHAdeMO_QUANTITY
  5218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5219. }
  5220. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5221. {
  5222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5223. {
  5224. tempIndex = ((gun_index==2) ? 1: 0);
  5225. }
  5226. else
  5227. {
  5228. tempIndex = gun_index;
  5229. }
  5230. for (int index = 0; index < CCS_QUANTITY; index++)
  5231. {
  5232. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5233. {
  5234. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5235. }
  5236. }// END OF CCS_QUANTITY
  5237. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5238. }
  5239. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5240. {
  5241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5242. {
  5243. tempIndex = ((gun_index==2) ? 1: 0);
  5244. }
  5245. else
  5246. {
  5247. tempIndex = gun_index;
  5248. }
  5249. for (int index = 0; index < GB_QUANTITY; index++)
  5250. {
  5251. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5252. {
  5253. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5254. }
  5255. }// END OF GB_QUANTITY
  5256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5257. }
  5258. else if(gunType[gun_index] == GUN_TYPE_DO)
  5259. {
  5260. tempIndex = gun_index;
  5261. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5262. {
  5263. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5264. {
  5265. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5266. }
  5267. }
  5268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5269. }
  5270. else
  5271. {
  5272. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5273. {
  5274. tempIndex = 2;
  5275. }
  5276. else
  5277. {
  5278. tempIndex = gun_index;
  5279. }
  5280. for (int index = 0; index < AC_QUANTITY; index++)
  5281. {
  5282. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5283. {
  5284. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5285. }
  5286. }// END OF AC_QUANTITY
  5287. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5288. }
  5289. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5290. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5291. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5292. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5293. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5294. }
  5295. //=================================== Power.Active.Import ==================================================
  5296. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5297. {
  5298. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5299. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5300. {
  5301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5302. {
  5303. tempIndex = ((gun_index==2) ? 1: 0);
  5304. }
  5305. else
  5306. {
  5307. tempIndex = gun_index;
  5308. }
  5309. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5310. {
  5311. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5312. {
  5313. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5314. }
  5315. } // End for CHAdeMO_QUANTITY
  5316. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5317. }
  5318. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5319. {
  5320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5321. {
  5322. tempIndex = ((gun_index==2) ? 1: 0);
  5323. }
  5324. else
  5325. {
  5326. tempIndex = gun_index;
  5327. }
  5328. for (int index = 0; index < CCS_QUANTITY; index++)
  5329. {
  5330. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5331. {
  5332. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5333. }
  5334. } // END for CCS_QUANTITY
  5335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5336. }
  5337. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5338. {
  5339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5340. {
  5341. tempIndex = ((gun_index==2) ? 1: 0);
  5342. }
  5343. else
  5344. {
  5345. tempIndex = gun_index;
  5346. }
  5347. for (int index = 0; index < GB_QUANTITY; index++)
  5348. {
  5349. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5350. {
  5351. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5352. }
  5353. }// END for GB_QUANTITY
  5354. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5355. }
  5356. else if(gunType[gun_index] == GUN_TYPE_DO)
  5357. {
  5358. tempIndex = gun_index;
  5359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5360. {
  5361. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5362. {
  5363. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5364. }
  5365. }
  5366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5367. }
  5368. else
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5371. {
  5372. tempIndex = 2;
  5373. }
  5374. else
  5375. {
  5376. tempIndex = gun_index;
  5377. }
  5378. for (int index = 0; index < AC_QUANTITY; index++)
  5379. {
  5380. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5381. {
  5382. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5383. }
  5384. } // END for AC_QUANTITY
  5385. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5386. }
  5387. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5388. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5389. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5390. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5392. }
  5393. //============================ Voltage L1 ====================================
  5394. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5395. {
  5396. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5397. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5398. {
  5399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5400. {
  5401. tempIndex = ((gun_index==2) ? 1: 0);
  5402. }
  5403. else
  5404. {
  5405. tempIndex = gun_index;
  5406. }
  5407. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5408. {
  5409. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5410. {
  5411. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5412. }
  5413. } // END OF FOR CHAdeMO_QUANTITY
  5414. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5415. }
  5416. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5417. {
  5418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5419. {
  5420. tempIndex = ((gun_index==2) ? 1: 0);
  5421. }
  5422. else
  5423. {
  5424. tempIndex = gun_index;
  5425. }
  5426. for (int index = 0; index < CCS_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5429. {
  5430. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5431. }
  5432. } // END OF FOR CCS_QUANTITY
  5433. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5434. }
  5435. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5436. {
  5437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5438. {
  5439. tempIndex = ((gun_index==2) ? 1: 0);
  5440. }
  5441. else
  5442. {
  5443. tempIndex = gun_index;
  5444. }
  5445. for (int index = 0; index < GB_QUANTITY; index++)
  5446. {
  5447. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5448. {
  5449. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5450. }
  5451. } // END OF FOR GB_QUANTITY
  5452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5453. }
  5454. else if(gunType[gun_index] == GUN_TYPE_DO)
  5455. {
  5456. tempIndex = gun_index;
  5457. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5458. {
  5459. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5460. {
  5461. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5462. }
  5463. }
  5464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5465. }
  5466. else
  5467. {
  5468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5469. {
  5470. tempIndex = 2;
  5471. }
  5472. else
  5473. {
  5474. tempIndex = gun_index;
  5475. }
  5476. for (int index = 0; index < AC_QUANTITY; index++)
  5477. {
  5478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5479. {
  5480. 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
  5481. }
  5482. } // END OF FOR AC_QUANTITY
  5483. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5484. }
  5485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5489. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5490. }
  5491. //====================== End SoC ================================
  5492. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5493. {
  5494. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5495. 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))
  5496. {
  5497. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5498. {
  5499. tempIndex = ((gun_index==2) ? 1: 0);
  5500. }
  5501. else
  5502. {
  5503. tempIndex = gun_index;
  5504. }
  5505. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5506. {
  5507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5510. {
  5511. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5512. }
  5513. }
  5514. }
  5515. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5516. {
  5517. for (int index = 0; index < CCS_QUANTITY; index++)
  5518. {
  5519. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5520. {
  5521. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5522. }
  5523. }
  5524. }
  5525. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5526. {
  5527. for (int index = 0; index < GB_QUANTITY; index++)
  5528. {
  5529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5530. {
  5531. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5532. }
  5533. }
  5534. }
  5535. else if(gunType[gun_index] == GUN_TYPE_DO)
  5536. {
  5537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5538. {
  5539. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5540. {
  5541. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5542. }
  5543. }
  5544. }
  5545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5546. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5548. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5550. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5551. } // END FOR DC CASE
  5552. }
  5553. // ================================= Current.Import L2 ===============================================
  5554. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5555. {
  5556. // AC 3 phse L2 current
  5557. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5558. {
  5559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5560. {
  5561. tempIndex = 2;
  5562. }
  5563. else
  5564. {
  5565. tempIndex = gun_index;
  5566. }
  5567. for (int index = 0; index < AC_QUANTITY; index++)
  5568. {
  5569. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5570. {
  5571. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5572. }
  5573. }// End of for AC_QUANTITY
  5574. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5575. }
  5576. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5577. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5579. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5581. }
  5582. // ================================= Current.Import L3 ===============================================
  5583. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5584. {
  5585. // AC 3 phse L3 current
  5586. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5587. {
  5588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5589. {
  5590. tempIndex = 2;
  5591. }
  5592. else
  5593. {
  5594. tempIndex = gun_index;
  5595. }
  5596. for (int index = 0; index < AC_QUANTITY; index++)
  5597. {
  5598. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5599. {
  5600. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5601. }
  5602. }// End of for AC_QUANTITY
  5603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5604. }
  5605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5610. }
  5611. //============================ Voltage L2 ====================================
  5612. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5613. {
  5614. // AC 3 phse L2 voltage
  5615. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5616. {
  5617. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5618. {
  5619. tempIndex = 2;
  5620. }
  5621. else
  5622. {
  5623. tempIndex = gun_index;
  5624. }
  5625. for (int index = 0; index < AC_QUANTITY; index++)
  5626. {
  5627. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5628. {
  5629. 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
  5630. }
  5631. } // END OF FOR AC_QUANTITY
  5632. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5633. }
  5634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5635. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5636. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5637. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5638. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5639. }
  5640. //============================ Voltage L3 ====================================
  5641. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5642. {
  5643. // AC 3 phse L3 voltage
  5644. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5645. {
  5646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5647. {
  5648. tempIndex = 2;
  5649. }
  5650. else
  5651. {
  5652. tempIndex = gun_index;
  5653. }
  5654. for (int index = 0; index < AC_QUANTITY; index++)
  5655. {
  5656. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5657. {
  5658. 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
  5659. }
  5660. } // END OF FOR AC_QUANTITY
  5661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5662. }
  5663. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5664. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5665. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5666. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5667. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5668. }
  5669. //====================== Start SoC ================================
  5670. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5671. {
  5672. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5673. 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))
  5674. {
  5675. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5676. {
  5677. tempIndex = ((gun_index==2) ? 1: 0);
  5678. }
  5679. else
  5680. {
  5681. tempIndex = gun_index;
  5682. }
  5683. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5684. {
  5685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5686. {
  5687. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5688. {
  5689. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5690. }
  5691. }
  5692. }
  5693. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5694. {
  5695. for (int index = 0; index < CCS_QUANTITY; index++)
  5696. {
  5697. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5698. {
  5699. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5700. }
  5701. }
  5702. }
  5703. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5704. {
  5705. for (int index = 0; index < GB_QUANTITY; index++)
  5706. {
  5707. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5708. {
  5709. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5710. }
  5711. }
  5712. }
  5713. else if(gunType[gun_index] == GUN_TYPE_DO)
  5714. {
  5715. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5716. {
  5717. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5718. {
  5719. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5720. }
  5721. }
  5722. }
  5723. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5724. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5725. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5727. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5729. } // END FOR DC CASE
  5730. }
  5731. //================================================ Message create ====================================================
  5732. json_object *StopTransaction = json_object_new_object();
  5733. json_object *transactionDatas = json_object_new_array();
  5734. json_object *sampledValues = json_object_new_array();
  5735. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5736. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5737. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5738. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5739. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5740. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5741. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5742. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5743. {
  5744. json_object *transactionData = json_object_new_object();
  5745. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5746. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5747. {
  5748. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5749. {
  5750. json_object *sampledValue = json_object_new_object();
  5751. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5752. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5753. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5754. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5755. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5756. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5757. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5758. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5759. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5760. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5761. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5762. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5763. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5764. json_object_array_add(sampledValues, sampledValue);
  5765. }
  5766. }
  5767. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5768. json_object_array_add(transactionDatas, transactionData);
  5769. }
  5770. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5771. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5772. ,MESSAGE_TYPE_CALL
  5773. ,guid
  5774. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5775. json_object_put(StopTransaction);
  5776. #if 1 // for TempStopTransaction
  5777. //Delete TempStopTransaction
  5778. if((access(TempStopTransaction,F_OK))!=-1)
  5779. {
  5780. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5781. }
  5782. #endif
  5783. #if 1
  5784. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5785. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5786. {
  5787. result = PASS;
  5788. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5789. }
  5790. #endif
  5791. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5792. OCPP_insert_transaction_msg(NO, queuedata);
  5793. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5794. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5795. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5796. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5797. {
  5798. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5799. }
  5800. //for test
  5801. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5802. return result;
  5803. }
  5804. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5805. {
  5806. mtrace();
  5807. int result = FAIL;
  5808. char guid[37]={0};
  5809. char tempdata[65]={0};
  5810. int tempIndex = 0;
  5811. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5812. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5813. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5814. //set value
  5815. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5816. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5817. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5818. -1);
  5819. random_uuid(guid);
  5820. //UTC Date time
  5821. struct timeval tmnow;
  5822. struct tm *tm;
  5823. char buf[28];//, usec_buf[6];
  5824. gettimeofday(&tmnow, NULL);
  5825. time_t t;
  5826. t = time(NULL);
  5827. /*UTC time and date*/
  5828. tm = gmtime(&t);
  5829. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5830. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5831. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5832. //********************************(1)Current.Import L1************************************************/
  5833. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5834. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5835. (dataType == ReadingContext_Trigger))
  5836. {
  5837. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5838. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5839. {
  5840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5841. {
  5842. tempIndex = ((gun_index==2) ? 1: 0);
  5843. }
  5844. else
  5845. {
  5846. tempIndex = gun_index;
  5847. }
  5848. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5849. {
  5850. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5851. {
  5852. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5853. }
  5854. }
  5855. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5856. }
  5857. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5858. {
  5859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5860. {
  5861. tempIndex = ((gun_index==2) ? 1: 0);
  5862. }
  5863. else
  5864. {
  5865. tempIndex = gun_index;
  5866. }
  5867. for (int index = 0; index < CCS_QUANTITY; index++)
  5868. {
  5869. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5870. {
  5871. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5872. }
  5873. }
  5874. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5875. }
  5876. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5877. {
  5878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5879. {
  5880. tempIndex = ((gun_index==2) ? 1: 0);
  5881. }
  5882. else
  5883. {
  5884. tempIndex = gun_index;
  5885. }
  5886. for (int index = 0; index < GB_QUANTITY; index++)
  5887. {
  5888. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5889. {
  5890. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5891. }
  5892. }
  5893. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5894. }
  5895. else if(gunType[gun_index] == GUN_TYPE_DO)
  5896. {
  5897. tempIndex = gun_index;
  5898. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5899. {
  5900. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5901. {
  5902. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5903. }
  5904. }
  5905. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5906. }
  5907. else
  5908. {
  5909. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5910. {
  5911. tempIndex = 2;
  5912. }
  5913. else
  5914. {
  5915. tempIndex = gun_index;
  5916. }
  5917. for (int index = 0; index < AC_QUANTITY; index++)
  5918. {
  5919. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5920. {
  5921. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5922. }
  5923. }
  5924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5925. }
  5926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5927. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5929. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5930. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5931. }
  5932. //********************************(2)Energy.Active.Import.Register ************************************************/
  5933. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5934. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5935. (dataType == ReadingContext_Trigger))
  5936. {
  5937. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5939. {
  5940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5941. {
  5942. tempIndex = ((gun_index==2) ? 1: 0);
  5943. }
  5944. else
  5945. {
  5946. tempIndex = gun_index;
  5947. }
  5948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5949. {
  5950. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5951. {
  5952. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5953. }
  5954. }
  5955. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5956. }
  5957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5958. {
  5959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5960. {
  5961. tempIndex = ((gun_index==2) ? 1: 0);
  5962. }
  5963. else
  5964. {
  5965. tempIndex = gun_index;
  5966. }
  5967. for (int index = 0; index < CCS_QUANTITY; index++)
  5968. {
  5969. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5970. {
  5971. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5972. }
  5973. }
  5974. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5975. }
  5976. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5977. {
  5978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5979. {
  5980. tempIndex = ((gun_index==2) ? 1: 0);
  5981. }
  5982. else
  5983. {
  5984. tempIndex = gun_index;
  5985. }
  5986. for (int index = 0; index < GB_QUANTITY; index++)
  5987. {
  5988. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5989. {
  5990. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5991. }
  5992. }
  5993. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5994. }
  5995. else if(gunType[gun_index] == GUN_TYPE_DO)
  5996. {
  5997. tempIndex = gun_index;
  5998. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5999. {
  6000. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6001. {
  6002. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6003. }
  6004. }
  6005. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6006. }
  6007. else
  6008. {
  6009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6010. {
  6011. tempIndex = 2;
  6012. }
  6013. else
  6014. {
  6015. tempIndex = gun_index;
  6016. }
  6017. for (int index = 0; index < AC_QUANTITY; index++)
  6018. {
  6019. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6020. {
  6021. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6022. }
  6023. }
  6024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6025. }
  6026. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6027. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6028. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6031. }
  6032. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6033. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6034. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6035. (dataType == ReadingContext_Trigger))
  6036. {
  6037. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6038. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6039. {
  6040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6041. {
  6042. tempIndex = ((gun_index==2) ? 1: 0);
  6043. }
  6044. else
  6045. {
  6046. tempIndex = gun_index;
  6047. }
  6048. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6049. {
  6050. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6051. {
  6052. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6053. }
  6054. } // END OF FOR CHAdeMO_QUANTITY
  6055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6056. }
  6057. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6058. {
  6059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6060. {
  6061. tempIndex = ((gun_index==2) ? 1: 0);
  6062. }
  6063. else
  6064. {
  6065. tempIndex = gun_index;
  6066. }
  6067. for (int index = 0; index < CCS_QUANTITY; index++)
  6068. {
  6069. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6070. {
  6071. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6072. }
  6073. } // END OF CCS_QUANTITY
  6074. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6075. }
  6076. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6077. {
  6078. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6079. {
  6080. tempIndex = ((gun_index==2) ? 1: 0);
  6081. }
  6082. else
  6083. {
  6084. tempIndex = gun_index;
  6085. }
  6086. for (int index = 0; index < GB_QUANTITY; index++)
  6087. {
  6088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6089. {
  6090. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6091. }
  6092. } // END OF GB_QUANTITY
  6093. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6094. }
  6095. else if(gunType[gun_index] == GUN_TYPE_DO)
  6096. {
  6097. tempIndex = gun_index;
  6098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6099. {
  6100. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6101. {
  6102. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6103. }
  6104. }
  6105. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6106. }
  6107. else
  6108. {
  6109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6110. {
  6111. tempIndex = 2;
  6112. }
  6113. else
  6114. {
  6115. tempIndex = gun_index;
  6116. }
  6117. for (int index = 0; index < AC_QUANTITY; index++)
  6118. {
  6119. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6120. {
  6121. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6122. }
  6123. }
  6124. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6125. }
  6126. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6127. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6128. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6129. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6130. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6131. }
  6132. //********************************(4)Power.Active.Import************************************************/
  6133. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6134. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6135. (dataType == ReadingContext_Trigger))
  6136. {
  6137. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6138. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6139. {
  6140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6141. {
  6142. tempIndex = ((gun_index==2) ? 1: 0);
  6143. }
  6144. else
  6145. {
  6146. tempIndex = gun_index;
  6147. }
  6148. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6149. {
  6150. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6151. {
  6152. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6153. }
  6154. } // END OF FOR
  6155. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6156. }
  6157. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6158. {
  6159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6160. {
  6161. tempIndex = ((gun_index==2) ? 1: 0);
  6162. }
  6163. else
  6164. {
  6165. tempIndex = gun_index;
  6166. }
  6167. for (int index = 0; index < CCS_QUANTITY; index++)
  6168. {
  6169. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6170. {
  6171. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6172. }
  6173. }
  6174. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6175. }
  6176. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6177. {
  6178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6179. {
  6180. tempIndex = ((gun_index==2) ? 1: 0);
  6181. }
  6182. else
  6183. {
  6184. tempIndex = gun_index;
  6185. }
  6186. for (int index = 0; index < GB_QUANTITY; index++)
  6187. {
  6188. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6189. {
  6190. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6191. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6192. }
  6193. }
  6194. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6195. }
  6196. else if(gunType[gun_index] == GUN_TYPE_DO)
  6197. {
  6198. tempIndex = gun_index;
  6199. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6202. {
  6203. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6204. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6205. }
  6206. }
  6207. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6208. }
  6209. else
  6210. {
  6211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6212. {
  6213. tempIndex = 2;
  6214. }
  6215. else
  6216. {
  6217. tempIndex = gun_index;
  6218. }
  6219. for (int index = 0; index < AC_QUANTITY; index++)
  6220. {
  6221. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6222. {
  6223. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6224. }
  6225. }
  6226. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6227. }
  6228. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6229. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6230. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6231. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6232. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6233. }
  6234. //***********************************************(5)VOLTAGE L1******************************************************/
  6235. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6236. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6237. (dataType == ReadingContext_Trigger))
  6238. {
  6239. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6240. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6241. {
  6242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6243. {
  6244. tempIndex = ((gun_index==2) ? 1: 0);
  6245. }
  6246. else
  6247. {
  6248. tempIndex = gun_index;
  6249. }
  6250. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6251. {
  6252. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6253. {
  6254. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6255. }
  6256. }
  6257. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6258. }
  6259. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6260. {
  6261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6262. {
  6263. tempIndex = ((gun_index==2) ? 1: 0);
  6264. }
  6265. else
  6266. {
  6267. tempIndex = gun_index;
  6268. }
  6269. for (int index = 0; index < CCS_QUANTITY; index++)
  6270. {
  6271. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6272. {
  6273. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6274. }
  6275. }
  6276. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6277. }
  6278. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6279. {
  6280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6281. {
  6282. tempIndex = ((gun_index==2) ? 1: 0);
  6283. }
  6284. else
  6285. {
  6286. tempIndex = gun_index;
  6287. }
  6288. for (int index = 0; index < GB_QUANTITY; index++)
  6289. {
  6290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6291. {
  6292. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6293. }
  6294. }
  6295. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6296. }
  6297. else if(gunType[gun_index] == GUN_TYPE_DO)
  6298. {
  6299. tempIndex = gun_index;
  6300. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6301. {
  6302. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6303. {
  6304. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6305. }
  6306. }
  6307. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6308. }
  6309. else
  6310. {
  6311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6312. {
  6313. tempIndex = 2;
  6314. }
  6315. else
  6316. {
  6317. tempIndex = gun_index;
  6318. }
  6319. for (int index = 0; index < AC_QUANTITY; index++)
  6320. {
  6321. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6322. {
  6323. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6324. }
  6325. }
  6326. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6327. }
  6328. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6329. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6330. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6331. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6332. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6333. }
  6334. //***********************************************(6)SOC******************************************************/
  6335. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6336. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6337. (dataType == ReadingContext_Trigger))
  6338. {
  6339. 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))
  6340. {
  6341. //idx_sample=5;
  6342. //sampledValue = NULL;
  6343. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6344. {
  6345. tempIndex = ((gun_index==2) ? 1: 0);
  6346. }
  6347. else
  6348. {
  6349. tempIndex = gun_index;
  6350. }
  6351. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6352. {
  6353. //tempIndex = ((gun_index==2) ? 1: 0);
  6354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6355. {
  6356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6357. {
  6358. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6359. }
  6360. }
  6361. }
  6362. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6363. {
  6364. //tempIndex = ((gun_index==2) ? 1: 0);
  6365. for (int index = 0; index < CCS_QUANTITY; index++)
  6366. {
  6367. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6368. {
  6369. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6370. }
  6371. }
  6372. }
  6373. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6374. {
  6375. //tempIndex = ((gun_index==2) ? 1: 0);
  6376. for (int index = 0; index < GB_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6379. {
  6380. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6381. }
  6382. }
  6383. }
  6384. else if(gunType[gun_index] == GUN_TYPE_DO)
  6385. {
  6386. //tempIndex = ((gun_index==2) ? 1: 0);
  6387. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6388. {
  6389. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6390. {
  6391. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6392. }
  6393. }
  6394. }
  6395. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6396. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6397. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6398. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6399. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6400. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6401. }
  6402. }
  6403. //********************************(7)Current.Import L2************************************************/
  6404. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6405. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6406. (dataType == ReadingContext_Trigger))
  6407. {
  6408. // Only for AC 3 phase
  6409. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6410. {
  6411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6412. {
  6413. tempIndex = 2;
  6414. }
  6415. else
  6416. {
  6417. tempIndex = gun_index;
  6418. }
  6419. for (int index = 0; index < AC_QUANTITY; index++)
  6420. {
  6421. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6422. {
  6423. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6424. }
  6425. }
  6426. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6427. }
  6428. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6429. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6430. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6431. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6432. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6433. }
  6434. //********************************(8)Current.Import L3************************************************/
  6435. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6436. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6437. (dataType == ReadingContext_Trigger))
  6438. {
  6439. // Only for AC 3 phase
  6440. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6441. {
  6442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6443. {
  6444. tempIndex = 2;
  6445. }
  6446. else
  6447. {
  6448. tempIndex = gun_index;
  6449. }
  6450. for (int index = 0; index < AC_QUANTITY; index++)
  6451. {
  6452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6453. {
  6454. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6455. }
  6456. }
  6457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6458. }
  6459. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6460. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6461. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6462. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6463. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6464. }
  6465. //***********************************************(9)VOLTAGE L2******************************************************/
  6466. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6467. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6468. (dataType == ReadingContext_Trigger))
  6469. {
  6470. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6471. {
  6472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6473. {
  6474. tempIndex = 2;
  6475. }
  6476. else
  6477. {
  6478. tempIndex = gun_index;
  6479. }
  6480. for (int index = 0; index < AC_QUANTITY; index++)
  6481. {
  6482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6483. {
  6484. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6485. }
  6486. }
  6487. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6488. }
  6489. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6490. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6491. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6492. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6493. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6494. }
  6495. //***********************************************(10)VOLTAGE L3******************************************************/
  6496. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6497. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6498. (dataType == ReadingContext_Trigger))
  6499. {
  6500. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6501. {
  6502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6503. {
  6504. tempIndex = 2;
  6505. }
  6506. else
  6507. {
  6508. tempIndex = gun_index;
  6509. }
  6510. for (int index = 0; index < AC_QUANTITY; index++)
  6511. {
  6512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6513. {
  6514. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6515. }
  6516. }
  6517. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6518. }
  6519. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6520. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6521. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6522. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6523. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6524. }
  6525. //***********************************************(11)Current.Offered******************************************************/
  6526. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6527. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6528. (dataType == ReadingContext_Trigger))
  6529. {
  6530. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6531. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6532. {
  6533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6534. {
  6535. tempIndex = ((gun_index==2) ? 1: 0);
  6536. }
  6537. else
  6538. {
  6539. tempIndex = gun_index;
  6540. }
  6541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6542. {
  6543. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6544. {
  6545. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6546. }
  6547. } // END OF FOR CHAdeMO_QUANTITY
  6548. }
  6549. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6550. {
  6551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6552. {
  6553. tempIndex = ((gun_index==2) ? 1: 0);
  6554. }
  6555. else
  6556. {
  6557. tempIndex = gun_index;
  6558. }
  6559. for (int index = 0; index < CCS_QUANTITY; index++)
  6560. {
  6561. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6562. {
  6563. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6564. }
  6565. } // END OF CCS_QUANTITY
  6566. }
  6567. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6568. {
  6569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6570. {
  6571. tempIndex = ((gun_index==2) ? 1: 0);
  6572. }
  6573. else
  6574. {
  6575. tempIndex = gun_index;
  6576. }
  6577. for (int index = 0; index < GB_QUANTITY; index++)
  6578. {
  6579. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6580. {
  6581. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6582. }
  6583. } // END OF GB_QUANTITY
  6584. }
  6585. else if(gunType[gun_index] == GUN_TYPE_DO)
  6586. {
  6587. tempIndex = gun_index;
  6588. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6589. {
  6590. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6591. {
  6592. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6593. }
  6594. }
  6595. }
  6596. else
  6597. {
  6598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6599. {
  6600. tempIndex = 2;
  6601. }
  6602. else
  6603. {
  6604. tempIndex = gun_index;
  6605. }
  6606. for (int index = 0; index < AC_QUANTITY; index++)
  6607. {
  6608. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6609. {
  6610. uint16_t currentOffer;
  6611. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6612. {
  6613. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6614. }
  6615. else
  6616. {
  6617. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6618. }
  6619. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6620. }
  6621. }
  6622. }
  6623. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6624. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6625. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6626. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6627. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6628. }
  6629. //***********************************************(12)Power.Offered******************************************************/
  6630. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6631. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6632. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6633. {
  6634. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6635. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6636. {
  6637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6638. {
  6639. tempIndex = ((gun_index==2) ? 1: 0);
  6640. }
  6641. else
  6642. {
  6643. tempIndex = gun_index;
  6644. }
  6645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6646. {
  6647. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6648. {
  6649. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6650. }
  6651. } // END OF FOR CHAdeMO_QUANTITY
  6652. }
  6653. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6654. {
  6655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6656. {
  6657. tempIndex = ((gun_index==2) ? 1: 0);
  6658. }
  6659. else
  6660. {
  6661. tempIndex = gun_index;
  6662. }
  6663. for (int index = 0; index < CCS_QUANTITY; index++)
  6664. {
  6665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6666. {
  6667. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6668. }
  6669. } // END OF CCS_QUANTITY
  6670. }
  6671. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6672. {
  6673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6674. {
  6675. tempIndex = ((gun_index==2) ? 1: 0);
  6676. }
  6677. else
  6678. {
  6679. tempIndex = gun_index;
  6680. }
  6681. for (int index = 0; index < GB_QUANTITY; index++)
  6682. {
  6683. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6684. {
  6685. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6686. }
  6687. } // END OF GB_QUANTITY
  6688. }
  6689. else if(gunType[gun_index] == GUN_TYPE_DO)
  6690. {
  6691. tempIndex = gun_index;
  6692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6693. {
  6694. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6695. {
  6696. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6697. }
  6698. }
  6699. }
  6700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6701. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6702. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6703. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6704. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6705. }
  6706. // Message create ====================================================================================================
  6707. if(TRUE)
  6708. {
  6709. json_object *MeterValueReq = json_object_new_object();
  6710. json_object *MeterValues = json_object_new_array();
  6711. json_object *sampledValues = json_object_new_array();
  6712. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6713. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6714. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6715. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6716. {
  6717. json_object *MeterValue = json_object_new_object();
  6718. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6719. {
  6720. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6721. {
  6722. json_object *sampledValue = json_object_new_object();
  6723. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6724. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6725. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6726. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6727. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6728. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6729. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6730. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6731. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6732. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6733. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6734. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6735. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6736. json_object_array_add(sampledValues, sampledValue);
  6737. }
  6738. }
  6739. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6740. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6741. json_object_array_add(MeterValues, MeterValue);
  6742. }
  6743. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6744. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6745. ,gun_index + 1
  6746. ,MESSAGE_TYPE_CALL
  6747. ,guid
  6748. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6749. json_object_put(MeterValueReq);
  6750. }
  6751. // Put request guid to hash map
  6752. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6753. 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*/)
  6754. {
  6755. result = PASS;
  6756. //DEBUG_INFO("MeterValues mapitem pass\n");
  6757. }
  6758. if((dataType != ReadingContext_Trigger) &&
  6759. (dataType != ReadingContext_Sample_Clock) &&
  6760. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6761. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6762. else
  6763. {
  6764. if(FirstHeartBeat)
  6765. LWS_Send(queuedata +2);
  6766. }
  6767. return result;
  6768. }
  6769. int sendLogStatusNotificationRequest(char *status)
  6770. {
  6771. mtrace();
  6772. int result = PASS;
  6773. char message[4096]={0};
  6774. char guid[37]={0};
  6775. char tempdata[128]={0};
  6776. json_object *LogStatusNotification = json_object_new_object();
  6777. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6778. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6779. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6780. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6781. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6782. random_uuid(guid);
  6783. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6784. json_object_put(LogStatusNotification);
  6785. LWS_Send(message);
  6786. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6787. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6788. {
  6789. result = PASS;
  6790. }
  6791. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6792. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6793. return result;
  6794. }
  6795. int sendSecurityEventNotificationRequest()
  6796. {
  6797. mtrace();
  6798. int result = PASS;
  6799. char message[4096]={0};
  6800. char guid[37]={0};
  6801. char tempdata[128]={0};
  6802. json_object *SecurityEventNotification = json_object_new_object();
  6803. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6804. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6805. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6806. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6807. random_uuid(guid);
  6808. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6809. json_object_put(SecurityEventNotification);
  6810. LWS_Send(message);
  6811. sprintf(tempdata, "SecurityEventNotification,0");
  6812. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6813. {
  6814. result = PASS;
  6815. }
  6816. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6817. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6818. return result;
  6819. }
  6820. int sendSignCertificateRequest()
  6821. {
  6822. mtrace();
  6823. int result = PASS;
  6824. char message[4096]={0};
  6825. char guid[37]={0};
  6826. char tempdata[128]={0};
  6827. json_object *SignCertificate = json_object_new_object();
  6828. DEBUG_INFO("sendSignCertificateRequest...\n");
  6829. // Read csr file content
  6830. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6831. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6832. char *line = NULL;
  6833. size_t len = 0;
  6834. while(getline(&line, &len, fp) != -1)
  6835. {
  6836. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6837. {
  6838. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6839. }
  6840. }
  6841. fclose(fp);
  6842. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6843. random_uuid(guid);
  6844. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6845. json_object_put(SignCertificate);
  6846. LWS_Send(message);
  6847. sprintf(tempdata, "SignCertificate,0");
  6848. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6849. {
  6850. result = PASS;
  6851. }
  6852. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6853. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6854. return result;
  6855. }
  6856. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6857. {
  6858. mtrace();
  6859. int result = PASS;
  6860. char message[110]={0};
  6861. char guid[37]={0};
  6862. char tempdata[65]={0};
  6863. json_object *FirmwareStatusNotification = json_object_new_object();
  6864. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6865. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6866. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6867. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6868. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6869. random_uuid(guid);
  6870. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6871. json_object_put(FirmwareStatusNotification);
  6872. LWS_Send(message);
  6873. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6874. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6875. {
  6876. result = PASS;
  6877. }
  6878. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6879. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6880. return result;
  6881. }
  6882. //==========================================
  6883. // send confirm routine
  6884. //==========================================
  6885. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6886. {
  6887. mtrace();
  6888. int result = FAIL;
  6889. char message[100]={0};
  6890. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6891. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6892. LWS_Send(message);
  6893. result = TRUE;
  6894. return result;
  6895. }
  6896. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6897. {
  6898. mtrace();
  6899. int result = FAIL;
  6900. char message[100]={0};
  6901. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6902. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6903. LWS_Send(message);
  6904. result = TRUE;
  6905. return result;
  6906. }
  6907. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6908. {
  6909. mtrace();
  6910. int result = FAIL;
  6911. char message[100]={0};
  6912. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6913. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6914. LWS_Send(message);
  6915. result = TRUE;
  6916. return result;
  6917. }
  6918. int sendClearCacheConfirmation(char *uuid,char *payload)
  6919. {
  6920. mtrace();
  6921. int result = FAIL;
  6922. char message[500]={0};
  6923. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6924. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6925. LWS_Send(message);
  6926. return result;
  6927. }
  6928. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6929. {
  6930. mtrace();
  6931. int result = FAIL;
  6932. char message[500]={0};
  6933. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6934. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6935. LWS_Send(message);
  6936. return result;
  6937. }
  6938. int sendDataTransferConfirmation(char *uuid,char *payload)
  6939. {
  6940. mtrace();
  6941. char statusStr[20]={0};
  6942. char dataStr[10]={0};
  6943. char sstr[20]={0};
  6944. int c = 0;
  6945. char *loc;
  6946. int result = FAIL;
  6947. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6948. /**********************status**************************/
  6949. loc = strstr(payload, "status");
  6950. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6951. c = 0;
  6952. while (loc[3+strlen("status")+c] != '\"')
  6953. {
  6954. sstr[c] = loc[3+strlen("status")+c];
  6955. c++;
  6956. }
  6957. sstr[c] = '\0';
  6958. strcpy(statusStr, sstr);
  6959. /**********************data**************************/
  6960. loc = strstr(payload, "data");
  6961. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6962. c = 0;
  6963. while (loc[3+strlen("data")+c] != '\"')
  6964. {
  6965. sstr[c] = loc[3+strlen("data")+c];
  6966. c++;
  6967. }
  6968. sstr[c] = '\0';
  6969. strcpy(dataStr, sstr);
  6970. return result;
  6971. }
  6972. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6973. {
  6974. mtrace();
  6975. int result = FAIL;
  6976. char message[1000]={0};
  6977. int CompositeScheduleIndex = 0;
  6978. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6979. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6980. if(nPeriod == 0)
  6981. {
  6982. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6983. {
  6984. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6985. ,MESSAGE_TYPE_CALLRESULT
  6986. ,uuid
  6987. ,payload
  6988. ,connectorIdInt);
  6989. }
  6990. else
  6991. {
  6992. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6993. ,MESSAGE_TYPE_CALLRESULT
  6994. ,uuid
  6995. ,payload
  6996. ,connectorIdInt
  6997. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6998. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6999. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7000. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7001. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7002. }
  7003. }
  7004. else
  7005. {
  7006. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7007. ,MESSAGE_TYPE_CALLRESULT
  7008. ,uuid
  7009. ,payload
  7010. ,connectorIdInt
  7011. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7012. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7013. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7014. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7015. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7016. {
  7017. if (idx_sample == 0)
  7018. {
  7019. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7020. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7021. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7022. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7023. }
  7024. else
  7025. {
  7026. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7027. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7028. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7029. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7030. }
  7031. }
  7032. sprintf(message + strlen(message), "]}}]");
  7033. }
  7034. LWS_Send(message);
  7035. result = TRUE;
  7036. return result;
  7037. }
  7038. int sendGetConfigurationConfirmation(char *uuid)
  7039. {
  7040. mtrace();
  7041. int result = FAIL;
  7042. int MaxKeySupported = 0;
  7043. int sentConfigurationNumber= 0;
  7044. int sentunConfigurationNumber= 0;
  7045. char message[1024*10]={0};
  7046. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7047. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7048. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7049. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7050. ,MESSAGE_TYPE_CALLRESULT
  7051. ,uuid );
  7052. //configuration key
  7053. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7054. {
  7055. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7056. {
  7057. if (sentConfigurationNumber == 0)
  7058. {
  7059. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7060. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7061. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7062. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7063. }
  7064. else
  7065. {
  7066. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7067. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7068. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7069. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7070. }
  7071. sentConfigurationNumber = sentConfigurationNumber + 1;
  7072. }
  7073. }
  7074. sprintf(message + strlen(message), "]");
  7075. if(UnknownKeynum != 0)
  7076. {
  7077. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7078. //unkown key
  7079. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7080. {
  7081. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7082. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7083. if(sentunConfigurationNumber == 0)
  7084. {
  7085. sprintf(message + strlen(message), "\"%s\""
  7086. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7087. }
  7088. else
  7089. {
  7090. sprintf(message + strlen(message), ",\"%s\""
  7091. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7092. }
  7093. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7094. }
  7095. sprintf(message + strlen(message), "]");
  7096. }
  7097. sprintf(message + strlen(message), "}]");
  7098. LWS_Send(message);
  7099. return result;
  7100. }
  7101. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7102. {
  7103. mtrace();
  7104. int result = FAIL;
  7105. char message[400]={0};
  7106. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7107. if(strcmp(payload,"")==0)
  7108. {
  7109. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7110. }
  7111. else
  7112. {
  7113. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7114. }
  7115. LWS_Send(message);
  7116. result = TRUE;
  7117. return result;
  7118. }
  7119. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7120. {
  7121. mtrace();
  7122. int result = FAIL;
  7123. char message[80]={0};
  7124. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7125. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7126. LWS_Send(message);
  7127. result = TRUE;
  7128. return result;
  7129. }
  7130. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7131. {
  7132. mtrace();
  7133. int result = FAIL;
  7134. char message[80]={0};
  7135. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7136. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7137. LWS_Send(message);
  7138. result = TRUE;
  7139. return result;
  7140. }
  7141. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7142. {
  7143. mtrace();
  7144. int result = FAIL;
  7145. char message[80]={0};
  7146. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7147. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7148. LWS_Send(message);
  7149. result = TRUE;
  7150. return result;
  7151. }
  7152. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7153. {
  7154. mtrace();
  7155. int result = FAIL;
  7156. char message[80]={0};
  7157. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7158. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7159. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7160. LWS_Send(message);
  7161. result = TRUE;
  7162. return result;
  7163. }
  7164. int sendResetConfirmation(char *uuid,char *payload)
  7165. {
  7166. mtrace();
  7167. int result = FAIL;
  7168. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7169. char message[80]={0};
  7170. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7171. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7172. LWS_Send(message);
  7173. result = TRUE;
  7174. return result;
  7175. }
  7176. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7177. {
  7178. mtrace();
  7179. int result = FAIL;
  7180. char message[500]={0};
  7181. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7182. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7183. LWS_Send(message);
  7184. result = TRUE;
  7185. return result;
  7186. }
  7187. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7188. {
  7189. mtrace();
  7190. int result = FAIL;
  7191. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7192. char message[80]={0};
  7193. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7194. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7195. LWS_Send(message);
  7196. result = TRUE;
  7197. return result;
  7198. }
  7199. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7200. {
  7201. mtrace();
  7202. int result = FAIL;
  7203. char message[80]={0};
  7204. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7205. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7206. LWS_Send(message);
  7207. result = TRUE;
  7208. return result;
  7209. }
  7210. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7211. {
  7212. mtrace();
  7213. int result = FAIL;
  7214. char message[80]={0};
  7215. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7216. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7217. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7218. LWS_Send(message);
  7219. result = TRUE;
  7220. return result;
  7221. }
  7222. int sendUpdateFirmwareConfirmation(char *uuid)
  7223. {
  7224. mtrace();
  7225. int result = FAIL;
  7226. char message[60]={0};
  7227. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7228. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7229. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7230. LWS_Send(message);
  7231. result = TRUE;
  7232. return result;
  7233. }
  7234. int sendCertificateSignedConfirmation(char *uuid)
  7235. {
  7236. mtrace();
  7237. int result = PASS;
  7238. char message[4096]={0};
  7239. json_object *CertificateSigned = json_object_new_object();
  7240. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7241. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7242. sprintf(message,"[%d,\"%s\",%s]"
  7243. ,MESSAGE_TYPE_CALLRESULT
  7244. ,uuid
  7245. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7246. json_object_put(CertificateSigned);
  7247. LWS_Send(message);
  7248. return result;
  7249. }
  7250. int sendDeleteCertificateConfirmation(char *uuid)
  7251. {
  7252. mtrace();
  7253. int result = PASS;
  7254. char message[4096]={0};
  7255. json_object *DeleteCertificate = json_object_new_object();
  7256. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7257. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7258. sprintf(message,"[%d,\"%s\",%s]"
  7259. ,MESSAGE_TYPE_CALLRESULT
  7260. ,uuid
  7261. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7262. json_object_put(DeleteCertificate);
  7263. LWS_Send(message);
  7264. return result;
  7265. }
  7266. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7267. {
  7268. mtrace();
  7269. int result = PASS;
  7270. char message[4096]={0};
  7271. json_object *ExtendedTriggerMessage = json_object_new_object();
  7272. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7273. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7274. sprintf(message,"[%d,\"%s\",%s]"
  7275. ,MESSAGE_TYPE_CALLRESULT
  7276. ,uuid
  7277. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7278. json_object_put(ExtendedTriggerMessage);
  7279. LWS_Send(message);
  7280. return result;
  7281. }
  7282. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7283. {
  7284. mtrace();
  7285. int result = PASS;
  7286. char message[4096]={0};
  7287. json_object *GetInstalledCertificateIds = json_object_new_object();
  7288. json_object *certificateHashDataDatas = json_object_new_array();
  7289. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7290. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7291. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7292. {
  7293. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7294. {
  7295. json_object *certificateHashData = json_object_new_object();
  7296. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7297. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7298. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7299. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7300. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7301. }
  7302. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7303. }
  7304. else
  7305. {
  7306. json_object_put(certificateHashDataDatas);
  7307. }
  7308. sprintf(message,"[%d,\"%s\",%s]"
  7309. ,MESSAGE_TYPE_CALLRESULT
  7310. ,uuid
  7311. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7312. json_object_put(GetInstalledCertificateIds);
  7313. LWS_Send(message);
  7314. return result;
  7315. }
  7316. int sendGetLogConfirmation(char *uuid)
  7317. {
  7318. mtrace();
  7319. int result = PASS;
  7320. char message[4096]={0};
  7321. json_object *GetLog = json_object_new_object();
  7322. DEBUG_INFO("sendGetLogConfirmation...\n");
  7323. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7324. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7325. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7326. sprintf(message,"[%d,\"%s\",%s]"
  7327. ,MESSAGE_TYPE_CALLRESULT
  7328. ,uuid
  7329. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7330. json_object_put(GetLog);
  7331. LWS_Send(message);
  7332. return result;
  7333. }
  7334. int sendInstallCertificateConfirmation(char *uuid)
  7335. {
  7336. mtrace();
  7337. int result = PASS;
  7338. char message[4096]={0};
  7339. json_object *InstallCertificate = json_object_new_object();
  7340. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7341. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7342. sprintf(message,"[%d,\"%s\",%s]"
  7343. ,MESSAGE_TYPE_CALLRESULT
  7344. ,uuid
  7345. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7346. json_object_put(InstallCertificate);
  7347. LWS_Send(message);
  7348. return result;
  7349. }
  7350. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7351. {
  7352. mtrace();
  7353. int result = PASS;
  7354. char message[4096]={0};
  7355. json_object *SignedUpdateFirmware = json_object_new_object();
  7356. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7357. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7358. sprintf(message,"[%d,\"%s\",%s]"
  7359. ,MESSAGE_TYPE_CALLRESULT
  7360. ,uuid
  7361. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7362. json_object_put(SignedUpdateFirmware);
  7363. LWS_Send(message);
  7364. return result;
  7365. }
  7366. int sendUnknownConfirmation(char *uuid)
  7367. {
  7368. mtrace();
  7369. int result = PASS;
  7370. char message[256]={0};
  7371. DEBUG_INFO("sendUnknownConfirmation...\n");
  7372. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7373. LWS_Send(message);
  7374. return result;
  7375. }
  7376. //==========================================
  7377. // Handle server request routine Start
  7378. //==========================================
  7379. int handleCancelReservationRequest(char *uuid, char *payload)
  7380. {
  7381. mtrace();
  7382. int result = FAIL;
  7383. int gunNO = 0;
  7384. int reservationIdInt = -1;
  7385. char comfirmstr[20];
  7386. DEBUG_INFO("handleCancelReservationRequest...\n");
  7387. json_object *CancelReservation;
  7388. CancelReservation = json_tokener_parse(payload);
  7389. if(!is_error(CancelReservation))
  7390. {
  7391. // Required data
  7392. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7393. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7394. }
  7395. json_object_put(CancelReservation);
  7396. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7397. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7398. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7399. if(reservationIdInt != -1)
  7400. {
  7401. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7402. //check Transaction active
  7403. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7405. {
  7406. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7407. {
  7408. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7409. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7410. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7411. {
  7412. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7413. }
  7414. else
  7415. {
  7416. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7417. }
  7418. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7419. goto end;
  7420. }
  7421. }
  7422. for (int index = 0; index < CCS_QUANTITY; index++)
  7423. {
  7424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7425. {
  7426. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7427. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7428. if(gunType[2] == GUN_TYPE_CCS)
  7429. {
  7430. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7431. }
  7432. else
  7433. {
  7434. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7435. }
  7436. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7437. goto end;
  7438. }
  7439. }
  7440. for (int index = 0; index < GB_QUANTITY; index++)
  7441. {
  7442. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7443. {
  7444. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7445. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7446. if(gunType[2] == GUN_TYPE_GBT)
  7447. {
  7448. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7449. }
  7450. else
  7451. {
  7452. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7453. }
  7454. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7455. goto end;
  7456. }
  7457. }
  7458. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7459. {
  7460. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7461. {
  7462. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7463. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7464. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7465. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7466. goto end;
  7467. }
  7468. }
  7469. for (int index = 0; index < AC_QUANTITY; index++)
  7470. {
  7471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7472. {
  7473. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7474. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7476. {
  7477. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7478. }
  7479. else
  7480. {
  7481. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7482. }
  7483. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7484. goto end;
  7485. }
  7486. }
  7487. }
  7488. //The reservationId does NOT match the reservationId
  7489. sendCancelReservationConfirmation(uuid, comfirmstr);
  7490. end:
  7491. // Fill in ocpp packet uuid
  7492. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7493. return result;
  7494. }
  7495. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7496. {
  7497. mtrace();
  7498. int result = FAIL;
  7499. int gunIndex = -1;
  7500. char typeStr[16]={0};
  7501. char comfirmstr[20];
  7502. int specificId = FALSE;
  7503. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7504. json_object *ChangeAvailability;
  7505. ChangeAvailability = json_tokener_parse(payload);
  7506. if(!is_error(ChangeAvailability))
  7507. {
  7508. // Required data
  7509. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7510. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7511. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7512. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7513. }
  7514. json_object_put(ChangeAvailability);
  7515. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7516. {
  7517. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7518. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7519. }
  7520. else if(gunIndex == 0)
  7521. {
  7522. for(int i=0; i < gunTotalNumber; i++)
  7523. {
  7524. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7525. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7526. }
  7527. }
  7528. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7529. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7530. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7531. {
  7532. specificId = TRUE;
  7533. }
  7534. if(specificId == FALSE)
  7535. goto end;
  7536. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7537. {
  7538. //----------------------gunIndex is 0 ------------------------------------------------//
  7539. if(gunIndex == 0)
  7540. {
  7541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7542. {
  7543. for(int i=0; i < gunTotalNumber; i++)
  7544. {
  7545. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7546. {
  7547. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7548. {
  7549. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7550. {
  7551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7552. goto end;
  7553. }
  7554. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7555. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7556. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7557. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7558. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7559. {
  7560. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7561. goto end;
  7562. }
  7563. }
  7564. }//END FOR CHAdeMO_QUANTITY
  7565. for (int index = 0; index < CCS_QUANTITY; index++)
  7566. {
  7567. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7568. {
  7569. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7570. {
  7571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7572. goto end;
  7573. }
  7574. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7575. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7576. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7577. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7578. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7579. {
  7580. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7581. goto end;
  7582. }
  7583. }
  7584. }//END FOR CCS_QUANTITY
  7585. for (int index = 0; index < GB_QUANTITY; index++)
  7586. {
  7587. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7588. {
  7589. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7590. {
  7591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7592. goto end;
  7593. }
  7594. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7595. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7596. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7597. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7598. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7599. {
  7600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7601. goto end;
  7602. }
  7603. }
  7604. }// END FOR GB_QUANTITY
  7605. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7606. {
  7607. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7608. {
  7609. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7610. {
  7611. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7612. goto end;
  7613. }
  7614. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7615. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7616. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7617. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7618. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7619. {
  7620. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7621. goto end;
  7622. }
  7623. }
  7624. }// END FOR GENERAL_GUN_QUANTITY
  7625. for (int index = 0; index < AC_QUANTITY; index++)
  7626. {
  7627. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7628. {
  7629. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7630. {
  7631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7632. goto end;
  7633. }
  7634. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7635. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7636. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7637. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7638. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7639. {
  7640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7641. goto end;
  7642. }
  7643. }
  7644. }//END FOR AC_QUANTITY
  7645. }// END FOR gunTotalNumber
  7646. }
  7647. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7648. {
  7649. for(int i=0; i < gunTotalNumber; i++)
  7650. {
  7651. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7652. {
  7653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7654. goto end;
  7655. }
  7656. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7657. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7658. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7659. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7660. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7661. {
  7662. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7663. goto end;
  7664. }
  7665. }
  7666. }
  7667. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7668. goto end;
  7669. }
  7670. //----------------------gunIndex is not 0 ------------------------------------------------//
  7671. //check Transaction active
  7672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7673. {
  7674. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7675. {
  7676. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7677. {
  7678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7679. goto end;
  7680. }
  7681. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7682. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7683. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7684. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7685. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7686. {
  7687. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7688. goto end;
  7689. }
  7690. else
  7691. {
  7692. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7693. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7694. goto end;
  7695. }
  7696. }
  7697. }//END FOR CHAdeMO_QUANTITY
  7698. for (int index = 0; index < CCS_QUANTITY; index++)
  7699. {
  7700. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7701. {
  7702. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7703. {
  7704. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7705. goto end;
  7706. }
  7707. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7708. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7709. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7710. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7711. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7712. {
  7713. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7714. goto end;
  7715. }
  7716. else
  7717. {
  7718. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7719. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7720. goto end;
  7721. }
  7722. }
  7723. }//END FOR CCS_QUANTITY
  7724. for (int index = 0; index < GB_QUANTITY; index++)
  7725. {
  7726. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7727. {
  7728. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7729. {
  7730. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7731. goto end;
  7732. }
  7733. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7734. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7737. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7738. {
  7739. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7740. goto end;
  7741. }
  7742. else
  7743. {
  7744. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7745. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7746. goto end;
  7747. }
  7748. }
  7749. }// END FOR GB_QUANTITY
  7750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7751. {
  7752. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7753. {
  7754. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7755. {
  7756. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7757. goto end;
  7758. }
  7759. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7760. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7761. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7762. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7763. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7764. {
  7765. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7766. goto end;
  7767. }
  7768. else
  7769. {
  7770. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7771. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7772. goto end;
  7773. }
  7774. }
  7775. }// END FOR GENERAL_GUN_QUANTITY
  7776. for (int index = 0; index < AC_QUANTITY; index++)
  7777. {
  7778. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7779. {
  7780. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7781. {
  7782. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7783. goto end;
  7784. }
  7785. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7786. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7787. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7788. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7789. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7790. {
  7791. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7792. goto end;
  7793. }
  7794. else
  7795. {
  7796. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7798. goto end;
  7799. }
  7800. }
  7801. }//END FOR AC_QUANTITY
  7802. }//END FOR AvailabilityTypeStr[Inoperative]
  7803. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7804. {
  7805. //----------------------gunIndex is 0 ------------------------------------------------//
  7806. if(gunIndex == 0)
  7807. {
  7808. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7809. {
  7810. for(int i=0; i < gunTotalNumber; i++)
  7811. {
  7812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7813. {
  7814. 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
  7815. {
  7816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7817. goto end;
  7818. }
  7819. }//END FOR CHAdeMO_QUANTITY
  7820. for (int index = 0; index < CCS_QUANTITY; index++)
  7821. {
  7822. 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
  7823. {
  7824. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7825. goto end;
  7826. }
  7827. }//END FOR CCS_QUANTITY
  7828. for (int index = 0; index < GB_QUANTITY; index++)
  7829. {
  7830. 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
  7831. {
  7832. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7833. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7834. goto end;
  7835. }
  7836. }// END FOR GB_QUANTITY
  7837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7838. {
  7839. 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
  7840. {
  7841. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7843. goto end;
  7844. }
  7845. }// END FOR GENERAL_GUN_QUANTITY
  7846. for (int index = 0; index < AC_QUANTITY; index++)
  7847. {
  7848. 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
  7849. {
  7850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7851. goto end;
  7852. }
  7853. }//END FOR CHAdeMO_QUANTITY
  7854. }// END FOR gunTotalNumber
  7855. }
  7856. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7857. {
  7858. for(int i=0; i < gunTotalNumber; i++)
  7859. {
  7860. for (int index = 0; index < AC_QUANTITY; index++)
  7861. {
  7862. 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
  7863. {
  7864. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7865. goto end;
  7866. }
  7867. }//END FOR CHAdeMO_QUANTITY
  7868. } // END FOR gunTotalNumber
  7869. }
  7870. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7871. goto end;
  7872. }
  7873. //----------------------gunIndex is not 0 ------------------------------------------------//
  7874. //check Transaction active
  7875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7876. {
  7877. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7878. {
  7879. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7880. goto end;
  7881. }
  7882. }//END FOR CHAdeMO_QUANTITY
  7883. for (int index = 0; index < CCS_QUANTITY; index++)
  7884. {
  7885. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7886. {
  7887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7888. goto end;
  7889. }
  7890. }//END FOR CCS_QUANTITY
  7891. for (int index = 0; index < GB_QUANTITY; index++)
  7892. {
  7893. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7894. {
  7895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7896. goto end;
  7897. }
  7898. }// END FOR GB_QUANTITY
  7899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7900. {
  7901. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7902. {
  7903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7904. goto end;
  7905. }
  7906. }// END FOR GENERAL_GUN_QUANTITY
  7907. for (int index = 0; index < AC_QUANTITY; index++)
  7908. {
  7909. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7910. {
  7911. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7912. goto end;
  7913. }
  7914. }//END FOR AC_QUANTITY
  7915. }//END FOR AvailabilityTypeStr[Operative]
  7916. end:
  7917. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7918. {
  7919. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7920. }
  7921. else
  7922. {
  7923. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7924. }
  7925. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7926. {
  7927. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7928. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7929. }
  7930. else if(gunIndex == 0)
  7931. {
  7932. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7933. {
  7934. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7935. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7936. }
  7937. }
  7938. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7939. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7940. return result;
  7941. }
  7942. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7943. {
  7944. mtrace();
  7945. int valueInvalid = NO;
  7946. int result = FAIL;
  7947. char keystr[40]={0};
  7948. char valuestr[501]={0}; //value should be limited in 500 bytes
  7949. char comfirmstr[20]={0};
  7950. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7951. json_object *ChangeConfiguration;
  7952. ChangeConfiguration = json_tokener_parse(payload);
  7953. if(!is_error(ChangeConfiguration))
  7954. {
  7955. // Required data
  7956. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7957. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7958. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  7959. {
  7960. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7961. }
  7962. else
  7963. {
  7964. valueInvalid = YES;
  7965. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  7966. }
  7967. }
  7968. json_object_put(ChangeConfiguration);
  7969. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  7970. {
  7971. DEBUG_ERROR("Payload is null or not accepted.\n");
  7972. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7973. }
  7974. else
  7975. {
  7976. int status = setKeyValue(keystr, valuestr);
  7977. switch(status)
  7978. {
  7979. case ConfigurationStatus_Accepted:
  7980. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7981. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7982. StoreConfigurationTable();
  7983. break;
  7984. case RebootRequired:
  7985. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7986. StoreConfigurationTable();
  7987. break;
  7988. case NotSupported:
  7989. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7990. break;
  7991. case ConfigurationStatus_Rejected:
  7992. default:
  7993. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7994. break;
  7995. }
  7996. }
  7997. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7998. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7999. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8000. {
  8001. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8002. SetOcppConnStatus(FALSE);
  8003. }
  8004. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8005. {
  8006. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8007. }
  8008. return result;
  8009. }
  8010. int handleClearCacheRequest(char *uuid, char *payload)
  8011. {
  8012. mtrace();
  8013. int result = FAIL;
  8014. char comfirmstr[20];
  8015. char rmFileCmd[100]={0};
  8016. struct stat stats;
  8017. DEBUG_INFO("handleClearCacheRequest...\n");
  8018. stat("/Storage/OCPP_PH", &stats);
  8019. // Check for directory existence
  8020. if (S_ISDIR(stats.st_mode) == 1)
  8021. {}
  8022. else
  8023. {
  8024. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8025. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8026. system(rmFileCmd);
  8027. }
  8028. if(OCPP_cleanLocalCache())
  8029. {
  8030. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8031. }
  8032. else
  8033. {
  8034. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8035. }
  8036. sendClearCacheConfirmation(uuid, comfirmstr);
  8037. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8038. return result;
  8039. }
  8040. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8041. {
  8042. mtrace();
  8043. int result = FAIL;
  8044. int resultRename;
  8045. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8046. char chargingProfilePurposeStr[26]={0};
  8047. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8048. char tempchargingProfilePurposeStr[26]={0};
  8049. char str[100]={0};
  8050. char fname[200]={0};
  8051. char comfirmstr[20]={0};
  8052. char word[1600]={0};
  8053. int clearflag = FALSE;
  8054. int chargingProfileIdIsNULL = FALSE;
  8055. int connectorIsNULL = FALSE;
  8056. int chargingProfilePurposeIsNULL = FALSE;
  8057. int stackLevelIsNULL = FALSE;
  8058. //int GotoEnd = FALSE;
  8059. FILE *fptr1, *fptr2;
  8060. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8061. int n_chargingProfile=0;
  8062. int isEmptyFile = FALSE;
  8063. char sLineWord[1600]={0};
  8064. char chargingProfiles[10][100]={0};
  8065. int ChargeProfileCount = 0;
  8066. int ch;
  8067. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8068. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8069. json_object *ClearChargingProfile;
  8070. ClearChargingProfile = json_tokener_parse(payload);
  8071. if(!is_error(ClearChargingProfile))
  8072. {
  8073. // Optional data
  8074. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8075. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8076. else
  8077. chargingProfileIdIsNULL = TRUE;
  8078. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8079. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8080. else
  8081. connectorIsNULL = TRUE;
  8082. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8083. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8084. else
  8085. chargingProfilePurposeIsNULL = TRUE;
  8086. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8087. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8088. else
  8089. stackLevelIsNULL = TRUE;
  8090. }
  8091. json_object_put(ClearChargingProfile);
  8092. if(connectorIsNULL == FALSE)
  8093. {
  8094. switch(connectorIdInt)
  8095. {
  8096. case 0:
  8097. if(chargingProfilePurposeIsNULL == TRUE)
  8098. {
  8099. int l = 0;
  8100. strcpy(fname, ChargePointMaxProfile_JSON);
  8101. if((access(fname,F_OK))!=-1)
  8102. {
  8103. strcpy(chargingProfiles[l], fname);
  8104. l = l + 1;
  8105. }
  8106. strcpy(fname, TxDefaultProfile_0_JSON);
  8107. if((access(fname,F_OK))!=-1)
  8108. {
  8109. strcpy(chargingProfiles[l], fname);
  8110. l = l + 1;
  8111. }
  8112. ChargeProfileCount = l;
  8113. }
  8114. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8115. {
  8116. strcpy(fname, ChargePointMaxProfile_JSON);
  8117. if((access(fname,F_OK))!=-1)
  8118. {
  8119. strcpy(chargingProfiles[0], fname);
  8120. ChargeProfileCount = 1;
  8121. }
  8122. }
  8123. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8124. {
  8125. strcpy(fname, TxDefaultProfile_0_JSON);
  8126. if((access(fname,F_OK))!=-1)
  8127. {
  8128. strcpy(chargingProfiles[0], fname);
  8129. ChargeProfileCount = 1;
  8130. }
  8131. }
  8132. break;
  8133. default:
  8134. if(chargingProfilePurposeIsNULL == TRUE)
  8135. {
  8136. int m = 0;
  8137. memset(fname, 0, ARRAY_SIZE(fname));
  8138. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8139. if((access(fname,F_OK))!=-1)
  8140. {
  8141. strcpy(chargingProfiles[m], fname);
  8142. m = m + 1;
  8143. }
  8144. memset(fname, 0, ARRAY_SIZE(fname));
  8145. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8146. if((access(fname,F_OK))!=-1)
  8147. {
  8148. strcpy(chargingProfiles[m], fname);
  8149. m = m + 1;
  8150. }
  8151. ChargeProfileCount = m;
  8152. }
  8153. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8154. {
  8155. //strcpy(fname, TxDefaultProfile_1_JSON);
  8156. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8157. if((access(fname,F_OK))!=-1)
  8158. {
  8159. strcpy(chargingProfiles[0], fname);
  8160. ChargeProfileCount = 1;
  8161. }
  8162. }
  8163. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8164. {
  8165. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8166. if((access(fname,F_OK))!=-1)
  8167. {
  8168. strcpy(chargingProfiles[0], fname);
  8169. ChargeProfileCount = 1;
  8170. }
  8171. //strcpy(fname, TxProfile_1_JSON);
  8172. }
  8173. //strcpy(fname, ChargePointMaxProfile_JSON );
  8174. break;
  8175. }
  8176. }
  8177. else // Check all Charging Profiles
  8178. {
  8179. int i = 0;
  8180. char fnametemp[200]={0};
  8181. ChargeProfileCount = 0;
  8182. //Check ChargePointMaxProfile.json exit
  8183. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8184. {
  8185. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8186. i = i + 1;
  8187. }
  8188. //Check TxDefaultProfile_0.json exit
  8189. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8190. {
  8191. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8192. i = i + 1;
  8193. }
  8194. //Check TxDefaultProfile_%d.json
  8195. for(int j=1; j <= gunTotalNumber; j++)
  8196. {
  8197. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8198. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8199. if((access(fnametemp,F_OK))!=-1)
  8200. {
  8201. strcpy(chargingProfiles[i], fnametemp);
  8202. i = i + 1;
  8203. }
  8204. }
  8205. //Check TxProfile_%d.json
  8206. for(int j=1; j <= gunTotalNumber; j++)
  8207. {
  8208. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8209. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8210. if((access(fnametemp,F_OK))!=-1)
  8211. {
  8212. strcpy(chargingProfiles[i], fnametemp);
  8213. i = i + 1;
  8214. }
  8215. }
  8216. ChargeProfileCount = i;
  8217. }// End connectorIsNULL is TRUE
  8218. if(ChargeProfileCount == 0)
  8219. {
  8220. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8221. goto end;
  8222. }
  8223. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8224. {
  8225. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8226. goto end;
  8227. }
  8228. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8229. {
  8230. memset(str, 0, ARRAY_SIZE(str));
  8231. // clear temp file
  8232. sprintf(str,"rm -f %s",temp);
  8233. system(str);
  8234. for(int k=0; k < ChargeProfileCount; k++)
  8235. {
  8236. memset(str, 0, ARRAY_SIZE(str));
  8237. //clear file in C
  8238. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8239. system(str);
  8240. }
  8241. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8242. goto end;
  8243. }
  8244. else if(connectorIsNULL == TRUE)
  8245. {
  8246. for(int k=0; k < ChargeProfileCount; k++)
  8247. {
  8248. fptr1 = fopen(chargingProfiles[k], "r");
  8249. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8250. //Check Charging Profile Count
  8251. while(fscanf(fptr1, "%s", word) != EOF)
  8252. {
  8253. //DEBUG_INFO("word=%s\n",word);
  8254. if(strstr(word, "chargingProfileId")!= NULL)
  8255. {
  8256. //DEBUG_INFO("test chargingProfileId \n");
  8257. n_chargingProfile = n_chargingProfile + 1;
  8258. //DEBUG_INFO("chargingProfileId Found\n");
  8259. }
  8260. }
  8261. rewind(fptr1);
  8262. //search Charging Profile Element
  8263. //int i= 0;
  8264. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8265. {
  8266. json_object *tmpProfilee;
  8267. tmpProfilee = json_tokener_parse(sLineWord);
  8268. if(!is_error(tmpProfilee))
  8269. {
  8270. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8271. {
  8272. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8273. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8274. }
  8275. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8276. {
  8277. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8278. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8279. }
  8280. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8281. {
  8282. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8283. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8284. }
  8285. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8286. {
  8287. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8288. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8289. }
  8290. }
  8291. json_object_put(tmpProfilee);
  8292. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8293. {
  8294. //------- not write to fptr2-------//
  8295. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8296. //clearflag = TRUE;
  8297. }
  8298. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8299. {
  8300. //------- not write to fptr2-------//
  8301. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8302. }
  8303. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8304. {
  8305. //------- not write to fptr2-------//
  8306. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8307. }
  8308. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8309. {
  8310. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8311. }
  8312. else
  8313. {
  8314. fprintf(fptr2, sLineWord);//writing data into file
  8315. }
  8316. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8317. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8318. if(clearflag == TRUE)
  8319. {
  8320. fclose(fptr1);
  8321. fclose(fptr2);
  8322. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8323. system(str);
  8324. // clear temp file
  8325. sprintf(str,"rm -f %s",temp);
  8326. system(str);
  8327. }
  8328. else
  8329. {
  8330. fclose(fptr1);
  8331. fclose(fptr2);
  8332. memset(str, 0, ARRAY_SIZE(str));
  8333. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8334. system(str);
  8335. resultRename = rename(temp, chargingProfiles[k]);
  8336. if(resultRename == 0)
  8337. {
  8338. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8339. }
  8340. else
  8341. {
  8342. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8343. }
  8344. if(comfirmstr[0]== 0)
  8345. {
  8346. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8347. }
  8348. //Check chargingProfile is empty file
  8349. /*------ Read the file ----------------*/
  8350. fptr1=fopen(chargingProfiles[k],"r");
  8351. ch=fgetc(fptr1);
  8352. rewind(fptr1);
  8353. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8354. if(ch!=EOF)
  8355. {
  8356. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8357. {
  8358. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8359. if(sLineWord[0]=='\0')
  8360. {
  8361. isEmptyFile = TRUE;
  8362. break;
  8363. }
  8364. else
  8365. {
  8366. isEmptyFile = FALSE;
  8367. break;
  8368. }
  8369. }
  8370. }
  8371. else
  8372. isEmptyFile = TRUE;
  8373. fclose(fptr1);
  8374. if(isEmptyFile == TRUE)
  8375. {
  8376. memset(str, 0, ARRAY_SIZE(str));
  8377. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8378. system(str);
  8379. }
  8380. }
  8381. }// End of while(int k=0; k < ChargePointCount; k++)
  8382. }
  8383. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8384. {
  8385. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8386. for(int k=0; k < ChargeProfileCount; k++)
  8387. {
  8388. fptr1 = fopen(chargingProfiles[k], "r");
  8389. fptr2 = fopen(temp, "w+");
  8390. //Check Charging Profile Count
  8391. while(fscanf(fptr1, "%s", word) != EOF)
  8392. {
  8393. //DEBUG_INFO("word=%s\n",word);
  8394. if(strstr(word, "chargingProfileId")!= NULL)
  8395. {
  8396. n_chargingProfile = n_chargingProfile + 1;
  8397. }
  8398. }
  8399. rewind(fptr1);
  8400. //search Charging Profile Element
  8401. //int i= 0;
  8402. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8403. {
  8404. json_object *tmpProfilee;
  8405. tmpProfilee = json_tokener_parse(sLineWord);
  8406. if(!is_error(tmpProfilee))
  8407. {
  8408. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8409. {
  8410. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8411. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8412. }
  8413. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8414. {
  8415. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8416. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8417. }
  8418. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8419. {
  8420. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8421. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8422. }
  8423. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8424. {
  8425. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8426. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8427. }
  8428. }
  8429. json_object_put(tmpProfilee);
  8430. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8431. {
  8432. //------- not write to fptr2-------//
  8433. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8434. //clearflag = TRUE;
  8435. }
  8436. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8437. {
  8438. //------- not write to fptr2-------//
  8439. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8440. }
  8441. else if(stackLevelIsNULL == TRUE)
  8442. {
  8443. //Clear Whole File
  8444. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8445. clearflag = TRUE;
  8446. break;
  8447. }
  8448. else
  8449. {
  8450. fprintf(fptr2, sLineWord);//writing data into file
  8451. }
  8452. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8453. }
  8454. if(clearflag == TRUE)
  8455. {
  8456. fclose(fptr1);
  8457. fclose(fptr2);
  8458. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8459. system(str);
  8460. // clear temp file
  8461. sprintf(str,"rm -f %s",temp);
  8462. system(str);
  8463. }
  8464. else
  8465. {
  8466. fclose(fptr1);
  8467. fclose(fptr2);
  8468. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8469. system(str);
  8470. resultRename = rename(temp, chargingProfiles[k]);
  8471. if(resultRename == 0)
  8472. {
  8473. DEBUG_INFO("File ChargingProfile renamed successfully");
  8474. }
  8475. else
  8476. {
  8477. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8478. }
  8479. if(comfirmstr[0]== 0)
  8480. {
  8481. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8482. }
  8483. //Check chargingProfile is empty file
  8484. /*------ Read the file ----------------*/
  8485. fptr1=fopen(chargingProfiles[k],"r");
  8486. ch=fgetc(fptr1);
  8487. rewind(fptr1);
  8488. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8489. if(ch!=EOF)
  8490. {
  8491. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8492. {
  8493. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8494. if(sLineWord[0]=='\0')
  8495. {
  8496. isEmptyFile = TRUE;
  8497. break;
  8498. }
  8499. else
  8500. {
  8501. isEmptyFile = FALSE;
  8502. break;
  8503. }
  8504. }
  8505. }
  8506. else
  8507. isEmptyFile = TRUE;
  8508. fclose(fptr1);
  8509. if(isEmptyFile == TRUE)
  8510. {
  8511. memset(str, 0, ARRAY_SIZE(str));
  8512. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8513. system(str);
  8514. }
  8515. /*------- End of reading ---------------*/
  8516. }
  8517. } // while(int k=0; k < ChargeProfileCount; k++)
  8518. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8519. end:
  8520. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8521. {
  8522. if(connectorIdInt == 0)
  8523. {
  8524. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8525. {
  8526. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8527. }
  8528. }
  8529. else
  8530. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8531. }
  8532. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8533. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8534. return result;
  8535. }
  8536. void createFirmwareVersionByDataTransfer(void)
  8537. {
  8538. json_object *FirmwareDataTransfer = json_object_new_object();
  8539. // AC & DC model
  8540. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8541. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8542. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8543. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8544. // DC model
  8545. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8546. {
  8547. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8548. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8549. (gunType[3] != GUN_TYPE_UNKNOWN))
  8550. {
  8551. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8552. }
  8553. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8554. {
  8555. // DS DM DW
  8556. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8557. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8558. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8559. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8560. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8561. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8562. }
  8563. else
  8564. {
  8565. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8566. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8567. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8568. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8569. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8570. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8571. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8572. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8573. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8574. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8575. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8576. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8577. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8579. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8580. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8581. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8582. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8583. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8584. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8585. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8586. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8587. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8588. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8589. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8590. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8591. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8592. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8593. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8594. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8595. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8596. }
  8597. }
  8598. // 4G model
  8599. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8600. {
  8601. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8602. }
  8603. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8604. json_object_put(FirmwareDataTransfer);
  8605. }
  8606. int handleDataTransferRequest(char *uuid, char *payload)
  8607. {
  8608. mtrace();
  8609. json_object *response = json_object_new_object();
  8610. int result = FAIL;
  8611. char tempvendorId[255]={0};
  8612. char tempmessageId[50]={0};
  8613. char tempdata[512]={0};
  8614. char message[2048]={0};
  8615. DEBUG_INFO("handleDataTransferRequest...\n");
  8616. if((uuid != NULL) && (payload != NULL))
  8617. {
  8618. json_object *DataTransfer;
  8619. DataTransfer = json_tokener_parse(payload);
  8620. if(!is_error(DataTransfer))
  8621. {
  8622. // Required data
  8623. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8624. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8625. // Optional data
  8626. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8627. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8628. if(json_object_object_get(DataTransfer, "data") != NULL)
  8629. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8630. result = PASS;
  8631. }
  8632. json_object_put(DataTransfer);
  8633. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8634. {
  8635. // Send all moudle firmware version on EVSE
  8636. createFirmwareVersionByDataTransfer();
  8637. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8638. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8639. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8640. json_object_put(response);
  8641. }
  8642. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8643. {
  8644. system("/usr/bin/run_tmate_restart.sh &");
  8645. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8646. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8647. json_object_put(response);
  8648. }
  8649. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8650. {
  8651. json_object *data;
  8652. data = json_tokener_parse(tempdata);
  8653. if(!is_error(data))
  8654. {
  8655. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  8656. {
  8657. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8658. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8659. if(json_object_object_get(data, "SOC") != NULL)
  8660. {
  8661. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8662. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8663. }
  8664. if(json_object_object_get(data, "Energy") != NULL)
  8665. {
  8666. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8667. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8668. }
  8669. if(json_object_object_get(data, "Duration") != NULL)
  8670. {
  8671. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8672. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8673. }
  8674. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8675. }
  8676. else
  8677. {
  8678. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8679. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8680. }
  8681. }
  8682. else
  8683. {
  8684. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8685. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8686. }
  8687. json_object_put(data);
  8688. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8689. json_object_put(response);
  8690. }
  8691. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8692. {
  8693. json_object *data;
  8694. data = json_tokener_parse(tempdata);
  8695. if(!is_error(data))
  8696. {
  8697. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8698. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8699. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8700. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8701. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8702. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8703. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8704. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8705. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8706. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8707. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8708. }
  8709. else
  8710. {
  8711. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8712. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8713. }
  8714. json_object_put(data);
  8715. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8716. json_object_put(response);
  8717. }
  8718. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8719. {
  8720. json_object *data;
  8721. data = json_tokener_parse(tempdata);
  8722. if(!is_error(data))
  8723. {
  8724. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8725. if(json_object_object_get(data, "idToken") != NULL)
  8726. {
  8727. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8728. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8729. }
  8730. if(json_object_object_get(data, "price") != NULL)
  8731. {
  8732. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8733. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8734. }
  8735. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8736. }
  8737. else
  8738. {
  8739. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8740. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8741. }
  8742. json_object_put(data);
  8743. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8744. json_object_put(response);
  8745. }
  8746. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8747. {
  8748. json_object *data;
  8749. data = json_tokener_parse(tempdata);
  8750. if(!is_error(data))
  8751. {
  8752. if(json_object_object_get(data, "txId") != NULL)
  8753. {
  8754. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8755. for(int idx = 0;idx<gunTotalNumber;idx++)
  8756. {
  8757. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8758. {
  8759. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8760. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8761. if(json_object_object_get(data, "description") != NULL)
  8762. {
  8763. // California pricing V1.0
  8764. DEBUG_INFO("California pricing V1.0\n");
  8765. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8766. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8767. }
  8768. else
  8769. {
  8770. // California pricing V1.1
  8771. DEBUG_INFO("California pricing V1.1\n");
  8772. if(json_object_object_get(data, "timestamp") != NULL)
  8773. {
  8774. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8775. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8776. }
  8777. if(json_object_object_get(data, "meterValue") != NULL)
  8778. {
  8779. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8780. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8781. }
  8782. if(json_object_object_get(data, "cost") != NULL)
  8783. {
  8784. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8785. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8786. }
  8787. if(json_object_object_get(data, "state") != NULL)
  8788. {
  8789. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8790. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8791. }
  8792. if(json_object_object_get(data, "chargingPrice") != NULL)
  8793. {
  8794. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8795. {
  8796. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8797. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8798. }
  8799. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8800. {
  8801. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8802. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8803. }
  8804. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8805. {
  8806. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8807. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8808. }
  8809. }
  8810. if(json_object_object_get(data, "idlePrice") != NULL)
  8811. {
  8812. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8813. {
  8814. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8815. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8816. }
  8817. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8818. {
  8819. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8820. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8821. }
  8822. }
  8823. if(json_object_object_get(data, "nextPeriod") != NULL)
  8824. {
  8825. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8826. {
  8827. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8828. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8829. }
  8830. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8831. {
  8832. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8833. {
  8834. 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")));
  8835. 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"));
  8836. }
  8837. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8838. {
  8839. 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")));
  8840. 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"));
  8841. }
  8842. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8843. {
  8844. 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")));
  8845. 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"));
  8846. }
  8847. }
  8848. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8849. {
  8850. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8851. {
  8852. 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")));
  8853. 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"));
  8854. }
  8855. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8856. {
  8857. 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")));
  8858. 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"));
  8859. }
  8860. }
  8861. }
  8862. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8863. {
  8864. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8865. {
  8866. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8867. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8868. }
  8869. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8870. {
  8871. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8872. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8873. }
  8874. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8875. {
  8876. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8877. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8878. }
  8879. }
  8880. }
  8881. }
  8882. }
  8883. }
  8884. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8885. }
  8886. else
  8887. {
  8888. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8889. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8890. }
  8891. json_object_put(data);
  8892. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8893. json_object_put(response);
  8894. }
  8895. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8896. {
  8897. json_object *data;
  8898. data = json_tokener_parse(tempdata);
  8899. if(!is_error(data))
  8900. {
  8901. if(json_object_object_get(data, "txId") != NULL)
  8902. {
  8903. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8904. for(int idx = 0;idx<gunTotalNumber;idx++)
  8905. {
  8906. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8907. {
  8908. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8909. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8910. if(json_object_object_get(data, "description") != NULL)
  8911. {
  8912. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8913. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8914. }
  8915. }
  8916. }
  8917. }
  8918. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8919. }
  8920. else
  8921. {
  8922. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8923. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8924. }
  8925. json_object_put(data);
  8926. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8927. json_object_put(response);
  8928. }
  8929. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8930. {
  8931. json_object *data;
  8932. data = json_tokener_parse(tempdata);
  8933. if(!is_error(data))
  8934. {
  8935. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8936. if(json_object_object_get(data, "Content_Type") != NULL)
  8937. {
  8938. 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))
  8939. {
  8940. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8941. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8942. {
  8943. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8944. }
  8945. }
  8946. else
  8947. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8948. }
  8949. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8950. }
  8951. else
  8952. {
  8953. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8954. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8955. }
  8956. json_object_put(data);
  8957. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8958. json_object_put(response);
  8959. }
  8960. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8961. {
  8962. json_object *data;
  8963. data = json_tokener_parse(tempdata);
  8964. if(!is_error(data))
  8965. {
  8966. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8967. if(json_object_object_get(data, "Page_Index") != NULL)
  8968. {
  8969. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8970. }
  8971. if(json_object_object_get(data, "Duration") != NULL)
  8972. {
  8973. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8974. }
  8975. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8976. }
  8977. else
  8978. {
  8979. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8980. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8981. }
  8982. json_object_put(data);
  8983. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8984. json_object_put(response);
  8985. }
  8986. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8987. {
  8988. json_object *data;
  8989. data = json_tokener_parse(tempdata);
  8990. if(!is_error(data))
  8991. {
  8992. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8993. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8994. {
  8995. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8996. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8997. else
  8998. {
  8999. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9000. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9001. }
  9002. }
  9003. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9004. {
  9005. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9006. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9007. else
  9008. {
  9009. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9010. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9011. }
  9012. }
  9013. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9014. {
  9015. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9016. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9017. else
  9018. {
  9019. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9020. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9021. }
  9022. }
  9023. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9024. {
  9025. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9026. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9027. else
  9028. {
  9029. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9030. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9031. }
  9032. }
  9033. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9034. {
  9035. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9036. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9037. else
  9038. {
  9039. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9040. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9041. }
  9042. }
  9043. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9044. {
  9045. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9046. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9047. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9048. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9049. else
  9050. {
  9051. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9052. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9053. }
  9054. }
  9055. if(json_object_object_get(data, "isAuthentication") != NULL)
  9056. {
  9057. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9058. {
  9059. case 0:
  9060. case 1:
  9061. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9062. break;
  9063. default:
  9064. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9065. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9066. break;
  9067. }
  9068. }
  9069. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9070. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9071. }
  9072. else
  9073. {
  9074. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9075. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9076. }
  9077. json_object_put(data);
  9078. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9079. json_object_put(response);
  9080. }
  9081. else
  9082. {
  9083. // Can not find valid message id
  9084. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9085. }
  9086. }
  9087. else
  9088. {
  9089. // Payload is null
  9090. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9091. }
  9092. LWS_Send(message);
  9093. return result;
  9094. }
  9095. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9096. {
  9097. mtrace();
  9098. int result = FAIL;
  9099. int connectorIdInt, durationInt;
  9100. char chargingRateUnitStr[4]={0};
  9101. char comfirmstr[20];
  9102. int confirmPeriods = 0;
  9103. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9104. json_object *GetCompositeSchedule;
  9105. GetCompositeSchedule = json_tokener_parse(payload);
  9106. if(!is_error(GetCompositeSchedule))
  9107. {
  9108. // Required data
  9109. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9110. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9111. else
  9112. connectorIdInt = -1;
  9113. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9114. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9115. else
  9116. durationInt = 86400;
  9117. // Optional data
  9118. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9119. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9120. }
  9121. json_object_put(GetCompositeSchedule);
  9122. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9123. if((connectorIdInt == 0) ||
  9124. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9125. {
  9126. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9127. struct StructChargingProfile tmpProfile[1];
  9128. if(strstr(chargingRateUnitStr, "W") != NULL)
  9129. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9130. else
  9131. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9132. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9133. {
  9134. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9135. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9136. }
  9137. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9138. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9139. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9140. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9141. {
  9142. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9143. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9144. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9145. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9146. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9147. {
  9148. confirmPeriods = idx;
  9149. break;
  9150. }
  9151. }
  9152. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9153. {
  9154. confirmPeriods += 1;
  9155. }
  9156. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9157. }
  9158. else
  9159. {
  9160. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9161. }
  9162. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9163. return result;
  9164. }
  9165. int handleGetConfigurationRequest(char *uuid, char *payload)
  9166. {
  9167. mtrace();
  9168. int result = FAIL;
  9169. int MaxKeySupported = 0;
  9170. int n_keys = 0;
  9171. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9172. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9173. json_object *GetConfiguration;
  9174. GetConfiguration = json_tokener_parse(payload);
  9175. if(!is_error(GetConfiguration))
  9176. {
  9177. // Optional data
  9178. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9179. {
  9180. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9181. {
  9182. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9183. n_keys = idx + 1;
  9184. }
  9185. }
  9186. }
  9187. json_object_put(GetConfiguration);
  9188. UnknownKeynum = 0;
  9189. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9190. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9191. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9192. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9193. if(n_keys != 0)
  9194. {
  9195. for(int i=0;i<n_keys;i++)
  9196. {
  9197. getKeyValue(requestKey[i]);
  9198. }
  9199. }
  9200. else
  9201. {
  9202. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9203. getKeyValue("");
  9204. }
  9205. processUnkownKey();
  9206. sendGetConfigurationConfirmation(uuid);
  9207. return result;
  9208. }
  9209. static char fnamePlusPath[100]={0};
  9210. static char fnamePWithNoPath[60]={0};
  9211. void checkUploadLog(void)
  9212. {
  9213. FILE *fp;
  9214. /* Open the command for reading. */
  9215. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9216. if (fp == NULL) {
  9217. DEBUG_WARN("Failed to run command\n" );
  9218. exit(1);
  9219. }
  9220. int ftppathlen = 0;
  9221. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9222. int i = 0;
  9223. /* Read the output a line at a time - output it. */
  9224. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9225. if(i==0)
  9226. {
  9227. ftppathlen = strlen(fnamePlusPath);
  9228. DEBUG_INFO("%s\n", fnamePlusPath);
  9229. fnamePlusPath[ftppathlen]='\0';
  9230. break;
  9231. }
  9232. i= i+1;
  9233. }
  9234. /* close */
  9235. pclose(fp);
  9236. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9237. {
  9238. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9239. {
  9240. fnamePlusPath[k]='\0';
  9241. }
  9242. }
  9243. i=1;
  9244. //char fname[60]={0};
  9245. while(i < ftppathlen)
  9246. {
  9247. int len=ftppathlen-i;
  9248. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9249. {
  9250. DEBUG_INFO("compare '/' all right\n");
  9251. break;
  9252. }
  9253. i=i+1;
  9254. }
  9255. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9256. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9257. fnamePWithNoPath[i+1] = '\0';
  9258. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9259. {
  9260. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9261. {
  9262. fnamePWithNoPath[j]='\0';
  9263. }
  9264. }
  9265. FILE* fp1 = fopen(fnamePlusPath, "r");
  9266. if (fp1)
  9267. {
  9268. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9269. // file exists
  9270. fclose(fp1);
  9271. }
  9272. else
  9273. {
  9274. // file doesn't exist
  9275. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9276. }
  9277. }
  9278. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9279. {
  9280. mtrace();
  9281. int result = FAIL;
  9282. time_t CurrentTime;
  9283. struct tm *tm;
  9284. pthread_t th_Status;
  9285. CurrentTime = time(NULL);
  9286. tm = localtime(&CurrentTime);
  9287. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9288. 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);
  9289. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9290. if(!interLock.isGetDiagnosticGoing)
  9291. {
  9292. interLock.isGetDiagnosticGoing = 1;
  9293. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9294. sleep(1);
  9295. }
  9296. else
  9297. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9298. return result;
  9299. }
  9300. void* GetDiagnosticsProcess(void* data)
  9301. {
  9302. pthread_detach(pthread_self());
  9303. mtrace();
  9304. int retriesInt=0, retryIntervalInt=0;
  9305. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9306. 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};
  9307. int port=0;
  9308. int isSuccess = FALSE;
  9309. char ftpbuf[200]={0};
  9310. char cmdBuf[2048];
  9311. struct tm *tmNow;
  9312. time_t CurrentTime;
  9313. struct tm tmStart;
  9314. struct tm tmStop;
  9315. CurrentTime = time(NULL);
  9316. tmNow=localtime(&CurrentTime);
  9317. uint16_t targetYear, targetMonth;
  9318. json_object *GetDiagnostics;
  9319. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9320. GetDiagnostics = json_tokener_parse(data);
  9321. if(!is_error(GetDiagnostics))
  9322. {
  9323. // Required data
  9324. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9325. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9326. // Optional data
  9327. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9328. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9329. else
  9330. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9331. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9332. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9333. else
  9334. retryIntervalInt = 30;
  9335. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9336. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9337. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9338. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9339. }
  9340. json_object_put(GetDiagnostics);
  9341. // Pack log to compress file
  9342. 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) &&
  9343. (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))
  9344. {
  9345. // Pack system log
  9346. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9347. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9348. targetYear = tmStart.tm_year;
  9349. targetMonth = tmStart.tm_mon;
  9350. do
  9351. {
  9352. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9353. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9354. if(targetMonth+1>=13)
  9355. {
  9356. targetYear += 1;
  9357. targetMonth = 1;
  9358. }
  9359. else
  9360. {
  9361. targetMonth += 1;
  9362. }
  9363. }while((targetYear < (tmNow->tm_year+1900)) ||
  9364. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9365. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9366. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9367. system(cmdBuf);
  9368. // Pack charging & event log
  9369. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9370. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9371. targetYear = tmStart.tm_year;
  9372. targetMonth = tmStart.tm_mon;
  9373. do
  9374. {
  9375. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9376. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9377. if(targetMonth+1>=13)
  9378. {
  9379. targetYear += 1;
  9380. targetMonth = 1;
  9381. }
  9382. else
  9383. {
  9384. targetMonth += 1;
  9385. }
  9386. }while((targetYear < (tmNow->tm_year+1900)) ||
  9387. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9388. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9389. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9390. system(cmdBuf);
  9391. // Combine log file
  9392. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9393. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9394. }
  9395. else
  9396. {
  9397. system("exec /root/logPackTools 'log' 6");
  9398. }
  9399. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9400. system(cmdBuf);
  9401. checkUploadLog();
  9402. //****************location*******************/
  9403. if(strcmp(locationstr,"")==0)
  9404. {
  9405. DEBUG_INFO("location is <Empty>!\n");
  9406. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9407. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9408. goto end;
  9409. }
  9410. memset(protocol, 0, ARRAY_SIZE(protocol));
  9411. memset(user, 0, ARRAY_SIZE(user) );
  9412. memset(password, 0, ARRAY_SIZE(password));
  9413. memset(host, 0, ARRAY_SIZE(host));
  9414. memset(path, 0, ARRAY_SIZE(path));
  9415. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9416. memset(host1, 0, ARRAY_SIZE(host1));
  9417. memset(path1, 0, ARRAY_SIZE(path1));
  9418. /*location: ftp://user:password@host:port/path*/
  9419. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9420. if((access(fnamePlusPath,F_OK))!=-1)
  9421. {
  9422. DEBUG_INFO("fnamePlusPath exist.\n");
  9423. }
  9424. else
  9425. {
  9426. DEBUG_INFO("fnamePlusPath not exist!\n");
  9427. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9428. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9429. goto end;
  9430. }
  9431. if(strchr(locationstr,'@')==NULL)
  9432. {
  9433. sscanf(locationstr,
  9434. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9435. protocol, host, &port, path);
  9436. strcpy(user,"anonymous");
  9437. strcpy(password,"");
  9438. }
  9439. else
  9440. {
  9441. //DEBUG_INFO("pch=%s\n", pch);
  9442. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9443. protocol, user, password, host, &port, path);
  9444. }
  9445. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9446. {
  9447. DEBUG_INFO("protocol is not ftp/http ! \n");
  9448. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9449. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9450. goto end;
  9451. }
  9452. if(strncmp(locationstr,"http", 4) == 0)
  9453. {
  9454. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9455. sprintf(ftppath,"/%s", path);
  9456. do
  9457. {
  9458. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9459. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9460. sleep(3);
  9461. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9462. if(!isSuccess)
  9463. {
  9464. DEBUG_INFO("Diagnostics fail.\n");
  9465. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9466. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9467. sleep(retryIntervalInt);
  9468. }
  9469. else
  9470. {
  9471. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9472. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9473. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9474. }
  9475. retriesInt--;
  9476. }while((isSuccess == 0)&&(retriesInt >= 0));
  9477. }
  9478. else
  9479. {
  9480. sscanf(host,"%[^/]%s",host1, path1);
  9481. if(strlen(path) > 0)
  9482. sprintf(ftppath,"/%s", path);
  9483. else
  9484. sprintf(ftppath,"/%s", path1);
  9485. int ftppathlen=strlen(ftppath);
  9486. int i=1;
  9487. char filenametemp[50];
  9488. while(i < ftppathlen)
  9489. {
  9490. int len=ftppathlen-i;
  9491. if(ftppath[len]== 47) // '/' ascll code: 47
  9492. {
  9493. DEBUG_INFO("find '/' all right\n");
  9494. break;
  9495. }
  9496. i=i+1;
  9497. }
  9498. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9499. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9500. filenametemp[i+1] = 0;
  9501. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9502. if(port == 0)
  9503. port = 21;
  9504. do
  9505. {
  9506. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9507. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9508. sleep(3);
  9509. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9510. if(!isSuccess)
  9511. {
  9512. DEBUG_INFO("Diagnostics fail.\n");
  9513. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9514. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9515. sleep(retryIntervalInt);
  9516. }
  9517. else
  9518. {
  9519. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9520. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9521. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9522. }
  9523. retriesInt--;
  9524. }while((!isSuccess)&&(retriesInt >= 0));
  9525. }
  9526. end:
  9527. system("rm -f /mnt/*");
  9528. sleep(5);
  9529. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9530. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9531. interLock.isGetDiagnosticGoing = 0;
  9532. pthread_exit(NULL);
  9533. }
  9534. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9535. {
  9536. mtrace();
  9537. int result = FAIL;
  9538. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9539. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9540. {
  9541. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9542. locallistVersion = -1;
  9543. }
  9544. else
  9545. {
  9546. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9547. OCPP_getListVerion();
  9548. }
  9549. //from db.OCPP_getListVerion
  9550. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9551. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9552. sendGetLocalListVersionConfirmation(uuid,"");
  9553. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9554. return result;
  9555. }
  9556. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9557. {
  9558. mtrace();
  9559. int result = FAIL;
  9560. int connectorIdInt=-1;
  9561. int tempIndex = 0;
  9562. int connectorIdIsNULL, chargingProfileIsNULL;
  9563. char comfirmstr[20]={0};
  9564. char cmdBuf[512];
  9565. json_object *RemoteStartTransaction;
  9566. FILE *fp;
  9567. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9568. if(server_pending == TRUE)
  9569. {
  9570. return 0;
  9571. }
  9572. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9573. RemoteStartTransaction = json_tokener_parse(payload);
  9574. if(!is_error(RemoteStartTransaction))
  9575. {
  9576. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9577. {
  9578. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9579. }
  9580. else
  9581. {
  9582. connectorIdIsNULL = TRUE;
  9583. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9584. {
  9585. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9586. {
  9587. connectorIdIsNULL = FALSE;
  9588. connectorIdInt = (gun_index+1);
  9589. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9590. break;
  9591. }
  9592. }
  9593. }
  9594. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9595. {
  9596. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9597. // Required data
  9598. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9599. // Optional data
  9600. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9601. {
  9602. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9603. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9604. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9605. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9606. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9607. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9608. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9609. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9610. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9611. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9612. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9613. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9614. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9615. {
  9616. 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")));
  9617. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9618. 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"));
  9619. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9620. 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"));
  9621. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9622. 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")));
  9623. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9624. {
  9625. 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++)
  9626. {
  9627. 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"));
  9628. 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"));
  9629. 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)
  9630. 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"));
  9631. }
  9632. }
  9633. }
  9634. }
  9635. else
  9636. {
  9637. chargingProfileIsNULL = TRUE;
  9638. }
  9639. }
  9640. }
  9641. else
  9642. {
  9643. connectorIdIsNULL = TRUE;
  9644. }
  9645. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9646. {
  9647. DEBUG_WARN("Connector id is NULL\n.");
  9648. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9649. goto end;
  9650. }
  9651. /*
  9652. enum _SYSTEM_STATUS
  9653. {
  9654. S_BOOTING = 0,
  9655. S_IDLE, = 1
  9656. S_AUTHORIZING, = 2
  9657. S_REASSIGN_CHECK, = 3
  9658. S_REASSIGN, = 4
  9659. S_PRECHARGE, = 5
  9660. S_PREPARING_FOR_EV, = 6
  9661. S_PREPARING_FOR_EVSE, = 7
  9662. S_CHARGING, = 8
  9663. S_TERMINATING, = 9
  9664. S_COMPLETE, = 10
  9665. S_ALARM, = 11
  9666. S_FAULT = 12
  9667. }
  9668. */
  9669. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9670. {
  9671. //check Transaction active
  9672. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9673. {
  9674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9675. {
  9676. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9677. }
  9678. else
  9679. {
  9680. tempIndex = connectorIdInt -1;
  9681. }
  9682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9683. {
  9684. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9685. {
  9686. 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))
  9687. {
  9688. //Reserved
  9689. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9690. }
  9691. 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))
  9692. {
  9693. //Reserved
  9694. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9695. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9696. goto end;
  9697. }
  9698. else
  9699. {
  9700. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9701. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9702. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9703. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9704. {
  9705. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9706. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9707. goto end;
  9708. }
  9709. }//END FOR ELSE
  9710. }
  9711. }// END FOR CHAdeMO_QUANTITY
  9712. }
  9713. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9714. {
  9715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9716. {
  9717. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9718. }
  9719. else
  9720. {
  9721. tempIndex = connectorIdInt -1;
  9722. }
  9723. for (int index = 0; index < CCS_QUANTITY; index++)
  9724. {
  9725. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9726. {
  9727. 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))
  9728. {
  9729. //Reserved
  9730. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9731. }
  9732. 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))
  9733. {
  9734. //Reserved
  9735. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9736. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9737. goto end;
  9738. }
  9739. else
  9740. {
  9741. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9742. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9743. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9744. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9745. {
  9746. DEBUG_WARN("CCS connector not allow start\n.");
  9747. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9748. goto end;
  9749. }
  9750. }// END FOR ELSE
  9751. }
  9752. }// END FOR CCS_QUANTITY
  9753. }
  9754. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9755. {
  9756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9757. {
  9758. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9759. }
  9760. else
  9761. {
  9762. tempIndex = connectorIdInt -1;
  9763. }
  9764. for (int index = 0; index < GB_QUANTITY; index++)
  9765. {
  9766. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9767. {
  9768. 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))
  9769. {
  9770. //Reserved
  9771. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9772. }
  9773. 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))
  9774. {
  9775. //Reserved
  9776. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9777. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9778. goto end;
  9779. }
  9780. else
  9781. {
  9782. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9783. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9785. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9786. {
  9787. DEBUG_WARN("GB connector not allow start\n.");
  9788. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9789. goto end;
  9790. }
  9791. }// END FOR ELSE
  9792. }
  9793. } // END FOR GB_QUANTITY
  9794. }
  9795. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9796. {
  9797. tempIndex = connectorIdInt -1;
  9798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9799. {
  9800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9801. {
  9802. 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))
  9803. {
  9804. //Reserved
  9805. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9806. }
  9807. 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))
  9808. {
  9809. //Reserved
  9810. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9811. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9812. goto end;
  9813. }
  9814. else
  9815. {
  9816. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9817. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9818. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9819. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9820. {
  9821. DEBUG_WARN("GB connector not allow start\n.");
  9822. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9823. goto end;
  9824. }
  9825. }// END FOR ELSE
  9826. }
  9827. } // END FOR GB_QUANTITY
  9828. }
  9829. else
  9830. {
  9831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9832. {
  9833. tempIndex = 2;
  9834. }
  9835. else
  9836. {
  9837. tempIndex = connectorIdInt -1;
  9838. }
  9839. for (int index = 0; index < AC_QUANTITY; index++)
  9840. {
  9841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9842. {
  9843. 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))
  9844. {
  9845. //Reserved
  9846. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9847. }
  9848. 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))
  9849. {
  9850. //Reserved
  9851. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9852. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9853. goto end;
  9854. }
  9855. else
  9856. {
  9857. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9858. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9859. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9860. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9861. {
  9862. DEBUG_WARN("AC connector not allow start\n.");
  9863. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9864. goto end;
  9865. }
  9866. }//END FOR ELSE
  9867. }
  9868. }// END FOR AC_QUANTITY
  9869. }
  9870. if(chargingProfileIsNULL == FALSE)
  9871. {
  9872. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9873. {
  9874. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9875. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9876. //memset idTag
  9877. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9878. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9879. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9881. // Save profile to file
  9882. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9883. system(cmdBuf);
  9884. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9885. fp = fopen(cmdBuf, "w");
  9886. 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));
  9887. fclose(fp);
  9888. }
  9889. else
  9890. {
  9891. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9892. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9893. }
  9894. }
  9895. else
  9896. {
  9897. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9898. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9899. //memset idTag
  9900. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9901. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9902. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9904. }
  9905. }
  9906. else
  9907. {
  9908. DEBUG_WARN("Connector id over\n.");
  9909. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9910. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9911. }
  9912. end:
  9913. json_object_put(RemoteStartTransaction);
  9914. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9915. {
  9916. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9917. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9918. }
  9919. //OCPP send RemoteStartConfirmation by first.
  9920. sendRemoteStartConfirmation(uuid, comfirmstr);
  9921. return result;
  9922. }
  9923. int handleRemoteStartRequest(char *uuid, char *payload)
  9924. {
  9925. mtrace();
  9926. int result = PASS;
  9927. int connectorIdInt=-1;
  9928. int tempIndex = 0;
  9929. char comfirmstr[20]={0};
  9930. char cmdBuf[512];
  9931. json_object *RemoteStartTransaction;
  9932. FILE *fp;
  9933. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9934. if(server_pending == TRUE)
  9935. {
  9936. result = FAIL;
  9937. }
  9938. RemoteStartTransaction = json_tokener_parse(payload);
  9939. if(!is_error(RemoteStartTransaction))
  9940. {
  9941. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9942. {
  9943. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9944. }
  9945. else
  9946. {
  9947. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9948. {
  9949. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9950. {
  9951. connectorIdInt = (gun_index+1);
  9952. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9953. break;
  9954. }
  9955. }
  9956. }
  9957. if(connectorIdInt == 0)
  9958. {
  9959. DEBUG_WARN("Connector id shall not equal 0.\n");
  9960. result = FAIL;
  9961. }
  9962. else if(connectorIdInt == -1)
  9963. {
  9964. DEBUG_INFO("Connector id does not specific.\n");
  9965. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9966. {
  9967. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  9968. // Required data
  9969. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9970. // Optional data
  9971. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9972. {
  9973. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9974. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9975. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9976. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9977. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9978. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9979. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9980. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9981. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9982. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9983. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9984. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9985. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9986. {
  9987. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  9988. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9989. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  9990. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9991. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  9992. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9993. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  9994. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9995. {
  9996. 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++)
  9997. {
  9998. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  9999. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10000. 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)
  10001. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10002. }
  10003. }
  10004. }
  10005. }
  10006. else
  10007. {
  10008. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10009. }
  10010. }
  10011. }
  10012. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10013. {
  10014. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10015. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10016. // Required data
  10017. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10018. // Optional data
  10019. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10020. {
  10021. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10022. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10023. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10024. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10025. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10026. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10027. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10028. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10029. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10030. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10031. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10032. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10033. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10034. {
  10035. 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")));
  10036. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10037. 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"));
  10038. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10039. 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"));
  10040. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10041. 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")));
  10042. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10043. {
  10044. 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++)
  10045. {
  10046. 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"));
  10047. 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"));
  10048. 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)
  10049. 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"));
  10050. }
  10051. }
  10052. }
  10053. }
  10054. else
  10055. {
  10056. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10057. }
  10058. }
  10059. else
  10060. {
  10061. DEBUG_WARN("Connector id is over maximun value.\n");
  10062. result = FAIL;
  10063. }
  10064. }
  10065. if(result == PASS)
  10066. {
  10067. if(connectorIdInt > 0)
  10068. {
  10069. //check Transaction active
  10070. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10071. {
  10072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10073. {
  10074. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10075. }
  10076. else
  10077. {
  10078. tempIndex = connectorIdInt -1;
  10079. }
  10080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10081. {
  10082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10083. {
  10084. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10085. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10086. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10087. {
  10088. //Reserved
  10089. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10090. }
  10091. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10092. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10093. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10094. {
  10095. //Reserved
  10096. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10097. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10098. goto end;
  10099. }
  10100. else
  10101. {
  10102. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10103. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10104. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10105. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10106. {
  10107. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10108. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10109. goto end;
  10110. }
  10111. }//END FOR ELSE
  10112. }
  10113. }// END FOR CHAdeMO_QUANTITY
  10114. }
  10115. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10116. {
  10117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10118. {
  10119. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10120. }
  10121. else
  10122. {
  10123. tempIndex = connectorIdInt -1;
  10124. }
  10125. for (int index = 0; index < CCS_QUANTITY; index++)
  10126. {
  10127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10128. {
  10129. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10130. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10131. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10132. {
  10133. //Reserved
  10134. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10135. }
  10136. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10137. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10138. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10139. {
  10140. //Reserved
  10141. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10142. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10143. goto end;
  10144. }
  10145. else
  10146. {
  10147. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10148. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10149. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10150. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10151. {
  10152. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10153. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10154. goto end;
  10155. }
  10156. }// END FOR ELSE
  10157. }
  10158. }// END FOR CCS_QUANTITY
  10159. }
  10160. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10161. {
  10162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10163. {
  10164. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10165. }
  10166. else
  10167. {
  10168. tempIndex = connectorIdInt -1;
  10169. }
  10170. for (int index = 0; index < GB_QUANTITY; index++)
  10171. {
  10172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10173. {
  10174. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10175. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10176. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10177. {
  10178. //Reserved
  10179. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10180. }
  10181. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10182. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10183. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10184. {
  10185. //Reserved
  10186. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10188. goto end;
  10189. }
  10190. else
  10191. {
  10192. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10193. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10194. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10195. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10196. {
  10197. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10198. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10199. goto end;
  10200. }
  10201. }// END FOR ELSE
  10202. }
  10203. } // END FOR GB_QUANTITY
  10204. }
  10205. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10206. {
  10207. tempIndex = connectorIdInt -1;
  10208. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10209. {
  10210. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10211. {
  10212. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10213. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10214. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10215. {
  10216. //Reserved
  10217. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10218. }
  10219. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10220. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10221. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10222. {
  10223. //Reserved
  10224. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10225. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10226. goto end;
  10227. }
  10228. else
  10229. {
  10230. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10231. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10232. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10233. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10234. {
  10235. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10237. goto end;
  10238. }
  10239. }// END FOR ELSE
  10240. }
  10241. } // END FOR GB_QUANTITY
  10242. }
  10243. else
  10244. {
  10245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10246. {
  10247. tempIndex = 2;
  10248. }
  10249. else
  10250. {
  10251. tempIndex = connectorIdInt -1;
  10252. }
  10253. for (int index = 0; index < AC_QUANTITY; index++)
  10254. {
  10255. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10256. {
  10257. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10258. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10259. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10260. {
  10261. //Reserved
  10262. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10263. }
  10264. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10265. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10266. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10267. {
  10268. //Reserved
  10269. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10271. goto end;
  10272. }
  10273. else
  10274. {
  10275. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10276. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10277. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10278. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10279. {
  10280. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10281. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10282. goto end;
  10283. }
  10284. }//END FOR ELSE
  10285. }
  10286. }// END FOR AC_QUANTITY
  10287. }
  10288. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10289. {
  10290. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10291. {
  10292. // Save profile to file
  10293. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10294. system(cmdBuf);
  10295. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10296. fp = fopen(cmdBuf, "w");
  10297. 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));
  10298. fclose(fp);
  10299. }
  10300. else
  10301. {
  10302. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10303. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10304. goto end;
  10305. }
  10306. }
  10307. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10308. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10309. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10310. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10311. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10313. }
  10314. else
  10315. {
  10316. uint8_t isHasIdleConnector = FALSE;
  10317. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10318. {
  10319. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10320. {
  10321. isHasIdleConnector = TRUE;
  10322. break;
  10323. }
  10324. }
  10325. if(isHasIdleConnector == TRUE)
  10326. {
  10327. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10328. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10329. {
  10330. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10331. {
  10332. // Save profile to file
  10333. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10334. system(cmdBuf);
  10335. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10336. fp = fopen(cmdBuf, "w");
  10337. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10338. fclose(fp);
  10339. refreshStartTimer(&clientTime.RemoteStartWait);
  10340. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10342. }
  10343. else
  10344. {
  10345. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10346. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10347. }
  10348. }
  10349. else
  10350. {
  10351. refreshStartTimer(&clientTime.RemoteStartWait);
  10352. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10353. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10354. }
  10355. }
  10356. else
  10357. {
  10358. DEBUG_INFO("There is not any connector is idle.\n");
  10359. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10360. }
  10361. }
  10362. }
  10363. else
  10364. {
  10365. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10366. }
  10367. end:
  10368. json_object_put(RemoteStartTransaction);
  10369. sendRemoteStartConfirmation(uuid, comfirmstr);
  10370. return result;
  10371. }
  10372. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10373. {
  10374. mtrace();
  10375. int result = FAIL;
  10376. int match = FALSE;
  10377. int GunNO = 0;
  10378. int tempIndex = 0;
  10379. int transactionIdInt=0;
  10380. int transactionIdIsNULL= TRUE;
  10381. char comfirmstr[20];
  10382. json_object *RemoteStopTransaction;
  10383. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10384. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10385. if(server_pending == TRUE)
  10386. {
  10387. return 0;
  10388. }
  10389. RemoteStopTransaction = json_tokener_parse(payload);
  10390. if(!is_error(RemoteStopTransaction))
  10391. {
  10392. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10393. {
  10394. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10395. transactionIdIsNULL = FALSE;
  10396. }
  10397. }
  10398. json_object_put(RemoteStopTransaction);
  10399. if(transactionIdIsNULL == FALSE)
  10400. {
  10401. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10402. {
  10403. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10404. {
  10405. //check Transaction active
  10406. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10407. {
  10408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10409. {
  10410. tempIndex = ((gun_index==2) ? 1: 0);
  10411. }
  10412. else
  10413. {
  10414. tempIndex = gun_index;
  10415. }
  10416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10417. {
  10418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10419. {
  10420. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10421. {
  10422. match = TRUE;
  10423. GunNO = gun_index;
  10424. }
  10425. }
  10426. }// END FOR CHAdeMO_QUANTITY
  10427. }
  10428. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10429. {
  10430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10431. {
  10432. tempIndex = ((gun_index==2) ? 1: 0);
  10433. }
  10434. else
  10435. {
  10436. tempIndex = gun_index;
  10437. }
  10438. for (int index = 0; index < CCS_QUANTITY; index++)
  10439. {
  10440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10441. {
  10442. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10443. {
  10444. match = TRUE;
  10445. GunNO = gun_index;
  10446. }
  10447. }
  10448. }// END FOR CCS_QUANTITY
  10449. }
  10450. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10451. {
  10452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10453. {
  10454. tempIndex = ((gun_index==2) ? 1: 0);
  10455. }
  10456. else
  10457. {
  10458. tempIndex = gun_index;
  10459. }
  10460. for (int index = 0; index < GB_QUANTITY; index++)
  10461. {
  10462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10463. {
  10464. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10465. {
  10466. match = TRUE;
  10467. GunNO = gun_index;
  10468. }
  10469. }
  10470. }// END FOR GB_QUANTITY
  10471. }
  10472. else if(gunType[gun_index] == GUN_TYPE_DO)
  10473. {
  10474. tempIndex = gun_index;
  10475. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10476. {
  10477. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10478. {
  10479. 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
  10480. {
  10481. match = TRUE;
  10482. GunNO = gun_index;
  10483. }
  10484. }
  10485. }// END FOR GB_QUANTITY
  10486. }
  10487. else
  10488. {
  10489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10490. {
  10491. tempIndex = 2;
  10492. }
  10493. else
  10494. {
  10495. tempIndex = gun_index;
  10496. }
  10497. for (int index = 0; index < AC_QUANTITY; index++)
  10498. {
  10499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10500. {
  10501. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10502. {
  10503. match = TRUE;
  10504. GunNO = gun_index;
  10505. }
  10506. }
  10507. }// END FOR CHAdeMO_QUANTITY
  10508. } // END FOR AC ELSE
  10509. }// CHECK IF ResponseTransactionId == transactionIdInt
  10510. }//END FOR
  10511. if( match == TRUE)
  10512. {
  10513. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10515. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10516. }
  10517. else
  10518. {
  10519. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10520. }
  10521. }
  10522. else
  10523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10524. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10525. return result;
  10526. }
  10527. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10528. {
  10529. mtrace();
  10530. int result = FAIL;
  10531. int connectorIdInt=0, reservationIdInt=0;
  10532. int tempIndex = 0;
  10533. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10534. char comfirmstr[20]={0};
  10535. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10536. int c = 0;
  10537. char *loc;
  10538. //char *ptr;
  10539. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10540. strcpy(sstrtemp, stringtrimspace(payload));
  10541. //***(1)connectorId ****/
  10542. c=0;
  10543. loc = strstr(sstrtemp, "connectorId");
  10544. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10545. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10546. {
  10547. sstr[c] = loc[strlen("connectorId")+2+c];
  10548. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10549. c++;
  10550. }
  10551. sstr[c] = '\0';
  10552. connectorIdInt = atoi(sstr);
  10553. //***(2)expiryDate ****/
  10554. loc = strstr(sstrtemp, "expiryDate");
  10555. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10556. c = 0;
  10557. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10558. {
  10559. sstr[c] = loc[3+strlen("expiryDate")+c];
  10560. c++;
  10561. }
  10562. sstr[c] = '\0';
  10563. strcpy(expiryDatestr, sstr);
  10564. //***(3)idTag ****/
  10565. loc = strstr(sstrtemp, "idTag");
  10566. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10567. c = 0;
  10568. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10569. {
  10570. sstr[c] = loc[3+strlen("idTag")+c];
  10571. c++;
  10572. }
  10573. sstr[c] = '\0';
  10574. strcpy(idTagstr, sstr);
  10575. //***(4)parentIdTag ****/
  10576. loc = strstr(sstrtemp, "parentIdTag");
  10577. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10578. c = 0;
  10579. if(loc == NULL)
  10580. {
  10581. strcpy(parentIdTagstr, "");
  10582. }
  10583. else
  10584. {
  10585. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10586. {
  10587. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10588. c++;
  10589. }
  10590. sstr[c] = '\0';
  10591. strcpy(parentIdTagstr, sstr);
  10592. }
  10593. //***(5)reservationId ****/
  10594. c=0;
  10595. loc = strstr(sstrtemp, "reservationId");
  10596. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10597. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10598. {
  10599. sstr[c] = loc[strlen("reservationId")+2+c];
  10600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10601. c++;
  10602. }
  10603. sstr[c] = '\0';
  10604. reservationIdInt = atoi(sstr);
  10605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10606. /*
  10607. enum SYSTEM_STATUS
  10608. {
  10609. SYS_MODE_BOOTING = 0,
  10610. SYS_MODE_IDLE = 1,
  10611. SYS_MODE_AUTHORIZING = 2,
  10612. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10613. SYS_MODE_REASSIGN = 4,
  10614. SYS_MODE_PREPARING = 5,
  10615. SYS_MODE_PREPARE_FOR_EV = 6,
  10616. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10617. SYS_MODE_CHARGING = 8,
  10618. SYS_MODE_TERMINATING = 9,
  10619. SYS_MODE_COMPLETE = 10,
  10620. SYS_MODE_ALARM = 11,
  10621. SYS_MODE_FAULT = 12,
  10622. SYS_MODE_RESERVATION = 13,
  10623. SYS_MODE_BOOKING = 14,
  10624. SYS_MODE_MAINTAIN = 15,
  10625. SYS_MODE_DEBUG = 16,
  10626. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10627. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10628. SYS_MODE_UPDATE = 19
  10629. };
  10630. */
  10631. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10632. {
  10633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10634. goto end;
  10635. }
  10636. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10637. {
  10638. //check Transaction active
  10639. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10640. {
  10641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10642. {
  10643. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10644. }
  10645. else
  10646. {
  10647. tempIndex = connectorIdInt -1;
  10648. }
  10649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10650. {
  10651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10652. {
  10653. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10654. {
  10655. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10656. {
  10657. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10658. {
  10659. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10661. }
  10662. 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'))
  10663. {
  10664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10665. }
  10666. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10667. {
  10668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10669. }
  10670. else
  10671. {
  10672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10673. }
  10674. }
  10675. 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
  10676. {
  10677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10678. }
  10679. }
  10680. else
  10681. {
  10682. //replace reservation
  10683. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10685. }
  10686. }
  10687. } // END FOR CHAdeMO_QUANTITY
  10688. }
  10689. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10690. {
  10691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10692. {
  10693. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10694. }
  10695. else
  10696. {
  10697. tempIndex = connectorIdInt -1;
  10698. }
  10699. for (int index = 0; index < CCS_QUANTITY; index++)
  10700. {
  10701. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10702. {
  10703. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10704. {
  10705. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10706. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10707. {
  10708. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10709. {
  10710. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10712. }
  10713. 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'))
  10714. {
  10715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10716. }
  10717. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10718. {
  10719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10720. }
  10721. else
  10722. {
  10723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10724. }
  10725. }
  10726. 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
  10727. {
  10728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10729. }
  10730. }
  10731. else
  10732. {
  10733. //replace reservation
  10734. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10736. }
  10737. }
  10738. } // END FOR CCS_QUANTITY
  10739. }
  10740. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10741. {
  10742. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10743. {
  10744. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10745. }
  10746. else
  10747. {
  10748. tempIndex = connectorIdInt -1;
  10749. }
  10750. for (int index = 0; index < GB_QUANTITY; index++)
  10751. {
  10752. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10753. {
  10754. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10755. {
  10756. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10757. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10758. {
  10759. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10760. {
  10761. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10763. }
  10764. 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'))
  10765. {
  10766. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10767. }
  10768. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10769. {
  10770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10771. }
  10772. else
  10773. {
  10774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10775. }
  10776. }
  10777. 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
  10778. {
  10779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10780. }
  10781. }
  10782. else
  10783. {
  10784. //replace reservation
  10785. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10786. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10787. }
  10788. }
  10789. }// END FOR GB_QUANTITY
  10790. }
  10791. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10792. {
  10793. tempIndex = connectorIdInt -1;
  10794. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10795. {
  10796. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10797. {
  10798. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10799. {
  10800. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10801. 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
  10802. {
  10803. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10804. {
  10805. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10807. }
  10808. 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'))
  10809. {
  10810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10811. }
  10812. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10813. {
  10814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10815. }
  10816. else
  10817. {
  10818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10819. }
  10820. }
  10821. 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
  10822. {
  10823. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10824. }
  10825. }
  10826. else
  10827. {
  10828. //replace reservation
  10829. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10830. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10831. }
  10832. }
  10833. }// END FOR GB_QUANTITY
  10834. }
  10835. else
  10836. {
  10837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10838. {
  10839. tempIndex = 2;
  10840. }
  10841. else
  10842. {
  10843. tempIndex = (connectorIdInt -1);
  10844. }
  10845. for (int index = 0; index < AC_QUANTITY; index++)
  10846. {
  10847. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10848. {
  10849. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10850. {
  10851. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10852. {
  10853. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10854. {
  10855. 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))
  10856. {
  10857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10858. }
  10859. else
  10860. {
  10861. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10863. }
  10864. }
  10865. 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'))
  10866. {
  10867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10868. }
  10869. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10870. {
  10871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10872. }
  10873. else
  10874. {
  10875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10876. }
  10877. }
  10878. 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
  10879. {
  10880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10881. }
  10882. }
  10883. else
  10884. {
  10885. //replace reservation
  10886. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10888. }
  10889. }
  10890. } // END FOR AC_QUANTITY
  10891. }
  10892. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10893. }
  10894. else if(connectorIdInt == 0)
  10895. {
  10896. //check Transaction active
  10897. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10898. {
  10899. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10900. {
  10901. 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'))
  10902. {
  10903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10904. goto end;
  10905. }
  10906. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10907. {
  10908. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10909. goto end;
  10910. }
  10911. 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
  10912. {
  10913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10914. goto end;
  10915. }
  10916. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10917. {
  10918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10919. goto end;
  10920. }
  10921. }
  10922. }// END FOR CHAdeMO_QUANTITY
  10923. for (int index = 0; index < CCS_QUANTITY; index++)
  10924. {
  10925. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10926. {
  10927. 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'))
  10928. {
  10929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10930. goto end;
  10931. }
  10932. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10933. {
  10934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10935. goto end;
  10936. }
  10937. 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
  10938. {
  10939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10940. goto end;
  10941. }
  10942. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10943. {
  10944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10945. goto end;
  10946. }
  10947. }
  10948. } // END FOR CCS_QUANTITY
  10949. for (int index = 0; index < GB_QUANTITY; index++)
  10950. {
  10951. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10952. {
  10953. 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'))
  10954. {
  10955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10956. goto end;
  10957. }
  10958. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10959. {
  10960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10961. goto end;
  10962. }
  10963. 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
  10964. {
  10965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10966. goto end;
  10967. }
  10968. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10969. {
  10970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10971. goto end;
  10972. }
  10973. }
  10974. } // END FOR GB_QUANTITY
  10975. for (int index = 0; index < AC_QUANTITY; index++)
  10976. {
  10977. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10978. {
  10979. 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'))
  10980. {
  10981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10982. goto end;
  10983. }
  10984. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10985. {
  10986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10987. goto end;
  10988. }
  10989. 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
  10990. {
  10991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10992. goto end;
  10993. }
  10994. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10995. {
  10996. 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))
  10997. {
  10998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10999. goto end;
  11000. }
  11001. }
  11002. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11003. {
  11004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11005. goto end;
  11006. }
  11007. }
  11008. }// END FOR AC_QUANTITY
  11009. //The connectorId is 0
  11010. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11012. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11013. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11014. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11015. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11016. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11017. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11018. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11019. result = TRUE;
  11020. return result;
  11021. }
  11022. else
  11023. {
  11024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11025. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11026. }
  11027. if(strcmp(comfirmstr,"Accepted") == 0)
  11028. {
  11029. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11030. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11031. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11032. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11033. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11034. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11035. result = TRUE;
  11036. return result;
  11037. }
  11038. end:
  11039. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11040. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11041. return result;
  11042. }
  11043. int handleResetRequest(char *uuid, char *payload)
  11044. {
  11045. mtrace();
  11046. int result = FAIL;
  11047. char sstr[10]={0},sstrtemp[30]={ 0 };
  11048. char typestr[10]={0};
  11049. char comfirmstr[20]={0};
  11050. int c = 0;
  11051. char *loc;
  11052. DEBUG_INFO("handleResetRequest...\n");
  11053. strcpy(sstrtemp, stringtrimspace(payload));
  11054. loc = strstr(sstrtemp, "type");
  11055. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11056. c = 0;
  11057. while (loc[3+strlen("type")+c] != '\"')
  11058. {
  11059. sstr[c] = loc[3+strlen("type")+c];
  11060. c++;
  11061. }
  11062. sstr[c] = '\0';
  11063. strcpy(typestr,sstr);
  11064. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11065. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11066. {
  11067. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11068. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11069. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11070. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11071. }
  11072. else
  11073. {
  11074. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11075. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11076. result = PASS;
  11077. }
  11078. sendResetConfirmation(uuid, comfirmstr);
  11079. return result;
  11080. }
  11081. int handleSendLocalListRequest(char *uuid, char *payload)
  11082. {
  11083. mtrace();
  11084. int result = FAIL;
  11085. char comfirmstr[20];
  11086. int checkState_Faulted = FALSE;
  11087. json_object *SendLocalList;
  11088. DEBUG_INFO("handleSendLocalListRequest...\n");
  11089. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11090. {
  11091. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11092. goto end;
  11093. }
  11094. //check Charge Point state
  11095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11096. {
  11097. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11098. {
  11099. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11100. }
  11101. }
  11102. for (int index = 0; index < CCS_QUANTITY; index++)
  11103. {
  11104. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11105. {
  11106. checkState_Faulted = TRUE; //OCPP Status
  11107. }
  11108. }
  11109. for (int index = 0; index < GB_QUANTITY; index++)
  11110. {
  11111. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11112. {
  11113. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11114. }
  11115. }
  11116. //check Charge Point state
  11117. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11118. {
  11119. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11120. {
  11121. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11122. }
  11123. }
  11124. //check Charge Point state
  11125. for (int index = 0; index < AC_QUANTITY; index++)
  11126. {
  11127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11128. {
  11129. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11130. }
  11131. }
  11132. if(checkState_Faulted == TRUE)
  11133. {
  11134. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11135. goto end;
  11136. }
  11137. // Parsing payload
  11138. SendLocalList = json_tokener_parse(payload);
  11139. if(!is_error(SendLocalList))
  11140. {
  11141. // Required data
  11142. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11143. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11144. // Optional data
  11145. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11146. {
  11147. //Check UpdateType
  11148. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11149. {
  11150. //Local list full update
  11151. DEBUG_INFO("Local list full update.\n");
  11152. OCPP_getListVerion();
  11153. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11154. {
  11155. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11156. goto end;
  11157. }
  11158. OCPP_cleanLocalList();
  11159. }
  11160. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11161. {
  11162. //Local list different update
  11163. DEBUG_INFO("Local list different update.\n");
  11164. OCPP_getListVerion();
  11165. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11166. {
  11167. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11168. goto end;
  11169. }
  11170. }
  11171. else
  11172. {
  11173. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11174. goto end;
  11175. }
  11176. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11177. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11178. {
  11179. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  11180. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11181. {
  11182. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  11183. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11184. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  11185. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11186. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  11187. }
  11188. // Add to db
  11189. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11190. {
  11191. //Local list full update
  11192. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11193. idx,
  11194. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11195. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11196. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11197. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11198. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11199. // update list
  11200. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11201. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11202. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11203. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11204. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11205. }
  11206. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11207. {
  11208. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11209. idx,
  11210. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11211. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11212. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11213. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11214. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11215. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11216. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11217. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11218. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11219. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11220. }
  11221. }
  11222. }
  11223. else
  11224. {
  11225. //Check UpdateType
  11226. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11227. {
  11228. //Local list full update
  11229. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11230. OCPP_cleanLocalList();
  11231. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11232. goto end;
  11233. }
  11234. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11235. {
  11236. //Local list different update
  11237. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11238. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11239. goto end;
  11240. }
  11241. }
  11242. result = PASS;
  11243. }
  11244. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11245. end:
  11246. json_object_put(SendLocalList);
  11247. sendSendLocalListConfirmation(uuid, comfirmstr);
  11248. return result;
  11249. }
  11250. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11251. {
  11252. mtrace();
  11253. int result = FAIL;
  11254. struct StructSetChargingProfile SetProfileReq = {0};
  11255. int tempchargingProfileIdInt;
  11256. int chargingSchedulePeriodCount = 0;
  11257. char comfirmstr[20]={0};
  11258. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11259. char rmFileCmd[128]={0};
  11260. int profileQuantity = 0;
  11261. json_object *SetChargingProfile;
  11262. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11263. SetChargingProfile = json_tokener_parse(payload);
  11264. if(!is_error(SetChargingProfile))
  11265. {
  11266. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11267. {
  11268. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11269. }
  11270. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11271. {
  11272. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11273. {
  11274. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11275. }
  11276. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11277. {
  11278. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11279. }
  11280. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11281. {
  11282. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11283. }
  11284. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11285. {
  11286. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11287. }
  11288. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11289. {
  11290. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11291. }
  11292. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11293. {
  11294. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11295. }
  11296. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11297. {
  11298. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11299. }
  11300. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11301. {
  11302. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11303. }
  11304. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11305. {
  11306. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11307. {
  11308. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  11309. }
  11310. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11311. {
  11312. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11313. }
  11314. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11315. {
  11316. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11317. }
  11318. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11319. {
  11320. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  11321. }
  11322. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11323. {
  11324. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11325. if(chargingSchedulePeriodCount <= 10)
  11326. {
  11327. 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++)
  11328. {
  11329. 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)
  11330. {
  11331. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11332. }
  11333. 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)
  11334. {
  11335. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11336. }
  11337. 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)
  11338. {
  11339. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11340. }
  11341. }
  11342. }
  11343. }
  11344. }
  11345. }
  11346. }
  11347. // Profile periods quantity check
  11348. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11349. {
  11350. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11351. goto end;
  11352. }
  11353. // Check invalid limit
  11354. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11355. {
  11356. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11357. {
  11358. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  11359. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11360. {
  11361. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11362. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11363. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11364. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11365. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11366. goto end;
  11367. }
  11368. }
  11369. }
  11370. else
  11371. {
  11372. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11373. {
  11374. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower))
  11375. {
  11376. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11377. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11378. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11379. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11380. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11381. goto end;
  11382. }
  11383. }
  11384. }
  11385. // Profile purpose info check
  11386. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11387. {
  11388. FILE *fp;
  11389. char dataLine[4096]={0};
  11390. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11391. if(SetProfileReq.ConnectorId != 0)
  11392. {
  11393. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11394. goto end;
  11395. }
  11396. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11397. if (!fp)
  11398. {
  11399. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11400. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11401. }
  11402. else
  11403. {
  11404. while(fscanf(fp, "%s", dataLine) != EOF)
  11405. {
  11406. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11407. {
  11408. profileQuantity += 1;
  11409. }
  11410. }
  11411. }
  11412. fclose(fp);
  11413. }
  11414. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11415. {
  11416. FILE *fp;
  11417. char dataLine[4096]={0};
  11418. char filename[128]={0};
  11419. int tmpProfileQuantity;
  11420. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11421. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11422. {
  11423. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11424. goto end;
  11425. }
  11426. if(SetProfileReq.ConnectorId == 0)
  11427. {
  11428. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11429. {
  11430. tmpProfileQuantity = 0;
  11431. memset(filename, 0, ARRAY_SIZE(filename));
  11432. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11433. fp = fopen(filename, "r");
  11434. if (!fp)
  11435. {
  11436. DEBUG_INFO("%s does not create.\n", filename);
  11437. fp = fopen(filename, "w+");
  11438. }
  11439. else
  11440. {
  11441. while(fscanf(fp, "%s", dataLine) != EOF)
  11442. {
  11443. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11444. {
  11445. tmpProfileQuantity += 1;
  11446. }
  11447. }
  11448. }
  11449. fclose(fp);
  11450. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11451. }
  11452. }
  11453. else
  11454. {
  11455. memset(filename, 0, ARRAY_SIZE(filename));
  11456. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11457. fp = fopen(filename, "r");
  11458. if (!fp)
  11459. {
  11460. DEBUG_INFO("%s does not create.\n", filename);
  11461. fp = fopen(filename, "w+");
  11462. }
  11463. else
  11464. {
  11465. while(fscanf(fp, "%s", dataLine) != EOF)
  11466. {
  11467. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11468. {
  11469. profileQuantity += 1;
  11470. }
  11471. }
  11472. }
  11473. fclose(fp);
  11474. }
  11475. }
  11476. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11477. {
  11478. int isMatchTransactiodId= FALSE;
  11479. FILE *fp;
  11480. char dataLine[4096]={0};
  11481. char filename[128]={0};
  11482. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11483. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11484. if(SetProfileReq.ConnectorId == 0)
  11485. {
  11486. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11487. goto end;
  11488. }
  11489. int tempIndex = 0;
  11490. //check Transaction active
  11491. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11492. {
  11493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11494. {
  11495. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11496. }
  11497. else
  11498. {
  11499. tempIndex = SetProfileReq.ConnectorId -1;
  11500. }
  11501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11502. {
  11503. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11504. {
  11505. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11506. {
  11507. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11508. {
  11509. isMatchTransactiodId = TRUE;
  11510. break;
  11511. }
  11512. }
  11513. }
  11514. }
  11515. }
  11516. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11517. {
  11518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11519. {
  11520. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11521. }
  11522. else
  11523. {
  11524. tempIndex = SetProfileReq.ConnectorId -1;
  11525. }
  11526. for (int index = 0; index < CCS_QUANTITY; index++)
  11527. {
  11528. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11529. {
  11530. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11531. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11532. {
  11533. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11534. {
  11535. isMatchTransactiodId = TRUE;
  11536. break;
  11537. }
  11538. }
  11539. }
  11540. }
  11541. }
  11542. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11543. {
  11544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11545. {
  11546. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11547. }
  11548. else
  11549. {
  11550. tempIndex = SetProfileReq.ConnectorId -1;
  11551. }
  11552. for (int index = 0; index < GB_QUANTITY; index++)
  11553. {
  11554. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11555. {
  11556. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11557. {
  11558. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11559. {
  11560. isMatchTransactiodId = TRUE;
  11561. break;
  11562. }
  11563. }
  11564. }
  11565. }
  11566. }
  11567. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11568. {
  11569. tempIndex = SetProfileReq.ConnectorId -1;
  11570. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11571. {
  11572. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11573. {
  11574. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11575. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11576. {
  11577. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11578. {
  11579. isMatchTransactiodId = TRUE;
  11580. break;
  11581. }
  11582. }
  11583. }
  11584. }
  11585. }
  11586. else
  11587. {
  11588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11589. {
  11590. tempIndex = 2;
  11591. }
  11592. else
  11593. {
  11594. tempIndex = (SetProfileReq.ConnectorId -1);
  11595. }
  11596. for (int index = 0; index < AC_QUANTITY; index++)
  11597. {
  11598. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11599. {
  11600. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11601. {
  11602. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11603. {
  11604. isMatchTransactiodId = TRUE;
  11605. break;
  11606. }
  11607. }
  11608. }
  11609. }
  11610. }
  11611. //check Transaction active
  11612. if(isMatchTransactiodId == FALSE)
  11613. {
  11614. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11615. goto end;
  11616. }
  11617. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11618. {
  11619. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11620. goto end;
  11621. }
  11622. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11623. fp = fopen(filename, "r");
  11624. if (!fp)
  11625. {
  11626. DEBUG_INFO("%s does not create.\n", filename);
  11627. fp = fopen(filename, "w+");
  11628. }
  11629. else
  11630. {
  11631. //Check Charging Profile Count
  11632. while(fscanf(fp, "%s", dataLine) != EOF)
  11633. {
  11634. //DEBUG_INFO("word=%s\n",word);
  11635. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11636. {
  11637. profileQuantity += 1;
  11638. }
  11639. }
  11640. }
  11641. fclose(fp);
  11642. }
  11643. // Check ChargeProfileMaxStackLevel
  11644. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11645. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11646. {
  11647. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11648. goto end;
  11649. }
  11650. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11651. {
  11652. FILE *fp;
  11653. char dataLine[4096]={0};
  11654. char fnametemp[128]={0};
  11655. int tmpProfileQuantity;
  11656. //Check ChargePointMaxProfile.json exit
  11657. profileQuantity = 0;
  11658. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11659. {
  11660. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11661. //Check Charging Profile Count
  11662. tmpProfileQuantity = 0;
  11663. while(fscanf(fp, "%s", dataLine) != EOF)
  11664. {
  11665. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11666. {
  11667. profileQuantity += 1;
  11668. tmpProfileQuantity += 1;
  11669. }
  11670. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11671. }
  11672. fclose(fp);
  11673. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11674. }
  11675. //Check TxDefaultProfile_%d.json
  11676. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11677. {
  11678. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11679. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11680. if((access(fnametemp,F_OK))!=-1)
  11681. {
  11682. fp = fopen(fnametemp, "r");
  11683. //Check Charging Profile Count
  11684. tmpProfileQuantity = 0;
  11685. while(fscanf(fp, "%s", dataLine) != EOF)
  11686. {
  11687. //DEBUG_INFO("word=%s\n",word);
  11688. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11689. {
  11690. profileQuantity += 1;
  11691. tmpProfileQuantity += 1;
  11692. }
  11693. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11694. }
  11695. fclose(fp);
  11696. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11697. }
  11698. }
  11699. //Check TxProfile_%d.json
  11700. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11701. {
  11702. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11703. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11704. if((access(fnametemp,F_OK))!=-1)
  11705. {
  11706. fp = fopen(fnametemp, "r");
  11707. //Check Charging Profile Count
  11708. tmpProfileQuantity = 0;
  11709. while(fscanf(fp, "%s", dataLine) != EOF)
  11710. {
  11711. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11712. {
  11713. profileQuantity += 1;
  11714. tmpProfileQuantity += 1;
  11715. }
  11716. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11717. }
  11718. fclose(fp);
  11719. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11720. }
  11721. }
  11722. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11723. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11724. {
  11725. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11726. goto end;
  11727. }
  11728. }
  11729. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11730. //**********************************Write to File********************************************************/
  11731. {
  11732. FILE *infile;
  11733. FILE *outfile;
  11734. char dataLine[4096]={0};
  11735. char filename[128]={0};
  11736. int chkChar=0;
  11737. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11738. {
  11739. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11740. {
  11741. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11742. }
  11743. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11744. {
  11745. if(SetProfileReq.ConnectorId==0)
  11746. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11747. else
  11748. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11749. }
  11750. else
  11751. {
  11752. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11753. }
  11754. infile = fopen (filename, "r");
  11755. outfile = fopen (tempfile, "w");
  11756. chkChar = fgetc(infile);
  11757. rewind(infile);
  11758. if(chkChar == EOF)
  11759. {
  11760. // Profile is empty
  11761. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11762. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11763. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11764. fclose(infile);
  11765. fclose(outfile);
  11766. sprintf(rmFileCmd,"rm -f %s",filename);
  11767. system(rmFileCmd);
  11768. rename(tempfile, filename);
  11769. }
  11770. else
  11771. {
  11772. // Profile is not empty
  11773. int ChargingProfileAdded = FALSE;
  11774. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11775. {
  11776. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11777. json_object *tmpChargingProfile;
  11778. tmpChargingProfile = json_tokener_parse(dataLine);
  11779. if(!is_error(SetChargingProfile))
  11780. {
  11781. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11782. {
  11783. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11784. {
  11785. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11786. }
  11787. }
  11788. }
  11789. json_object_put(tmpChargingProfile);
  11790. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11791. {
  11792. if(ChargingProfileAdded == FALSE)
  11793. {
  11794. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11795. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11796. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11797. ChargingProfileAdded = TRUE;
  11798. }
  11799. }
  11800. else
  11801. {
  11802. fprintf(outfile,"%s\n",dataLine);
  11803. if(ChargingProfileAdded == FALSE)
  11804. {
  11805. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11806. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11807. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11808. ChargingProfileAdded = TRUE;
  11809. }
  11810. }
  11811. } // end of while loop
  11812. fclose(infile);
  11813. fclose(outfile);
  11814. sprintf(rmFileCmd,"rm -f %s",filename);
  11815. system(rmFileCmd);
  11816. rename(tempfile, filename);
  11817. }
  11818. }
  11819. sleep(1);
  11820. result = TRUE;
  11821. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11822. }
  11823. end:
  11824. json_object_put(SetChargingProfile);
  11825. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11826. {
  11827. if(SetProfileReq.ConnectorId == 0)
  11828. {
  11829. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11830. {
  11831. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11832. }
  11833. }
  11834. else
  11835. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11836. }
  11837. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11838. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11839. return result;
  11840. }
  11841. int handleTriggerMessageRequest(char *uuid, char *payload)
  11842. {
  11843. mtrace();
  11844. int result = FAIL;
  11845. int connectorIdIsNULL = FALSE;
  11846. int connectorIdInt =0;
  11847. char sstr[40]={0},sstrtemp[100]={ 0 };
  11848. char requestedMessagestr[40]={0};
  11849. char comfirmstr[20]={0};
  11850. int c = 0;
  11851. char *loc;
  11852. DEBUG_INFO("handleTriggerMessageRequest\n");
  11853. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11854. strcpy(sstrtemp, stringtrimspace(payload));
  11855. c = 0;
  11856. loc = strstr(sstrtemp, "requestedMessage");
  11857. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11858. {
  11859. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11860. c++;
  11861. }
  11862. sstr[c] = '\0';
  11863. strcpy(requestedMessagestr, sstr);
  11864. c = 0;
  11865. loc = strstr(sstrtemp, "connectorId");
  11866. if(loc == NULL)
  11867. {
  11868. connectorIdIsNULL = TRUE;
  11869. }
  11870. else
  11871. {
  11872. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11873. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11874. {
  11875. sstr[c] = loc[strlen("connectorId")+2+c];
  11876. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11877. c++;
  11878. }
  11879. sstr[c] = '\0';
  11880. connectorIdInt = atoi(sstr);
  11881. }
  11882. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11883. {
  11884. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11885. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11886. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11887. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11888. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11889. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11890. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11891. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11892. {
  11893. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11894. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11895. return TRUE;
  11896. }
  11897. else
  11898. {
  11899. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11900. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11901. }
  11902. }
  11903. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11904. {
  11905. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11906. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11907. return TRUE;
  11908. }
  11909. //==========================
  11910. // Trigger message
  11911. //==========================
  11912. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11913. {
  11914. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11915. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11916. {
  11917. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11918. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11919. }
  11920. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11921. }
  11922. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11923. {
  11924. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11925. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11926. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11927. }
  11928. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11929. {
  11930. //sendBootNotificationRequest();
  11931. server_sign = FALSE;
  11932. }
  11933. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11934. {
  11935. refreshStartTimer(&clientTime.Heartbeat);
  11936. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  11937. }
  11938. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11939. {
  11940. if(connectorIdIsNULL == FALSE)
  11941. {
  11942. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11943. {
  11944. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11945. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11946. }
  11947. }
  11948. else
  11949. {
  11950. for(int idx=0;idx< gunTotalNumber;idx++)
  11951. {
  11952. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11953. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11954. }
  11955. }
  11956. }
  11957. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11958. {
  11959. if(connectorIdIsNULL == FALSE)
  11960. {
  11961. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11962. {
  11963. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11964. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11965. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11966. }
  11967. }
  11968. else
  11969. {
  11970. for(int idx=0;idx< gunTotalNumber;idx++)
  11971. {
  11972. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11973. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11974. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11975. }
  11976. }
  11977. }
  11978. return result;
  11979. }
  11980. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11981. {
  11982. mtrace();
  11983. int result = FAIL;
  11984. int connectorIdInt =0;
  11985. char comfirmstr[20]={0};
  11986. int tempIndex = 0;
  11987. json_object *UnlockConnector;
  11988. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11989. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11990. UnlockConnector = json_tokener_parse(payload);
  11991. if(!is_error(UnlockConnector))
  11992. {
  11993. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11994. {
  11995. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11996. }
  11997. }
  11998. json_object_put(UnlockConnector);
  11999. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12000. if(gunTotalNumber == 0)
  12001. {
  12002. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12003. goto end;
  12004. }
  12005. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12006. {
  12007. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12008. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12009. goto end;
  12010. }
  12011. else
  12012. {
  12013. //check Transaction active
  12014. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12015. {
  12016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12017. {
  12018. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12019. }
  12020. else
  12021. {
  12022. tempIndex = connectorIdInt -1;
  12023. }
  12024. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12025. {
  12026. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12027. {
  12028. //stop Transaction
  12029. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12030. }
  12031. }
  12032. }
  12033. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12034. {
  12035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12036. {
  12037. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12038. }
  12039. else
  12040. {
  12041. tempIndex = connectorIdInt -1;
  12042. }
  12043. for (int index = 0; index < CCS_QUANTITY; index++)
  12044. {
  12045. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12046. {
  12047. //stop Transaction
  12048. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12049. }
  12050. }
  12051. }
  12052. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12053. {
  12054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12055. {
  12056. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12057. }
  12058. else
  12059. {
  12060. tempIndex = connectorIdInt -1;
  12061. }
  12062. for (int index = 0; index < GB_QUANTITY; index++)
  12063. {
  12064. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12065. {
  12066. //stop Transaction
  12067. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12068. }
  12069. }
  12070. }
  12071. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12072. {
  12073. tempIndex = connectorIdInt -1;
  12074. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12075. {
  12076. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12077. {
  12078. //stop Transaction
  12079. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12080. }
  12081. }
  12082. }
  12083. else
  12084. {
  12085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12086. {
  12087. tempIndex = 2;
  12088. }
  12089. else
  12090. {
  12091. tempIndex = connectorIdInt-1;
  12092. }
  12093. for (int index = 0; index < AC_QUANTITY; index++)
  12094. {
  12095. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12096. {
  12097. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12098. }
  12099. }
  12100. }
  12101. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12102. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12103. result = TRUE;
  12104. return result;
  12105. }
  12106. end:
  12107. //json_object_put(obj); --- remove temporally
  12108. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12109. return result;
  12110. }
  12111. static char UpdateFirmwarepayloadData[300]={0};
  12112. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12113. {
  12114. mtrace();
  12115. int result = FAIL;
  12116. pthread_t t;
  12117. sendUpdateFirmwareConfirmation(uuid);
  12118. memset(UpdateFirmwarepayloadData, 0, 300);
  12119. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12120. if(!interLock.isUpdateFirmwareGoing)
  12121. {
  12122. interLock.isUpdateFirmwareGoing = 1;
  12123. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12124. sleep(1);
  12125. }
  12126. else
  12127. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12128. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12129. return result;
  12130. }
  12131. void *UpdateFirmwareProcess(void *data)
  12132. {
  12133. pthread_detach(pthread_self());
  12134. mtrace();
  12135. int retriesInt =0, retryIntervalInt=0;
  12136. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12137. int port=0;
  12138. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12139. int isSuccess = 0;
  12140. char ftpbuf[512];
  12141. char temp[100];
  12142. char * pch;
  12143. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12144. json_object *UpdateFirmware;
  12145. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12146. if(!is_error(UpdateFirmware))
  12147. {
  12148. // Required data
  12149. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12150. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12151. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12152. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12153. // Optional data
  12154. if(json_object_object_get(UpdateFirmware, "retries"))
  12155. {
  12156. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12157. }
  12158. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12159. {
  12160. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12161. }
  12162. }
  12163. json_object_put(UpdateFirmware);
  12164. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12165. memset(path, 0, ARRAY_SIZE(path));
  12166. // Wait retrieveData
  12167. if(strlen(retrieveDatestr) > 10)
  12168. {
  12169. do
  12170. {
  12171. sleep(1);
  12172. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12173. }
  12174. // Ready to download
  12175. system("rm -f /mnt/*");
  12176. if(strncmp(locationstr,"http", 4) == 0)
  12177. {
  12178. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12179. sprintf(ftppath,"/%s", path);
  12180. DEBUG_INFO("locationstr: %s\n", locationstr);
  12181. DEBUG_INFO("protocol: %s\n",protocol);
  12182. DEBUG_INFO("host: %s\n",host);
  12183. DEBUG_INFO("path: %s\n",path);
  12184. DEBUG_INFO("ftppath: %s\n",ftppath);
  12185. int ftppathlen=strlen(ftppath);
  12186. int i=1;
  12187. char filenametemp[50];
  12188. while(i < ftppathlen)
  12189. {
  12190. int len=ftppathlen-i;
  12191. if(ftppath[len]== 47) // '/' ascll code: 47
  12192. {
  12193. DEBUG_INFO("compare '/' all right\n");
  12194. break;
  12195. }
  12196. i=i+1;
  12197. }
  12198. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12199. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12200. filenametemp[i+1] = 0;
  12201. do
  12202. {
  12203. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12204. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12205. sleep(1);
  12206. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12207. if(!isSuccess)
  12208. {
  12209. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12210. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12211. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12212. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12213. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12214. }
  12215. else
  12216. {
  12217. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12218. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12219. }
  12220. retriesInt--;
  12221. }while((isSuccess == 0)&&(retriesInt >= 0));
  12222. }
  12223. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12224. {
  12225. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12226. memset(temp, 0, ARRAY_SIZE(temp));
  12227. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12228. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12229. int ftppathlen=strlen(ftpbuf);
  12230. int i=1;
  12231. char filenametemp[50];
  12232. while(i < ftppathlen)
  12233. {
  12234. int len=ftppathlen-i;
  12235. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12236. {
  12237. DEBUG_INFO(" compare '/' all right\n");
  12238. break;
  12239. }
  12240. i=i+1;
  12241. }
  12242. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12243. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12244. filenametemp[i+1] = 0;
  12245. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12246. pch=strchr(temp,'@');
  12247. if(pch==NULL)
  12248. {
  12249. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12250. protocol, host, &port, path);
  12251. strcpy(user,"anonymous");
  12252. strcpy(password,"");
  12253. }
  12254. else
  12255. {
  12256. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12257. protocol, user, password, host, &port, path);
  12258. }
  12259. sscanf(host,"%[^/]%s",host1, path1);
  12260. sprintf(ftppath,"%s", path1);
  12261. //DEBUG_INFO("protocol =%s\n",protocol);
  12262. //DEBUG_INFO("user =%s\n",user);
  12263. //DEBUG_INFO("password =%s\n",password);
  12264. //DEBUG_INFO("host1 =%s\n",host1);
  12265. //DEBUG_INFO("port =%d\n",port);
  12266. //DEBUG_INFO("path1 =%s\n",path1);
  12267. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12268. //ftpFile(host, user, password, port, ftppath, fname);
  12269. //download firmware pthred
  12270. if(port == 0)
  12271. {
  12272. port = 21;
  12273. }
  12274. do
  12275. {
  12276. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12277. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12278. sleep(1);
  12279. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12280. if(!isSuccess)
  12281. {
  12282. //BulldogUtil.sleepMs(interval*1000);
  12283. DEBUG_INFO("Update firmware request and download file fail.\n");
  12284. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12285. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12286. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12287. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12288. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12289. }
  12290. else
  12291. {
  12292. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12293. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12294. }
  12295. retriesInt--;
  12296. }while((!isSuccess)&&(retriesInt >= 0));
  12297. }
  12298. else
  12299. {
  12300. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12301. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12302. sleep(1);
  12303. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12304. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12305. }
  12306. // OCPPPH only, must announce CSU upgrade firmware
  12307. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12308. interLock.isUpdateFirmwareGoing = 0;
  12309. pthread_exit(NULL);
  12310. }
  12311. int handleCertificateSignedRequest(char *uuid, char *payload)
  12312. {
  12313. mtrace();
  12314. int result = PASS;
  12315. json_object *CertificateSigned;
  12316. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12317. CertificateSigned = json_tokener_parse(payload);
  12318. if(!is_error(CertificateSigned))
  12319. {
  12320. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12321. }
  12322. json_object_put(CertificateSigned);
  12323. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12324. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12325. fclose(fp);
  12326. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12327. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12328. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12329. sendCertificateSignedConfirmation(uuid);
  12330. return result;
  12331. }
  12332. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12333. {
  12334. mtrace();
  12335. int result = PASS;
  12336. json_object *DeleteCertificate;
  12337. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12338. DeleteCertificate = json_tokener_parse(payload);
  12339. if(!is_error(DeleteCertificate))
  12340. {
  12341. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12342. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12343. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12344. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12345. }
  12346. json_object_put(DeleteCertificate);
  12347. /*
  12348. * TODO: Delete certificateSigned process
  12349. */
  12350. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12351. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12352. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12353. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12354. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12355. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12356. sendDeleteCertificateConfirmation(uuid);
  12357. return result;
  12358. }
  12359. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12360. {
  12361. mtrace();
  12362. int result = PASS;
  12363. json_object *ExtendedTriggerMessage;
  12364. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12365. ExtendedTriggerMessage = json_tokener_parse(payload);
  12366. if(!is_error(ExtendedTriggerMessage))
  12367. {
  12368. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12369. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12370. {
  12371. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12372. }
  12373. else
  12374. {
  12375. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12376. }
  12377. }
  12378. json_object_put(ExtendedTriggerMessage);
  12379. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12380. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12381. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12382. {
  12383. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12384. }
  12385. else
  12386. {
  12387. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12388. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12389. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12390. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12391. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12392. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12393. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12394. {
  12395. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12396. }
  12397. else
  12398. {
  12399. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12400. }
  12401. }
  12402. sendExtendedTriggerMessageConfirmation(uuid);
  12403. //==========================
  12404. // Trigger message
  12405. //==========================
  12406. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12407. {
  12408. //sendBootNotificationRequest();
  12409. server_sign = FALSE;
  12410. }
  12411. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12412. {
  12413. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12414. }
  12415. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12416. {
  12417. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12418. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12419. {
  12420. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12421. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12422. }
  12423. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12424. }
  12425. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12426. {
  12427. refreshStartTimer(&clientTime.Heartbeat);
  12428. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12429. }
  12430. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12431. {
  12432. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12433. {
  12434. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12435. }
  12436. else
  12437. {
  12438. for(int idx=0;idx< gunTotalNumber;idx++)
  12439. {
  12440. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12441. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12442. }
  12443. }
  12444. }
  12445. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12446. {
  12447. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12448. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12449. {
  12450. 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\" &");
  12451. }
  12452. }
  12453. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12454. {
  12455. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12456. {
  12457. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12458. }
  12459. else
  12460. {
  12461. for(int idx=0;idx< gunTotalNumber;idx++)
  12462. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12463. }
  12464. }
  12465. return result;
  12466. }
  12467. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12468. {
  12469. mtrace();
  12470. int result = PASS;
  12471. json_object *GetInstalledCertificateIds;
  12472. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12473. GetInstalledCertificateIds = json_tokener_parse(payload);
  12474. if(!is_error(GetInstalledCertificateIds))
  12475. {
  12476. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12477. }
  12478. json_object_put(GetInstalledCertificateIds);
  12479. /*
  12480. * TODO: Return installed certificate process
  12481. */
  12482. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12483. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12484. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12485. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12486. sendGetInstalledCertificateIdsConfirmation(uuid);
  12487. return result;
  12488. }
  12489. int handleGetLogRequest(char *uuid, char *payload)
  12490. {
  12491. mtrace();
  12492. int result = PASS;
  12493. json_object *GetLog;
  12494. DEBUG_INFO("handleGetLogRequest...\n");
  12495. GetLog = json_tokener_parse(payload);
  12496. if(!is_error(GetLog))
  12497. {
  12498. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12499. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12500. if(json_object_object_get(GetLog, "retries") != NULL)
  12501. {
  12502. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12503. }
  12504. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12505. {
  12506. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12507. }
  12508. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12509. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12510. {
  12511. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12512. }
  12513. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12514. {
  12515. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12516. }
  12517. }
  12518. json_object_put(GetLog);
  12519. /*
  12520. * TODO: Upload log process
  12521. */
  12522. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12523. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12524. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12525. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12526. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12527. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12528. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12529. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12530. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12531. sendGetLogConfirmation(uuid);
  12532. return result;
  12533. }
  12534. int handleInstallCertificateRequest(char *uuid, char *payload)
  12535. {
  12536. mtrace();
  12537. int result = PASS;
  12538. json_object *InstallCertificate;
  12539. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12540. InstallCertificate = json_tokener_parse(payload);
  12541. if(!is_error(InstallCertificate))
  12542. {
  12543. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12544. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12545. /*
  12546. * TODO: Install certificate process
  12547. */
  12548. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12549. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12550. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12551. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12552. sendInstallCertificateConfirmation(uuid);
  12553. }
  12554. json_object_put(InstallCertificate);
  12555. return result;
  12556. }
  12557. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12558. {
  12559. mtrace();
  12560. int result = PASS;
  12561. json_object *SignedUpdateFirmware;
  12562. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12563. SignedUpdateFirmware = json_tokener_parse(payload);
  12564. if(!is_error(SignedUpdateFirmware))
  12565. {
  12566. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12567. {
  12568. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12569. }
  12570. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12571. {
  12572. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12573. }
  12574. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12575. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12576. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12577. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12578. {
  12579. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12580. }
  12581. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12582. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12583. }
  12584. json_object_put(SignedUpdateFirmware);
  12585. /*
  12586. * TODO: Upgrade firmware process
  12587. */
  12588. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12589. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12590. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12591. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12592. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12593. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12594. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12595. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12596. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12597. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12598. sendInstallCertificateConfirmation(uuid);
  12599. return result;
  12600. }
  12601. int handleUnknownRequest(char *uuid, char *payload)
  12602. {
  12603. mtrace();
  12604. int result = PASS;
  12605. DEBUG_INFO("handleUnknownRequest...\n");
  12606. sendUnknownConfirmation(uuid);
  12607. result = PASS;
  12608. return result;
  12609. }
  12610. //==========================================
  12611. // Handle server response routine
  12612. //==========================================
  12613. void handleAuthorizeResponse(char *payload, int gun_index)
  12614. {
  12615. mtrace();
  12616. char expiryDatestr[30]={0};
  12617. char parentIdTagstr[20]={0};
  12618. char statusstr[20]={0};
  12619. int expiryDateISNULL=FALSE;
  12620. int parentIdTagISNULL=FALSE;
  12621. DEBUG_INFO("handleAuthorizeResponse...\n");
  12622. json_object *Authorize;
  12623. Authorize = json_tokener_parse(payload);
  12624. if(!is_error(Authorize))
  12625. {
  12626. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12627. {
  12628. // Required data
  12629. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12630. // Optional data
  12631. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12632. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12633. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12634. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12635. }
  12636. }
  12637. json_object_put(Authorize);
  12638. if(expiryDateISNULL == FALSE)
  12639. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12640. if(parentIdTagISNULL == FALSE)
  12641. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12642. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12643. //Update idTag information to authorization cache if supproted
  12644. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12645. {
  12646. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12647. }
  12648. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12649. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12650. authorizeRetryTimes = 0;
  12651. }
  12652. void handleBootNotificationResponse(char *payload, int gun_index)
  12653. {
  12654. mtrace();
  12655. char statusStr[12]={0};
  12656. char currentTimeStr[30]={0};
  12657. int intervalInt = 0;
  12658. DEBUG_INFO("handleBootNotificationResponse...\n");
  12659. json_object *BootNotification;
  12660. BootNotification = json_tokener_parse(payload);
  12661. if(!is_error(BootNotification))
  12662. {
  12663. // Required data
  12664. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12665. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12666. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12667. }
  12668. json_object_put(BootNotification);
  12669. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12670. BootNotificationInterval = intervalInt;
  12671. HeartBeatWaitTime = intervalInt;
  12672. //write back to ShmOCPP16DataPH->BootNotification
  12673. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12674. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12675. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12676. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12677. {
  12678. if((intervalInt == 0) || (intervalInt >= 10))
  12679. {
  12680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12681. HeartBeatWaitTime = intervalInt;
  12682. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12683. }
  12684. server_sign = TRUE;
  12685. server_pending =FALSE;
  12686. }
  12687. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12688. {
  12689. server_pending = TRUE;
  12690. }
  12691. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12692. srand(time(NULL));
  12693. refreshStartTimer(&clientTime.Heartbeat);
  12694. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12695. SetOcppConnStatus(TRUE);
  12696. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12697. }
  12698. void handleDataTransferResponse(char *payload, int gun_index)
  12699. {
  12700. char sstr[160]={0};//sstr[200]={ 0 };
  12701. int c = 0;
  12702. char *loc;
  12703. DEBUG_INFO("handleDataTransferResponse ...\n");
  12704. loc = strstr(payload, "status");
  12705. c = 0;
  12706. while (loc[3+strlen("status")+c] != '\"')
  12707. {
  12708. sstr[c] = loc[3+strlen("status")+c];
  12709. c++;
  12710. }
  12711. sstr[c] = '\0';
  12712. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12713. }
  12714. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12715. {
  12716. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12717. //struct json_object *obj;
  12718. // obj = json_tokener_parse(payload);
  12719. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12720. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12721. //No fields are defined.
  12722. }
  12723. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12724. {
  12725. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12726. //struct json_object *obj;
  12727. // obj = json_tokener_parse(payload);
  12728. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12729. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12730. //No fields are defined.
  12731. }
  12732. void handleHeartbeatResponse(char *payload, int gun_index)
  12733. {
  12734. mtrace();
  12735. DEBUG_INFO("handleHeartbeatResponse...\n");
  12736. json_object *Heartbeat;
  12737. Heartbeat = json_tokener_parse(payload);
  12738. if(!is_error(Heartbeat))
  12739. {
  12740. // Required data
  12741. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12742. }
  12743. json_object_put(Heartbeat);
  12744. if(FirstHeartBeat == 0)
  12745. {
  12746. FirstHeartBeat = 1;
  12747. DEBUG_INFO("FirstHeartBeat \n");
  12748. }
  12749. HeartBeatWithNOResponse = 0;
  12750. refreshStartTimer(&clientTime.Heartbeat);
  12751. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12752. }
  12753. void handleMeterValuesResponse(char *payload, int gun_index)
  12754. {
  12755. mtrace();
  12756. DEBUG_INFO("handleMeterValuesResponse...\n");
  12757. isQueueSendable = 1;
  12758. }
  12759. void handleStartTransactionResponse(char *payload, int gun_index)
  12760. {
  12761. mtrace();
  12762. //int transactionIdInt = 0;
  12763. FILE *outfile;
  12764. char data[100]={0};
  12765. DEBUG_INFO("handleStartTransactionResponse...\n");
  12766. json_object *StartTransaction;
  12767. StartTransaction = json_tokener_parse(payload);
  12768. if(!is_error(StartTransaction))
  12769. {
  12770. // Required data
  12771. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12772. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12773. // Optional data
  12774. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12775. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12776. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12777. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12778. }
  12779. json_object_put(StartTransaction);
  12780. isQueueSendable = 1;
  12781. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12782. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12783. //-----------Start : write to the Queue TransactionId file -----------------//
  12784. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12785. {}
  12786. else
  12787. {
  12788. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12789. if(log == NULL)
  12790. {
  12791. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12792. return ;
  12793. }
  12794. else
  12795. {
  12796. fclose(log);
  12797. }
  12798. }
  12799. // open file for writing
  12800. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12801. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12802. {
  12803. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12804. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12805. fputs(data, outfile);
  12806. fclose (outfile);
  12807. }
  12808. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12809. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12810. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12811. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12812. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12813. }
  12814. void handleStatusNotificationResponse(char *payload, int gun_index)
  12815. {
  12816. mtrace();
  12817. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12818. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12819. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12820. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12821. }
  12822. void handleStopTransactionnResponse(char *payload, int gun_index)
  12823. {
  12824. mtrace();
  12825. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12826. json_object *StopTransaction;
  12827. StopTransaction = json_tokener_parse(payload);
  12828. if(!is_error(StopTransaction))
  12829. {
  12830. // Optional data
  12831. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12832. {
  12833. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12834. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12835. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12836. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12837. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12838. }
  12839. }
  12840. json_object_put(StopTransaction);
  12841. isQueueSendable = 1;
  12842. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12843. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12844. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12845. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12846. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12847. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  12848. }
  12849. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12850. {
  12851. mtrace();
  12852. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12853. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12854. }
  12855. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12856. {
  12857. mtrace();
  12858. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12859. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12860. }
  12861. void handleSignCertificateResponse(char *payload, int gun_index)
  12862. {
  12863. mtrace();
  12864. DEBUG_INFO("handleSignCertificateResponse...\n");
  12865. json_object *SignCertificate;
  12866. SignCertificate = json_tokener_parse(payload);
  12867. if(!is_error(SignCertificate))
  12868. {
  12869. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12870. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12871. }
  12872. json_object_put(SignCertificate);
  12873. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12874. }
  12875. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12876. {
  12877. mtrace();
  12878. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12879. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12880. }
  12881. //==========================================
  12882. // Handle Error routine
  12883. //==========================================
  12884. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12885. {
  12886. mtrace();
  12887. #ifdef SystemLogMessage
  12888. DEBUG_INFO("errorCode: %s\n", errorCode);
  12889. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12890. DEBUG_INFO("errorDetails: %s\n", payload);
  12891. #endif
  12892. }
  12893. //===============================================
  12894. // Common routine
  12895. //===============================================
  12896. int initialConfigurationTable(void)
  12897. {
  12898. //clock_t start_t, end_t, total_t;
  12899. FILE *fp;
  12900. FILE *outfile;
  12901. char str[512]={0};
  12902. char sstr[256]={0};
  12903. int c = 0;
  12904. char *loc;
  12905. int confVersion = 11;
  12906. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12907. //start_t = clock();
  12908. //printf("Starting of the program, start_t = %ld\n", start_t);
  12909. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12910. // Check configuration file size is correct
  12911. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12912. {
  12913. struct stat st;
  12914. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12915. if(st.st_size < 3100)
  12916. {
  12917. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12918. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12919. }
  12920. }
  12921. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12922. {
  12923. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12924. if(outfile == NULL)
  12925. {
  12926. DEBUG_INFO("Error opening file\n");
  12927. return FALSE;
  12928. }
  12929. /*Core Profile*/
  12930. //AllowOfflineTxForUnknownId
  12931. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12935. //AuthorizationCacheEnabled
  12936. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12940. //AuthorizeRemoteTxRequests
  12941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12945. //BlinkRepeat
  12946. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12948. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12950. //ClockAlignedDataInterval
  12951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12955. //ConnectionTimeOut
  12956. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12960. //GetConfigurationMaxKeys
  12961. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12963. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12965. // HeartbeatInterval
  12966. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12970. // LightIntensity
  12971. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12975. // LocalAuthorizeOffline
  12976. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12980. // LocalPreAuthorize
  12981. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12985. // MaxEnergyOnInvalidId
  12986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12990. // MeterValuesAlignedData
  12991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12994. 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" );
  12995. else
  12996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12998. // MeterValuesAlignedDataMaxLength
  12999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13003. else
  13004. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13006. // MeterValuesSampledData
  13007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13010. 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" );
  13011. else
  13012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13014. // MeterValuesSampledDataMaxLength
  13015. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13018. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13019. else
  13020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13022. // MeterValueSampleInterval
  13023. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13027. // MinimumStatusDuration
  13028. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13031. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13033. // NumberOfConnectors
  13034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13037. {
  13038. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13039. }
  13040. else
  13041. {
  13042. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13043. }
  13044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13045. // ResetRetries
  13046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13050. // ConnectorPhaseRotation
  13051. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13055. // ConnectorPhaseRotationMaxLength
  13056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13060. // StopTransactionOnEVSideDisconnect
  13061. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13065. // StopTransactionOnInvalidId
  13066. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13070. // StopTxnAlignedData
  13071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13075. // StopTxnAlignedDataMaxLength
  13076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13080. // StopTxnSampledData
  13081. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13085. else
  13086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13088. // StopTxnSampledDataMaxLength
  13089. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13091. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13092. {
  13093. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13094. }
  13095. else
  13096. {
  13097. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13098. }
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13100. // SupportedFeatureProfiles
  13101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13105. // SupportedFeatureProfilesMaxLength
  13106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13110. // TransactionMessageAttempts
  13111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13114. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13116. // TransactionMessageRetryInterval
  13117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13120. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13122. // UnlockConnectorOnEVSideDisconnect
  13123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13127. // WebSocketPingInterval
  13128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13132. // QueueOffLineMeterValues
  13133. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13137. // AuthorizationKey
  13138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13142. // SecurityProfile
  13143. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13145. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13147. // DefaultPrice
  13148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13152. // CustomDisplayCostAndPrice
  13153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13157. // CustomIdleFeeAfterStop
  13158. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13162. // SystemUptimeSec
  13163. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13167. // FreeVend
  13168. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13172. // OcppServer
  13173. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13175. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13177. // MaintainServer
  13178. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13180. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13182. // Configuration Version
  13183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13185. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13187. //* Local Auth List Management Profile*/
  13188. #if 0
  13189. //For OCTT Test Case
  13190. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13193. #endif
  13194. #if 1
  13195. //LocalAuthListEnabled
  13196. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13200. #endif
  13201. //LocalAuthListMaxLength
  13202. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13206. //SendLocalListMaxLength
  13207. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13211. //ReserveConnectorZeroSupported
  13212. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13216. //* Smart Charging Profile */
  13217. //ChargeProfileMaxStackLevel
  13218. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13222. // ChargingScheduleAllowedChargingRateUnit
  13223. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13227. // ChargingScheduleMaxPeriods
  13228. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13229. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13232. // ConnectorSwitch3to1PhaseSupported
  13233. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13237. // MaxChargingProfilesInstalled
  13238. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13242. fclose(outfile);
  13243. }
  13244. else
  13245. {
  13246. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13247. char keystr[60]={0};
  13248. char readonlystr[10]={0};
  13249. char valuestr[256]={0};
  13250. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13251. if(fp == NULL) {
  13252. DEBUG_INFO("Error opening file");
  13253. return FALSE;
  13254. }
  13255. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13256. {
  13257. //DEBUG_INFO("Get Configuration \n");
  13258. if(strlen(str) > 0)
  13259. {
  13260. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13261. //*************************key*********************************/
  13262. if(strstr(str, "key") != NULL)
  13263. {
  13264. loc = strstr(str, "key");
  13265. c = 0;
  13266. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13267. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13268. {
  13269. sstr[c] = loc[strlen("key")+3+c];
  13270. c++;
  13271. }
  13272. sstr[c] = '\0';
  13273. strcpy(keystr,sstr);
  13274. }
  13275. //*************************readonly*********************************/
  13276. if(strstr(str, "readonly") != NULL)
  13277. {
  13278. loc = strstr(str, "readonly");
  13279. c = 0;
  13280. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13281. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13282. {
  13283. sstr[c] = loc[strlen("readonly")+2+c];
  13284. c++;
  13285. }
  13286. sstr[c] = '\0';
  13287. strcpy(readonlystr,sstr);
  13288. }
  13289. //*************************value*********************************/
  13290. if(strstr(str, "value") != NULL)
  13291. {
  13292. loc = strstr(str, "value");
  13293. c = 0;
  13294. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13295. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13296. {
  13297. sstr[c] = loc[strlen("value")+3+c];
  13298. c++;
  13299. }
  13300. sstr[c] = '\0';
  13301. strcpy(valuestr,sstr);
  13302. }
  13303. // DEBUG_INFO("keystr=%s\n",keystr);
  13304. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13305. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13306. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13307. {
  13308. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13310. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13311. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13312. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13313. }
  13314. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13315. {
  13316. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13319. }
  13320. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13321. {
  13322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13324. }
  13325. if(strcmp(keystr, "BlinkRepeat") == 0)
  13326. {
  13327. //Charger.BlinkRepeat = Integer.parseInt(value);
  13328. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13330. }
  13331. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13332. {
  13333. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13334. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13335. }
  13336. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13337. {
  13338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13340. }
  13341. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13342. {
  13343. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13345. }
  13346. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13347. {
  13348. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13350. HeartBeatWaitTime = atoi(valuestr);
  13351. }
  13352. if(strcmp(keystr, "LightIntensity") == 0)
  13353. {
  13354. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13355. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13356. }
  13357. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13358. {
  13359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13360. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13361. }
  13362. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13363. {
  13364. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13365. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13366. }
  13367. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13368. {
  13369. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13370. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13371. }
  13372. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13373. {
  13374. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13375. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13376. }
  13377. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13378. {
  13379. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13380. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13381. }
  13382. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13383. {
  13384. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13385. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13386. }
  13387. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13388. {
  13389. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13391. }
  13392. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13393. {
  13394. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13396. }
  13397. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13398. {
  13399. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13401. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13402. }
  13403. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13404. {
  13405. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13407. }
  13408. if(strcmp(keystr, "ResetRetries") == 0)
  13409. {
  13410. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13412. }
  13413. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13414. {
  13415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13416. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13417. }
  13418. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13419. {
  13420. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13421. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13422. }
  13423. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13424. {
  13425. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13426. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13427. }
  13428. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13429. {
  13430. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13431. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13432. }
  13433. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13434. {
  13435. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13436. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13437. }
  13438. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13439. {
  13440. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13441. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13442. }
  13443. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13444. {
  13445. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13446. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13447. }
  13448. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13449. {
  13450. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13451. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13452. }
  13453. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13454. {
  13455. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13456. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13457. }
  13458. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13459. {
  13460. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13462. }
  13463. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13464. {
  13465. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13466. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13467. TransactionMessageAttemptsValue = atoi(valuestr);
  13468. }
  13469. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13470. {
  13471. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13472. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13473. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13474. }
  13475. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13476. {
  13477. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13479. }
  13480. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13481. {
  13482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13484. }
  13485. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13486. {
  13487. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13488. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13489. }
  13490. if(strcmp(keystr, "AuthorizationKey") == 0)
  13491. {
  13492. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13493. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13495. }
  13496. if(strcmp(keystr, "SecurityProfile") == 0)
  13497. {
  13498. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13499. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13501. }
  13502. if(strcmp(keystr, "DefaultPrice") == 0)
  13503. {
  13504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13505. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13506. }
  13507. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13508. {
  13509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13511. }
  13512. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13513. {
  13514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13516. }
  13517. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13518. {
  13519. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13521. }
  13522. if(strcmp(keystr, "FreeVend") == 0)
  13523. {
  13524. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13525. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13526. }
  13527. if(strcmp(keystr, "OcppServer") == 0)
  13528. {
  13529. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13530. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13531. }
  13532. if(strcmp(keystr, "MaintainServer") == 0)
  13533. {
  13534. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13535. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13536. }
  13537. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13538. {
  13539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13541. }
  13542. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13543. {
  13544. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13546. }
  13547. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13548. {
  13549. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13550. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13551. }
  13552. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13553. {
  13554. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13555. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13556. }
  13557. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13558. {
  13559. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13560. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13561. }
  13562. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13563. {
  13564. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13565. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13566. }
  13567. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13568. {
  13569. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13570. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13571. }
  13572. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13573. {
  13574. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13576. }
  13577. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13578. {
  13579. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13580. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13581. }
  13582. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13583. {
  13584. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13585. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13586. }
  13587. }
  13588. }
  13589. fclose(fp);
  13590. }
  13591. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13592. {
  13593. return PASS;
  13594. }
  13595. else
  13596. {
  13597. return FAIL;
  13598. }
  13599. }
  13600. void StoreConfigurationTable(void)
  13601. {
  13602. FILE *outfile;
  13603. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13604. if(outfile == NULL)
  13605. {
  13606. DEBUG_INFO("Error opening file");
  13607. return ;
  13608. }
  13609. /*Core Profile*/
  13610. //AllowOfflineTxForUnknownId
  13611. /*
  13612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13613. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13616. */
  13617. //DEBUG_INFO("data=%s\n",data);
  13618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13619. //AuthorizationCacheEnabled
  13620. /*
  13621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13624. */
  13625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13626. //AuthorizeRemoteTxRequests
  13627. /*
  13628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13631. */
  13632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13633. //BlinkRepeat
  13634. /*
  13635. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13638. */
  13639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13640. //ClockAlignedDataInterval
  13641. /*
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13645. */
  13646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13647. //ConnectionTimeOut
  13648. /*
  13649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13652. */
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13654. //GetConfigurationMaxKeys
  13655. /*
  13656. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13659. */
  13660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13661. // HeartbeatInterval
  13662. /*
  13663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13666. */
  13667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13668. // LightIntensity
  13669. /*
  13670. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13671. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13673. */
  13674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13675. // LocalAuthorizeOffline
  13676. /*
  13677. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13678. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13680. */
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13682. // LocalPreAuthorize
  13683. /*
  13684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13687. */
  13688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13689. // MaxEnergyOnInvalidId
  13690. /*
  13691. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13692. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13694. */
  13695. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13697. // MeterValuesAlignedData
  13698. /*
  13699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13701. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13702. */
  13703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13704. // MeterValuesAlignedDataMaxLength
  13705. /*
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13707. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13709. */
  13710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13711. // MeterValuesSampledData
  13712. /*
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13716. */
  13717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13718. // MeterValuesSampledDataMaxLength
  13719. /*
  13720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13723. */
  13724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13725. // MeterValueSampleInterval
  13726. /*
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13730. */
  13731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13732. // MinimumStatusDuration
  13733. /*
  13734. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13736. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13737. */
  13738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13739. // NumberOfConnectors
  13740. /*
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13743. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13744. {
  13745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13746. }
  13747. else
  13748. {
  13749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13750. }
  13751. */
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13753. // ResetRetries
  13754. /*
  13755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13756. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13758. */
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13760. // ConnectorPhaseRotation
  13761. /*
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13765. */
  13766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13767. // ConnectorPhaseRotationMaxLength
  13768. /*
  13769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13772. */
  13773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13774. // StopTransactionOnEVSideDisconnect
  13775. /*
  13776. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13779. */
  13780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13781. // StopTransactionOnInvalidId
  13782. /*
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13786. */
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13788. // StopTxnAlignedData
  13789. /*
  13790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13793. */
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13795. // StopTxnAlignedDataMaxLength
  13796. /*
  13797. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13800. */
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13802. // StopTxnSampledData
  13803. /*
  13804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13807. */
  13808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13809. // StopTxnSampledDataMaxLength
  13810. /*
  13811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13814. */
  13815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13816. // SupportedFeatureProfiles
  13817. /*
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13821. */
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13823. // SupportedFeatureProfilesMaxLength
  13824. /*
  13825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13828. */
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13830. // TransactionMessageAttempts
  13831. /*
  13832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13835. */
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13837. // TransactionMessageRetryInterval
  13838. /*
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13842. */
  13843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13844. // UnlockConnectorOnEVSideDisconnect
  13845. /*
  13846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13849. */
  13850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13851. // WebSocketPingInterval
  13852. /*
  13853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13856. */
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13858. // QueueOffLineMeterValues
  13859. /*
  13860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13863. */
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13865. // AuthorizationKey
  13866. /*
  13867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13870. */
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13872. // SecurityProfile
  13873. /*
  13874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13877. */
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13879. // DefaultPrice
  13880. /*
  13881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13884. */
  13885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13886. // CustomDisplayCostAndPrice
  13887. /*
  13888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13891. */
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13893. // CustomIdleFeeAfterStop
  13894. /*
  13895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13898. */
  13899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13900. // SystemUptimeSec
  13901. /*
  13902. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13905. */
  13906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13907. // FreeVend
  13908. /*
  13909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13912. */
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13914. // OcppServer
  13915. /*
  13916. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  13919. */
  13920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13921. // MaintainServer
  13922. /*
  13923. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  13926. */
  13927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13928. // ConfigurationVersion
  13929. /*
  13930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13933. */
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13935. //* Local Auth List Management Profile*/
  13936. //LocalAuthListEnabled
  13937. /*
  13938. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13941. */
  13942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13943. //LocalAuthListMaxLength
  13944. /*
  13945. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13948. */
  13949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13950. //SendLocalListMaxLength
  13951. /*
  13952. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13955. */
  13956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13957. //ReserveConnectorZeroSupported
  13958. /*
  13959. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13962. */
  13963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13964. //* Smart Charging Profile */
  13965. //ChargeProfileMaxStackLevel
  13966. /*
  13967. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13970. */
  13971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13972. // ChargingScheduleAllowedChargingRateUnit
  13973. /*
  13974. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13977. */
  13978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13979. // ChargingScheduleMaxPeriods
  13980. /*
  13981. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13984. */
  13985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13986. // ConnectorSwitch3to1PhaseSupported
  13987. /*
  13988. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13991. */
  13992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13993. // MaxChargingProfilesInstalled
  13994. /*
  13995. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13998. */
  13999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14000. fclose(outfile);
  14001. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14002. }
  14003. void getKeyValue(char *keyReq)
  14004. {
  14005. int isEmpty = FALSE;
  14006. int isKnowKey = FALSE;
  14007. DEBUG_INFO("keyReq = %s\n", keyReq);
  14008. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14009. isEmpty = TRUE;
  14010. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14011. {
  14012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14014. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14015. {
  14016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14017. }
  14018. else
  14019. {
  14020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14021. }
  14022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14023. isKnowKey = TRUE;
  14024. }
  14025. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14026. {
  14027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14029. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14030. {
  14031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14032. }
  14033. else
  14034. {
  14035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14036. }
  14037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14038. isKnowKey = TRUE;
  14039. }
  14040. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14041. {
  14042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14044. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14045. {
  14046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14047. }
  14048. else
  14049. {
  14050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14051. }
  14052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14053. isKnowKey = TRUE;
  14054. }
  14055. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14056. {
  14057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14059. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14060. {
  14061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14062. }
  14063. else
  14064. {
  14065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14066. }
  14067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14068. isKnowKey = TRUE;
  14069. }
  14070. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14071. {
  14072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14074. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14075. {
  14076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14077. }
  14078. else
  14079. {
  14080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14081. }
  14082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14083. isKnowKey = TRUE;
  14084. }
  14085. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14086. {
  14087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14089. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14090. {
  14091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14092. }
  14093. else
  14094. {
  14095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14096. }
  14097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14098. isKnowKey = TRUE;
  14099. }
  14100. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14101. {
  14102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14104. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14105. {
  14106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14107. }
  14108. else
  14109. {
  14110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14111. }
  14112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14113. isKnowKey = TRUE;
  14114. }
  14115. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14116. {
  14117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14119. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14120. {
  14121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14122. }
  14123. else
  14124. {
  14125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14126. }
  14127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14128. isKnowKey = TRUE;
  14129. }
  14130. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14131. {
  14132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14135. {
  14136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14137. }
  14138. else
  14139. {
  14140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14141. }
  14142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14143. isKnowKey = TRUE;
  14144. }
  14145. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14146. {
  14147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14149. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14150. {
  14151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14152. }
  14153. else
  14154. {
  14155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14156. }
  14157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14158. isKnowKey = TRUE;
  14159. }
  14160. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14161. {
  14162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14164. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14165. {
  14166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14167. }
  14168. else
  14169. {
  14170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14171. }
  14172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14173. isKnowKey = TRUE;
  14174. }
  14175. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14176. {
  14177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14179. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14180. {
  14181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14182. }
  14183. else
  14184. {
  14185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14186. }
  14187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14188. isKnowKey = TRUE;
  14189. }
  14190. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14191. {
  14192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14194. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14195. {
  14196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14197. }
  14198. else
  14199. {
  14200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14201. }
  14202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14203. isKnowKey = TRUE;
  14204. }
  14205. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14206. {
  14207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14209. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14210. {
  14211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14212. }
  14213. else
  14214. {
  14215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14216. }
  14217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14218. isKnowKey = TRUE;
  14219. }
  14220. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14221. {
  14222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14224. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14225. {
  14226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14227. }
  14228. else
  14229. {
  14230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14231. }
  14232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14233. isKnowKey = TRUE;
  14234. }
  14235. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14236. {
  14237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14239. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14240. {
  14241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14242. }
  14243. else
  14244. {
  14245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14246. }
  14247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14248. isKnowKey = TRUE;
  14249. }
  14250. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14251. {
  14252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14254. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14255. {
  14256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14257. }
  14258. else
  14259. {
  14260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14261. }
  14262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14263. isKnowKey = TRUE;
  14264. }
  14265. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14266. {
  14267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14269. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14270. {
  14271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14272. }
  14273. else
  14274. {
  14275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14276. }
  14277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14278. isKnowKey = TRUE;
  14279. }
  14280. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14281. {
  14282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14284. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14285. {
  14286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14287. }
  14288. else
  14289. {
  14290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14291. }
  14292. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14294. isKnowKey = TRUE;
  14295. }
  14296. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14297. {
  14298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14300. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14301. {
  14302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14303. }
  14304. else
  14305. {
  14306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14307. }
  14308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14309. isKnowKey = TRUE;
  14310. }
  14311. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14312. {
  14313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14315. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14316. {
  14317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14318. }
  14319. else
  14320. {
  14321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14322. }
  14323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14324. isKnowKey = TRUE;
  14325. }
  14326. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14327. {
  14328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14330. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14331. {
  14332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14333. }
  14334. else
  14335. {
  14336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14337. }
  14338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14339. isKnowKey = TRUE;
  14340. }
  14341. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14342. {
  14343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14345. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14346. {
  14347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14348. }
  14349. else
  14350. {
  14351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14352. }
  14353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14354. isKnowKey = TRUE;
  14355. }
  14356. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14357. {
  14358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14360. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14361. {
  14362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14363. }
  14364. else
  14365. {
  14366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14367. }
  14368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14369. isKnowKey = TRUE;
  14370. }
  14371. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14372. {
  14373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14375. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14376. {
  14377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14378. }
  14379. else
  14380. {
  14381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14382. }
  14383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14384. isKnowKey = TRUE;
  14385. }
  14386. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14387. {
  14388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14390. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14391. {
  14392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14393. }
  14394. else
  14395. {
  14396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14397. }
  14398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14399. isKnowKey = TRUE;
  14400. }
  14401. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14402. {
  14403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14405. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14406. {
  14407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14408. }
  14409. else
  14410. {
  14411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14412. }
  14413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14414. isKnowKey = TRUE;
  14415. }
  14416. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14417. {
  14418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14421. {
  14422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14423. }
  14424. else
  14425. {
  14426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14427. }
  14428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14429. isKnowKey = TRUE;
  14430. }
  14431. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14432. {
  14433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14435. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14436. {
  14437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14438. }
  14439. else
  14440. {
  14441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14442. }
  14443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14444. isKnowKey = TRUE;
  14445. }
  14446. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14447. {
  14448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14450. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14451. {
  14452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14453. }
  14454. else
  14455. {
  14456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14457. }
  14458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14459. isKnowKey = TRUE;
  14460. }
  14461. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14462. {
  14463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14465. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14466. {
  14467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14468. }
  14469. else
  14470. {
  14471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14472. }
  14473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14474. isKnowKey = TRUE;
  14475. }
  14476. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14477. {
  14478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14480. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14481. {
  14482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14483. }
  14484. else
  14485. {
  14486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14487. }
  14488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14489. isKnowKey = TRUE;
  14490. }
  14491. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14492. {
  14493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14495. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14496. {
  14497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14498. }
  14499. else
  14500. {
  14501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14502. }
  14503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14504. isKnowKey = TRUE;
  14505. }
  14506. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14507. {
  14508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14510. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14511. {
  14512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14513. }
  14514. else
  14515. {
  14516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14517. }
  14518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14519. isKnowKey = TRUE;
  14520. }
  14521. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14522. {
  14523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14525. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14526. {
  14527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14528. }
  14529. else
  14530. {
  14531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14532. }
  14533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14534. isKnowKey = TRUE;
  14535. }
  14536. /*
  14537. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14538. {
  14539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14541. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14542. {
  14543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14544. }
  14545. else
  14546. {
  14547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14548. }
  14549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14550. isKnowKey = TRUE;
  14551. }*/
  14552. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14553. {
  14554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14557. {
  14558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14559. }
  14560. else
  14561. {
  14562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14563. }
  14564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14565. isKnowKey = TRUE;
  14566. }
  14567. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14568. {
  14569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14572. {
  14573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14574. }
  14575. else
  14576. {
  14577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14578. }
  14579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14580. isKnowKey = TRUE;
  14581. }
  14582. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14583. {
  14584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14586. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14587. {
  14588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14589. }
  14590. else
  14591. {
  14592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14593. }
  14594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14595. isKnowKey = TRUE;
  14596. }
  14597. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14598. {
  14599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14601. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14602. {
  14603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14604. }
  14605. else
  14606. {
  14607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14608. }
  14609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14610. isKnowKey = TRUE;
  14611. }
  14612. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14613. {
  14614. struct sysinfo s_info;
  14615. int error = sysinfo(&s_info);
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14619. {
  14620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14621. }
  14622. else
  14623. {
  14624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14625. }
  14626. if(error != 0)
  14627. {
  14628. DEBUG_WARN("System uptime get error: %d\n", error);
  14629. }
  14630. else
  14631. {
  14632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14633. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14634. }
  14635. isKnowKey = TRUE;
  14636. }
  14637. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14638. {
  14639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14641. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14642. {
  14643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14644. }
  14645. else
  14646. {
  14647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14648. }
  14649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14650. isKnowKey = TRUE;
  14651. }
  14652. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14653. {
  14654. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14657. {
  14658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14659. }
  14660. else
  14661. {
  14662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14663. }
  14664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14665. isKnowKey = TRUE;
  14666. }
  14667. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14668. {
  14669. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14672. {
  14673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14674. }
  14675. else
  14676. {
  14677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14678. }
  14679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14680. isKnowKey = TRUE;
  14681. }
  14682. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14683. {
  14684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14686. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14687. {
  14688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14689. }
  14690. else
  14691. {
  14692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14693. }
  14694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14695. isKnowKey = TRUE;
  14696. }
  14697. #if 1
  14698. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14699. {
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14702. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14703. {
  14704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14705. }
  14706. else
  14707. {
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14709. }
  14710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14711. isKnowKey = TRUE;
  14712. }
  14713. #endif
  14714. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14715. {
  14716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14718. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14719. {
  14720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14721. }
  14722. else
  14723. {
  14724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14725. }
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14727. isKnowKey = TRUE;
  14728. }
  14729. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14730. {
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14733. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14734. {
  14735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14736. }
  14737. else
  14738. {
  14739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14740. }
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14742. isKnowKey = TRUE;
  14743. }
  14744. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14745. {
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14748. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14749. {
  14750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14751. }
  14752. else
  14753. {
  14754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14755. }
  14756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14757. isKnowKey = TRUE;
  14758. }
  14759. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14760. {
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14763. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14764. {
  14765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14766. }
  14767. else
  14768. {
  14769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14770. }
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14772. isKnowKey = TRUE;
  14773. }
  14774. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14775. {
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14778. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14779. {
  14780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14781. }
  14782. else
  14783. {
  14784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14785. }
  14786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14787. isKnowKey = TRUE;
  14788. }
  14789. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14790. {
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14793. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14794. {
  14795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14796. }
  14797. else
  14798. {
  14799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14800. }
  14801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14802. isKnowKey = TRUE;
  14803. }
  14804. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14805. {
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14808. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14809. {
  14810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14811. }
  14812. else
  14813. {
  14814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14815. }
  14816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14817. isKnowKey = TRUE;
  14818. }
  14819. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14820. {
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14823. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14824. {
  14825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14826. }
  14827. else
  14828. {
  14829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14830. }
  14831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14832. isKnowKey = TRUE;
  14833. }
  14834. //=========================================================
  14835. if(!isEmpty && !isKnowKey)
  14836. {
  14837. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14838. strcpy(unknownkey[UnknownKeynum], keyReq);
  14839. UnknownKeynum = UnknownKeynum + 1;
  14840. }
  14841. }
  14842. void processUnkownKey(void)
  14843. {
  14844. DEBUG_INFO("processUnkownKey...\n");
  14845. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14846. for(int index=0; index < UnknownKeynum; index++)
  14847. {
  14848. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14849. {
  14850. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14851. }
  14852. }
  14853. }
  14854. int setKeyValue(char *key, char *value)
  14855. {
  14856. int isSuccess = NotSupported;
  14857. int check_ascii=0;
  14858. char str[501]={0};
  14859. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14860. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14861. {
  14862. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14863. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14864. {
  14865. strcpy(str, (const char*)value);
  14866. for(int i = 0; str[i]; i++){
  14867. str[i] = tolower(str[i]);
  14868. }
  14869. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14870. isSuccess = ConfigurationStatus_Accepted;
  14871. }
  14872. else
  14873. {
  14874. isSuccess = ConfigurationStatus_Rejected;
  14875. }
  14876. }
  14877. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14878. {
  14879. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14880. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14881. {
  14882. strcpy(str, (const char*)value);
  14883. for(int i = 0; str[i]; i++){
  14884. str[i] = tolower(str[i]);
  14885. }
  14886. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14887. isSuccess = ConfigurationStatus_Accepted;
  14888. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  14889. }
  14890. else
  14891. {
  14892. isSuccess = ConfigurationStatus_Rejected;
  14893. }
  14894. }
  14895. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14896. {
  14897. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14898. {
  14899. strcpy(str, (const char*)value);
  14900. for(int i = 0; str[i]; i++)
  14901. {
  14902. str[i] = tolower(str[i]);
  14903. }
  14904. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14905. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14906. isSuccess = ConfigurationStatus_Accepted;
  14907. }
  14908. else
  14909. {
  14910. isSuccess = ConfigurationStatus_Rejected;
  14911. }
  14912. }
  14913. if(strcmp(key, "BlinkRepeat") == 0)
  14914. {
  14915. //Charger.BlinkRepeat = Integer.parseInt(value);
  14916. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14917. {
  14918. check_ascii = value[0];
  14919. if( (check_ascii < 48) || (check_ascii > 57) )
  14920. {
  14921. isSuccess = ConfigurationStatus_Rejected;
  14922. }
  14923. else
  14924. {
  14925. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14926. isSuccess = ConfigurationStatus_Accepted;
  14927. }
  14928. }
  14929. else
  14930. {
  14931. isSuccess = ConfigurationStatus_Rejected;
  14932. }
  14933. }
  14934. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14935. {
  14936. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14937. {
  14938. check_ascii = value[0];
  14939. if( (check_ascii < 48) || (check_ascii > 57) )
  14940. {
  14941. isSuccess = ConfigurationStatus_Rejected;
  14942. }
  14943. else
  14944. {
  14945. if((atoi(value) == 0) || (atoi(value) >= 5))
  14946. {
  14947. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14948. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14949. isSuccess = ConfigurationStatus_Accepted;
  14950. }
  14951. else
  14952. isSuccess = ConfigurationStatus_Rejected;
  14953. }
  14954. }
  14955. else
  14956. {
  14957. isSuccess = ConfigurationStatus_Rejected;
  14958. }
  14959. }
  14960. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14961. {
  14962. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14963. {
  14964. check_ascii = value[0];
  14965. if( (check_ascii < 48) || (check_ascii > 57) )
  14966. {
  14967. isSuccess = ConfigurationStatus_Rejected;
  14968. }
  14969. else
  14970. {
  14971. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14973. isSuccess = ConfigurationStatus_Accepted;
  14974. }
  14975. }
  14976. else
  14977. {
  14978. isSuccess = ConfigurationStatus_Rejected;
  14979. }
  14980. }
  14981. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14982. {
  14983. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14984. {
  14985. check_ascii = value[0];
  14986. if( (check_ascii < 48) || (check_ascii > 57) )
  14987. {
  14988. isSuccess = ConfigurationStatus_Rejected;
  14989. }
  14990. else
  14991. {
  14992. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14993. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14994. isSuccess = ConfigurationStatus_Accepted;
  14995. }
  14996. }
  14997. else
  14998. {
  14999. isSuccess = ConfigurationStatus_Rejected;
  15000. }
  15001. }
  15002. if(strcmp(key, "HeartbeatInterval") == 0)
  15003. {
  15004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15005. {
  15006. check_ascii = value[0];
  15007. if( (check_ascii < 48) || (check_ascii > 57) )
  15008. {
  15009. isSuccess = ConfigurationStatus_Rejected;
  15010. }
  15011. else
  15012. {
  15013. if((atoi(value) == 0) || (atoi(value) >= 10))
  15014. {
  15015. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15016. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15017. HeartBeatWaitTime = atoi(value);
  15018. isSuccess = ConfigurationStatus_Accepted;
  15019. }
  15020. else
  15021. {
  15022. isSuccess = ConfigurationStatus_Rejected;
  15023. }
  15024. }
  15025. }
  15026. else
  15027. {
  15028. isSuccess = ConfigurationStatus_Rejected;
  15029. }
  15030. }
  15031. if(strcmp(key, "LightIntensity") == 0)
  15032. {
  15033. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15034. {
  15035. check_ascii = value[0];
  15036. if( (check_ascii < 48) || (check_ascii > 57) )
  15037. {
  15038. isSuccess = ConfigurationStatus_Rejected;
  15039. }
  15040. else
  15041. {
  15042. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15043. isSuccess = ConfigurationStatus_Accepted;
  15044. }
  15045. }
  15046. else
  15047. {
  15048. isSuccess = ConfigurationStatus_Rejected;
  15049. }
  15050. }
  15051. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15052. {
  15053. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15054. {
  15055. strcpy(str, (const char*)value);
  15056. for(int i = 0; str[i]; i++)
  15057. {
  15058. str[i] = tolower(str[i]);
  15059. }
  15060. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15061. isSuccess = ConfigurationStatus_Accepted;
  15062. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15063. }
  15064. else
  15065. {
  15066. isSuccess = ConfigurationStatus_Rejected;
  15067. }
  15068. }
  15069. if(strcmp(key, "LocalPreAuthorize") == 0)
  15070. {
  15071. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15072. {
  15073. strcpy(str, (const char*)value);
  15074. for(int i = 0; str[i]; i++)
  15075. {
  15076. str[i] = tolower(str[i]);
  15077. }
  15078. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15079. isSuccess = ConfigurationStatus_Accepted;
  15080. }
  15081. else
  15082. {
  15083. isSuccess = ConfigurationStatus_Rejected;
  15084. }
  15085. }
  15086. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15087. {
  15088. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15089. {
  15090. check_ascii = value[0];
  15091. if( (check_ascii < 48) || (check_ascii > 57) )
  15092. {
  15093. isSuccess = ConfigurationStatus_Rejected;
  15094. }
  15095. else
  15096. {
  15097. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15098. isSuccess = ConfigurationStatus_Accepted;
  15099. }
  15100. }
  15101. else
  15102. {
  15103. isSuccess = ConfigurationStatus_Rejected;
  15104. }
  15105. }
  15106. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15107. {
  15108. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15109. {
  15110. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15111. isSuccess = ConfigurationStatus_Accepted;
  15112. }
  15113. else
  15114. {
  15115. isSuccess = ConfigurationStatus_Rejected;
  15116. }
  15117. }
  15118. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15119. {
  15120. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15121. {
  15122. check_ascii = value[0];
  15123. if( (check_ascii < 48) || (check_ascii > 57) )
  15124. {
  15125. isSuccess = ConfigurationStatus_Rejected;
  15126. }
  15127. else
  15128. {
  15129. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15130. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15131. isSuccess = ConfigurationStatus_Accepted;
  15132. }
  15133. }
  15134. else
  15135. {
  15136. isSuccess = ConfigurationStatus_Rejected;
  15137. }
  15138. }
  15139. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15140. {
  15141. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15142. {
  15143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15144. isSuccess = ConfigurationStatus_Accepted;
  15145. }
  15146. else
  15147. {
  15148. isSuccess = ConfigurationStatus_Rejected;
  15149. }
  15150. }
  15151. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15152. {
  15153. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15154. {
  15155. check_ascii = value[0];
  15156. if( (check_ascii < 48) || (check_ascii > 57) )
  15157. {
  15158. isSuccess = ConfigurationStatus_Rejected;
  15159. }
  15160. else
  15161. {
  15162. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15163. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15164. isSuccess = ConfigurationStatus_Accepted;
  15165. }
  15166. }
  15167. else
  15168. {
  15169. isSuccess = ConfigurationStatus_Rejected;
  15170. }
  15171. }
  15172. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15173. {
  15174. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15175. {
  15176. check_ascii = value[0];
  15177. if( (check_ascii < 48) || (check_ascii > 57) )
  15178. {
  15179. isSuccess = ConfigurationStatus_Rejected;
  15180. }
  15181. else
  15182. {
  15183. if((atoi(value) == 0) || (atoi(value) >= 3))
  15184. {
  15185. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15186. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15187. isSuccess = ConfigurationStatus_Accepted;
  15188. }
  15189. else
  15190. {
  15191. isSuccess = ConfigurationStatus_Rejected;
  15192. }
  15193. }
  15194. }
  15195. else
  15196. {
  15197. isSuccess = ConfigurationStatus_Rejected;
  15198. }
  15199. }
  15200. if(strcmp(key, "MinimumStatusDuration") == 0)
  15201. {
  15202. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15203. {
  15204. check_ascii = value[0];
  15205. if( (check_ascii < 48) || (check_ascii > 57) )
  15206. {
  15207. isSuccess = ConfigurationStatus_Rejected;
  15208. }
  15209. else
  15210. {
  15211. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15212. {
  15213. isSuccess = ConfigurationStatus_Rejected;
  15214. }
  15215. else
  15216. {
  15217. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15218. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15219. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15220. isSuccess = ConfigurationStatus_Accepted;
  15221. }
  15222. }
  15223. }
  15224. else
  15225. {
  15226. isSuccess = ConfigurationStatus_Rejected;
  15227. }
  15228. }
  15229. if(strcmp(key, "NumberOfConnectors") == 0)
  15230. {
  15231. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15232. {
  15233. check_ascii = value[0];
  15234. if( (check_ascii < 48) || (check_ascii > 57) )
  15235. {
  15236. isSuccess = ConfigurationStatus_Rejected;
  15237. }
  15238. else
  15239. {
  15240. //Charger.ResetRetries = Integer.parseInt(value);
  15241. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15242. isSuccess = ConfigurationStatus_Accepted;
  15243. }
  15244. }
  15245. else
  15246. {
  15247. isSuccess = ConfigurationStatus_Rejected;
  15248. }
  15249. }
  15250. if(strcmp(key, "ResetRetries") == 0)
  15251. {
  15252. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15253. {
  15254. check_ascii = value[0];
  15255. if( (check_ascii < 48) || (check_ascii > 57) )
  15256. {
  15257. isSuccess = ConfigurationStatus_Rejected;
  15258. }
  15259. else
  15260. {
  15261. //Charger.ResetRetries = Integer.parseInt(value);
  15262. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15263. isSuccess = ConfigurationStatus_Accepted;
  15264. }
  15265. }
  15266. else
  15267. {
  15268. isSuccess = ConfigurationStatus_Rejected;
  15269. }
  15270. }
  15271. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15272. {
  15273. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15274. {
  15275. strcpy(str, (const char*)value);
  15276. for(int i = 0; str[i]; i++)
  15277. {
  15278. str[i] = tolower(str[i]);
  15279. }
  15280. if(strcmp(str, "notapplicable")== 0)
  15281. {
  15282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15283. isSuccess = ConfigurationStatus_Accepted;
  15284. }
  15285. else if(strcmp(str, "unknown")== 0)
  15286. {
  15287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15288. isSuccess = ConfigurationStatus_Accepted;
  15289. }
  15290. else if(strcmp(str, "rst")== 0)
  15291. {
  15292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15293. isSuccess = ConfigurationStatus_Accepted;
  15294. }
  15295. else if(strcmp(str, "rts")== 0)
  15296. {
  15297. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15298. isSuccess = ConfigurationStatus_Accepted;
  15299. }
  15300. else if(strcmp(str, "srt")== 0)
  15301. {
  15302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15303. isSuccess = ConfigurationStatus_Accepted;
  15304. }
  15305. else if(strcmp(str, "str")== 0)
  15306. {
  15307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15308. isSuccess = ConfigurationStatus_Accepted;
  15309. }
  15310. else if(strcmp(str, "trs")== 0)
  15311. {
  15312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15313. isSuccess = ConfigurationStatus_Accepted;
  15314. }
  15315. else if(strcmp(str, "tsr")== 0)
  15316. {
  15317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15318. isSuccess = ConfigurationStatus_Accepted;
  15319. }
  15320. else
  15321. {
  15322. isSuccess = ConfigurationStatus_Rejected;
  15323. }
  15324. }
  15325. else
  15326. {
  15327. isSuccess = ConfigurationStatus_Rejected;
  15328. }
  15329. }
  15330. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15331. {
  15332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15333. {
  15334. check_ascii = value[0];
  15335. if( (check_ascii < 48) || (check_ascii > 57) )
  15336. {
  15337. isSuccess = ConfigurationStatus_Rejected;
  15338. }
  15339. else
  15340. {
  15341. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15342. isSuccess = ConfigurationStatus_Accepted;
  15343. }
  15344. }
  15345. else
  15346. {
  15347. isSuccess = ConfigurationStatus_Rejected;
  15348. }
  15349. }
  15350. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15351. {
  15352. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15353. {
  15354. strcpy(str, (const char*)value);
  15355. for(int i = 0; str[i]; i++)
  15356. {
  15357. str[i] = tolower(str[i]);
  15358. }
  15359. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15360. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15361. isSuccess = ConfigurationStatus_Accepted;
  15362. }
  15363. else
  15364. {
  15365. isSuccess = ConfigurationStatus_Rejected;
  15366. }
  15367. }
  15368. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15369. {
  15370. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15371. {
  15372. strcpy(str, (const char*)value);
  15373. for(int i = 0; str[i]; i++)
  15374. {
  15375. str[i] = tolower(str[i]);
  15376. }
  15377. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15378. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15379. isSuccess = ConfigurationStatus_Accepted;
  15380. }
  15381. else
  15382. {
  15383. isSuccess = ConfigurationStatus_Rejected;
  15384. }
  15385. }
  15386. if(strcmp(key, "StopTxnAlignedData") == 0)
  15387. {
  15388. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15389. {
  15390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15391. isSuccess = ConfigurationStatus_Accepted;
  15392. }
  15393. else
  15394. {
  15395. isSuccess = ConfigurationStatus_Rejected;
  15396. }
  15397. }
  15398. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15399. {
  15400. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15401. {
  15402. check_ascii = value[0];
  15403. if( (check_ascii < 48) || (check_ascii > 57) )
  15404. {
  15405. isSuccess = ConfigurationStatus_Rejected;
  15406. }
  15407. else
  15408. {
  15409. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15410. isSuccess = ConfigurationStatus_Accepted;
  15411. }
  15412. }
  15413. else
  15414. {
  15415. isSuccess = ConfigurationStatus_Rejected;
  15416. }
  15417. }
  15418. if(strcmp(key, "StopTxnSampledData") == 0)
  15419. {
  15420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15421. {
  15422. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15423. isSuccess = ConfigurationStatus_Accepted;
  15424. }
  15425. else
  15426. {
  15427. isSuccess = ConfigurationStatus_Rejected;
  15428. }
  15429. }
  15430. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15431. {
  15432. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15433. {
  15434. check_ascii = value[0];
  15435. if( (check_ascii < 48) || (check_ascii > 57) )
  15436. {
  15437. isSuccess = ConfigurationStatus_Rejected;
  15438. }
  15439. else
  15440. {
  15441. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15442. isSuccess = ConfigurationStatus_Accepted;
  15443. }
  15444. }
  15445. else
  15446. {
  15447. isSuccess = ConfigurationStatus_Rejected;
  15448. }
  15449. }
  15450. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15451. {
  15452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15453. {
  15454. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15455. isSuccess = ConfigurationStatus_Accepted;
  15456. }
  15457. else
  15458. {
  15459. isSuccess = ConfigurationStatus_Rejected;
  15460. }
  15461. }
  15462. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15463. {
  15464. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15465. {
  15466. check_ascii = value[0];
  15467. if( (check_ascii < 48) || (check_ascii > 57) )
  15468. {
  15469. isSuccess = ConfigurationStatus_Rejected;
  15470. }
  15471. else
  15472. {
  15473. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15474. isSuccess = ConfigurationStatus_Accepted;
  15475. }
  15476. }
  15477. else
  15478. {
  15479. isSuccess = ConfigurationStatus_Rejected;
  15480. }
  15481. }
  15482. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15483. {
  15484. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15485. {
  15486. check_ascii = value[0];
  15487. if( (check_ascii < 48) || (check_ascii > 57) )
  15488. {
  15489. isSuccess = ConfigurationStatus_Rejected;
  15490. }
  15491. else
  15492. {
  15493. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15495. TransactionMessageAttemptsValue = atoi(value);
  15496. isSuccess = ConfigurationStatus_Accepted;
  15497. }
  15498. }
  15499. else
  15500. {
  15501. isSuccess = ConfigurationStatus_Rejected;
  15502. }
  15503. }
  15504. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15505. {
  15506. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15507. {
  15508. check_ascii = value[0];
  15509. if( (check_ascii < 48) || (check_ascii > 57) )
  15510. {
  15511. isSuccess = ConfigurationStatus_Rejected;
  15512. }
  15513. else
  15514. {
  15515. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15516. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15517. TransactionMessageRetryIntervalValue = atoi(value);
  15518. isSuccess = ConfigurationStatus_Accepted;
  15519. }
  15520. }
  15521. else
  15522. {
  15523. isSuccess = ConfigurationStatus_Rejected;
  15524. }
  15525. }
  15526. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15527. {
  15528. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15529. {
  15530. strcpy(str, (const char*)value);
  15531. for(int i = 0; str[i]; i++)
  15532. {
  15533. str[i] = tolower(str[i]);
  15534. }
  15535. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15537. isSuccess = ConfigurationStatus_Accepted;
  15538. }
  15539. else
  15540. {
  15541. isSuccess = ConfigurationStatus_Rejected;
  15542. }
  15543. }
  15544. if(strcmp(key, "WebSocketPingInterval") == 0)
  15545. {
  15546. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15547. {
  15548. check_ascii = value[0];
  15549. if( (check_ascii < 48) || (check_ascii > 57) )
  15550. {
  15551. isSuccess = ConfigurationStatus_Rejected;
  15552. }
  15553. else
  15554. {
  15555. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15556. isSuccess = ConfigurationStatus_Accepted;
  15557. if((atoi(value) == 0) || (atoi(value) >= 10))
  15558. {
  15559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15560. isSuccess = ConfigurationStatus_Accepted;
  15561. }
  15562. else
  15563. isSuccess = ConfigurationStatus_Rejected;
  15564. }
  15565. }
  15566. else
  15567. {
  15568. isSuccess = ConfigurationStatus_Rejected;
  15569. }
  15570. }
  15571. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15572. {
  15573. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15574. {
  15575. strcpy(str, (const char*)value);
  15576. for(int i = 0; str[i]; i++)
  15577. {
  15578. str[i] = tolower(str[i]);
  15579. }
  15580. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15581. isSuccess = ConfigurationStatus_Accepted;
  15582. }
  15583. else
  15584. {
  15585. isSuccess = ConfigurationStatus_Rejected;
  15586. }
  15587. }
  15588. if(strcmp(key, "AuthorizationKey") == 0)
  15589. {
  15590. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15591. {
  15592. strcpy(str, (const char*)value);
  15593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15594. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15595. isSuccess = ConfigurationStatus_Accepted;
  15596. }
  15597. else
  15598. {
  15599. isSuccess = ConfigurationStatus_Rejected;
  15600. }
  15601. }
  15602. if(strcmp(key, "SecurityProfile") == 0)
  15603. {
  15604. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15605. {
  15606. check_ascii = value[0];
  15607. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15608. {
  15609. isSuccess = ConfigurationStatus_Rejected;
  15610. }
  15611. else if(check_ascii == 0x33)
  15612. {
  15613. isSuccess = NotSupported;
  15614. }
  15615. else
  15616. {
  15617. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15618. {
  15619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15620. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15621. isSuccess = ConfigurationStatus_Accepted;
  15622. }
  15623. else
  15624. isSuccess = ConfigurationStatus_Rejected;
  15625. }
  15626. }
  15627. else
  15628. {
  15629. isSuccess = ConfigurationStatus_Rejected;
  15630. }
  15631. }
  15632. if(strcmp(key, "DefaultPrice") == 0)
  15633. {
  15634. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15635. {
  15636. strcpy(str, (const char*)value);
  15637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15638. isSuccess = ConfigurationStatus_Accepted;
  15639. }
  15640. else
  15641. {
  15642. isSuccess = ConfigurationStatus_Rejected;
  15643. }
  15644. }
  15645. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15646. {
  15647. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15648. {
  15649. strcpy(str, (const char*)value);
  15650. for(int i = 0; str[i]; i++)
  15651. {
  15652. str[i] = tolower(str[i]);
  15653. }
  15654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15655. isSuccess = ConfigurationStatus_Accepted;
  15656. }
  15657. else
  15658. {
  15659. isSuccess = ConfigurationStatus_Rejected;
  15660. }
  15661. }
  15662. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15663. {
  15664. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15665. {
  15666. strcpy(str, (const char*)value);
  15667. for(int i = 0; str[i]; i++)
  15668. {
  15669. str[i] = tolower(str[i]);
  15670. }
  15671. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15672. isSuccess = ConfigurationStatus_Accepted;
  15673. }
  15674. else
  15675. {
  15676. isSuccess = ConfigurationStatus_Rejected;
  15677. }
  15678. }
  15679. if(strcmp(key, "SystemUptimeSec") == 0)
  15680. {
  15681. isSuccess = NotSupported;
  15682. }
  15683. if(strcmp(key, "FreeVend") == 0)
  15684. {
  15685. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15686. {
  15687. strcpy(str, (const char*)value);
  15688. for(int i = 0; str[i]; i++)
  15689. {
  15690. str[i] = tolower(str[i]);
  15691. }
  15692. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15693. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15694. isSuccess = ConfigurationStatus_Accepted;
  15695. }
  15696. else
  15697. {
  15698. isSuccess = ConfigurationStatus_Rejected;
  15699. }
  15700. }
  15701. if(strcmp(key, "OcppServer") == 0)
  15702. {
  15703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15704. {
  15705. strcpy(str, (const char*)value);
  15706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  15707. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  15708. isSuccess = ConfigurationStatus_Accepted;
  15709. }
  15710. else
  15711. {
  15712. isSuccess = ConfigurationStatus_Rejected;
  15713. }
  15714. }
  15715. if(strcmp(key, "MaintainServer") == 0)
  15716. {
  15717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15718. {
  15719. strcpy(str, (const char*)value);
  15720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  15721. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  15722. isSuccess = ConfigurationStatus_Accepted;
  15723. }
  15724. else
  15725. {
  15726. isSuccess = ConfigurationStatus_Rejected;
  15727. }
  15728. }
  15729. #if 0
  15730. //For OCPP Test Case
  15731. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15732. {
  15733. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15734. {
  15735. strcpy(str, (const char*)value);
  15736. for(int i = 0; str[i]; i++)
  15737. {
  15738. str[i] = tolower(str[i]);
  15739. }
  15740. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15741. isSuccess = ConfigurationStatus_Accepted;
  15742. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15743. }
  15744. else
  15745. {
  15746. isSuccess = ConfigurationStatus_Rejected;
  15747. }
  15748. }
  15749. #endif
  15750. #if 1
  15751. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15752. {
  15753. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15754. {
  15755. strcpy(str, (const char*)value);
  15756. for(int i = 0; str[i]; i++)
  15757. {
  15758. str[i] = tolower(str[i]);
  15759. }
  15760. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15761. isSuccess = ConfigurationStatus_Accepted;
  15762. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15763. }
  15764. else
  15765. {
  15766. isSuccess = ConfigurationStatus_Rejected;
  15767. }
  15768. }
  15769. #endif
  15770. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15771. {
  15772. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15773. {
  15774. check_ascii = value[0];
  15775. if( (check_ascii < 48) || (check_ascii > 57) )
  15776. {
  15777. isSuccess = ConfigurationStatus_Rejected;
  15778. }
  15779. else
  15780. {
  15781. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15782. isSuccess = ConfigurationStatus_Accepted;
  15783. }
  15784. }
  15785. else
  15786. {
  15787. isSuccess = ConfigurationStatus_Rejected;
  15788. }
  15789. }
  15790. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15791. {
  15792. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15793. {
  15794. check_ascii = value[0];
  15795. if( (check_ascii < 48) || (check_ascii > 57) )
  15796. {
  15797. isSuccess = ConfigurationStatus_Rejected;
  15798. }
  15799. else
  15800. {
  15801. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15802. isSuccess = ConfigurationStatus_Accepted;
  15803. }
  15804. }
  15805. else
  15806. {
  15807. isSuccess = ConfigurationStatus_Rejected;
  15808. }
  15809. }
  15810. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15811. {
  15812. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15813. {
  15814. strcpy(str, (const char*)value);
  15815. for(int i = 0; str[i]; i++)
  15816. {
  15817. str[i] = tolower(str[i]);
  15818. }
  15819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15820. isSuccess = ConfigurationStatus_Accepted;
  15821. }
  15822. else
  15823. {
  15824. isSuccess = ConfigurationStatus_Rejected;
  15825. }
  15826. }
  15827. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15828. {
  15829. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15830. {
  15831. check_ascii = value[0];
  15832. if( (check_ascii < 48) || (check_ascii > 57) )
  15833. {
  15834. isSuccess = ConfigurationStatus_Rejected;
  15835. }
  15836. else
  15837. {
  15838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15839. isSuccess = ConfigurationStatus_Accepted;
  15840. }
  15841. }
  15842. else
  15843. {
  15844. isSuccess = ConfigurationStatus_Rejected;
  15845. }
  15846. }
  15847. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15848. {
  15849. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15850. {
  15851. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15852. isSuccess = ConfigurationStatus_Accepted;
  15853. }
  15854. else
  15855. {
  15856. isSuccess = ConfigurationStatus_Rejected;
  15857. }
  15858. }
  15859. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15860. {
  15861. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15862. {
  15863. check_ascii = value[0];
  15864. if( (check_ascii < 48) || (check_ascii > 57) )
  15865. {
  15866. isSuccess = ConfigurationStatus_Rejected;
  15867. }
  15868. else
  15869. {
  15870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15871. isSuccess = ConfigurationStatus_Accepted;
  15872. }
  15873. }
  15874. else
  15875. {
  15876. isSuccess = ConfigurationStatus_Rejected;
  15877. }
  15878. }
  15879. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15880. {
  15881. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15882. {
  15883. strcpy(str, (const char*)value);
  15884. for(int i = 0; str[i]; i++)
  15885. {
  15886. str[i] = tolower(str[i]);
  15887. }
  15888. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15889. isSuccess = ConfigurationStatus_Accepted;
  15890. }
  15891. else
  15892. {
  15893. isSuccess = ConfigurationStatus_Rejected;
  15894. }
  15895. }
  15896. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15897. {
  15898. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15899. {
  15900. check_ascii = value[0];
  15901. if( (check_ascii < 48) || (check_ascii > 57) )
  15902. {
  15903. isSuccess = ConfigurationStatus_Rejected;
  15904. }
  15905. else
  15906. {
  15907. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15908. isSuccess = ConfigurationStatus_Accepted;
  15909. }
  15910. }
  15911. else
  15912. {
  15913. isSuccess = ConfigurationStatus_Rejected;
  15914. }
  15915. }
  15916. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15917. return isSuccess;
  15918. }
  15919. int TransactionMessageAttemptsGet(void)
  15920. {
  15921. return TransactionMessageAttemptsValue;
  15922. }
  15923. int FirstHeartBeatResponse(void)
  15924. {
  15925. return FirstHeartBeat;
  15926. }
  15927. int TransactionMessageRetryIntervalGet(void)
  15928. {
  15929. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15930. }
  15931. int ReadHttpStatus(int sock)
  15932. {
  15933. //char c;
  15934. char buff[1024]="",*ptr=buff+1;
  15935. int bytes_received, status;
  15936. DEBUG_INFO("Begin Response ..\n");
  15937. while((bytes_received = recv(sock, ptr, 1, 0))){
  15938. if(bytes_received==-1){
  15939. perror("ReadHttpStatus");
  15940. exit(1);
  15941. }
  15942. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15943. ptr++;
  15944. }
  15945. *ptr=0;
  15946. ptr=buff+1;
  15947. sscanf(ptr,"%*s %d ", &status);
  15948. DEBUG_INFO("%s\n",ptr);
  15949. DEBUG_INFO("status=%d\n",status);
  15950. DEBUG_INFO("End Response ..\n");
  15951. return (bytes_received>0)?status:0;
  15952. }
  15953. //the only filed that it parsed is 'Content-Length'
  15954. int ParseHeader(int sock)
  15955. {
  15956. //char c;
  15957. char buff[1024]="",*ptr=buff+4;
  15958. int bytes_received;
  15959. DEBUG_INFO("Begin HEADER ..\n");
  15960. while((bytes_received = recv(sock, ptr, 1, 0))){
  15961. if(bytes_received==-1){
  15962. perror("Parse Header");
  15963. exit(1);
  15964. }
  15965. if(
  15966. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15967. (ptr[-1]=='\r') && (*ptr=='\n' )
  15968. ) break;
  15969. ptr++;
  15970. }
  15971. *ptr=0;
  15972. ptr=buff+4;
  15973. //printf("%s",ptr);
  15974. if(bytes_received){
  15975. ptr=strstr(ptr,"Content-Length:");
  15976. if(ptr){
  15977. sscanf(ptr,"%*s %d",&bytes_received);
  15978. }else
  15979. bytes_received=-1; //unknown size
  15980. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15981. }
  15982. DEBUG_INFO("End HEADER ..\n");
  15983. return bytes_received ;
  15984. }
  15985. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15986. {
  15987. int result = TRUE;
  15988. char rmFileCmd[100]={0};
  15989. char FilePath[100]={0};
  15990. char ftpbuf[200];
  15991. int systemresult;
  15992. sprintf(FilePath,"/mnt/%s",filename);
  15993. system("ping 8.8.8.8 &");
  15994. if((access(FilePath,F_OK))!=-1)
  15995. {
  15996. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15997. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15998. system(rmFileCmd);
  15999. }
  16000. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16001. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16002. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16003. systemresult = system(ftpbuf);
  16004. if(systemresult != 0)
  16005. {
  16006. DEBUG_INFO("http DownLoad error!\n");
  16007. result = FALSE;
  16008. }
  16009. system("pkill ping");
  16010. return result;
  16011. }
  16012. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16013. {
  16014. int result = TRUE;
  16015. char rmFileCmd[100]={0};
  16016. char FilePath[100]={0};
  16017. char ftpbuf[200];
  16018. int systemresult;
  16019. sprintf(FilePath,"/mnt/%s",filename);
  16020. system("ping 8.8.8.8 &");
  16021. if((access(FilePath,F_OK))!=-1)
  16022. {
  16023. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16024. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16025. system(rmFileCmd);
  16026. }
  16027. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16028. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16029. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16030. systemresult = system(ftpbuf);
  16031. if(systemresult != 0)
  16032. {
  16033. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16034. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16035. systemresult = system(ftpbuf);
  16036. if(systemresult != 0)
  16037. {
  16038. DEBUG_WARN("wget error!\n");
  16039. result = FALSE;
  16040. }
  16041. }
  16042. system("pkill ping");
  16043. return result;
  16044. }
  16045. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16046. {
  16047. char rmFileCmd[100]={0};
  16048. char FilePath[100]={0};
  16049. char buf[512];
  16050. int systemresult = 0;
  16051. //DEBUG_INFO("filename=%s\n",filename);
  16052. //DEBUG_INFO("url=%s\n",url);
  16053. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16054. if((access(FilePath,F_OK))!=-1)
  16055. {
  16056. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16057. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16058. system(rmFileCmd);
  16059. }
  16060. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16061. if(fp == NULL)
  16062. {
  16063. DEBUG_INFO("log is NULL\n");
  16064. return FALSE;
  16065. }
  16066. else
  16067. {
  16068. fprintf(fp, "%s\n", url);
  16069. fprintf(fp, "%s\n", filename);
  16070. fclose(fp);
  16071. }
  16072. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16073. if(phpFP == NULL)
  16074. {
  16075. DEBUG_INFO("PHP upload fail.\n");
  16076. return FALSE;
  16077. }
  16078. else
  16079. {
  16080. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16081. {
  16082. if(strstr(buf, "result") != NULL)
  16083. {
  16084. sscanf(buf, "result: %d", &systemresult);
  16085. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16086. }
  16087. }
  16088. pclose(phpFP);
  16089. }
  16090. if(systemresult != 1)
  16091. {
  16092. DEBUG_INFO("HTTP upload error!\n");
  16093. return FALSE;
  16094. }
  16095. return TRUE;
  16096. }
  16097. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16098. {
  16099. int result = FALSE;
  16100. char ftpbuf[200];
  16101. int systemresult;
  16102. /*
  16103. // Domaind name transfer to IP address
  16104. struct hostent* server;
  16105. char *IPbuffer;
  16106. server = gethostbyname(location);
  16107. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16108. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16109. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16110. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16111. systemresult = system(ftpbuf);
  16112. if(systemresult != 0)
  16113. {
  16114. DEBUG_INFO("ftpput error!\n");
  16115. }
  16116. else
  16117. {
  16118. result = TRUE;
  16119. DEBUG_INFO("ftpput OK!\n");
  16120. }
  16121. return result;
  16122. }
  16123. int GetOcppServerURL()
  16124. {
  16125. int result = FALSE;
  16126. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16127. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16128. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16129. struct yuarel url;
  16130. char urlStr[512];
  16131. // OCPPPH only
  16132. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16133. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16134. {
  16135. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16136. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16137. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16138. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16139. if(yuarel_parse(&url, urlStr) != -1)
  16140. {
  16141. sprintf(OcppProtocol, "%s", url.scheme);
  16142. sprintf(OcppHost, "%s", url.host);
  16143. if(url.path == NULL)
  16144. OcppTempPath[0] = '\0';
  16145. else
  16146. sprintf(OcppTempPath, "%s", url.path);
  16147. if(url.port == 0)
  16148. {
  16149. if(strcmp(OcppProtocol, "wss") == 0)
  16150. OcppPort = 443;
  16151. else
  16152. OcppPort = 80;
  16153. }
  16154. else
  16155. OcppPort = url.port;
  16156. result = TRUE;
  16157. }
  16158. }
  16159. else
  16160. {
  16161. strcpy(OcppHost,"");
  16162. }
  16163. return result;
  16164. }
  16165. int GetOcppPath()
  16166. {
  16167. int result = FALSE;
  16168. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16169. {
  16170. if(OcppTempPath == NULL)
  16171. {
  16172. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16173. }
  16174. else
  16175. {
  16176. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16177. }
  16178. result = TRUE;
  16179. goto End;
  16180. }
  16181. else
  16182. {
  16183. strcpy(OcppPath,"");
  16184. }
  16185. End:
  16186. return result;
  16187. }
  16188. int GetOcppPort()
  16189. {
  16190. return OcppPort;
  16191. }
  16192. int GetOcppConnStatus(void)
  16193. {
  16194. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16195. }
  16196. void SetOcppConnStatus(uint8_t status)
  16197. {
  16198. ShmOCPP16DataPH->OcppConnStatus = status;
  16199. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16200. }
  16201. int GetHeartBeatWithNOResponse(void)
  16202. {
  16203. return HeartBeatWithNOResponse;
  16204. }
  16205. void SetHeartBeatWithNOResponse(void)
  16206. {
  16207. HeartBeatWithNOResponse = 0;
  16208. }
  16209. void GetStartTransactionIdTag(int gun_index)
  16210. {
  16211. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16212. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16213. }
  16214. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16215. {
  16216. char ch;
  16217. FILE *fptr1;
  16218. int temptransactionId;
  16219. char str[100]={0};
  16220. temptransactionId = 0;
  16221. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16222. {
  16223. DEBUG_INFO("IdTag is empty.\n");
  16224. return temptransactionId;
  16225. }
  16226. /*------ Read the file ----------------*/
  16227. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16228. if (!fptr1)
  16229. {
  16230. DEBUG_INFO("QueueTransactionId file open error.\n");
  16231. //printf(" File not found or unable to open the input file!!\n");
  16232. return temptransactionId;
  16233. }
  16234. ch=fgetc(fptr1);
  16235. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16236. rewind(fptr1);
  16237. if(ch!=EOF)
  16238. {
  16239. // printf("%c",ch);
  16240. while (fgets(str, 100, fptr1) != NULL)
  16241. {
  16242. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16243. if(str[0]=='\0')
  16244. {
  16245. break;
  16246. }
  16247. char *revbuf[8] = {0}; // Variable store string split
  16248. int num = 0;// Quantity after string split
  16249. DEBUG_INFO("Transaction queue data= %s\n", str);
  16250. splitstring(str,",",revbuf,&num); // String split
  16251. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16252. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16253. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16254. DEBUG_INFO("------------------------------\n");
  16255. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16256. {
  16257. if(isStopTransaction)
  16258. {
  16259. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16260. {
  16261. temptransactionId = atoi(revbuf[2]);
  16262. //break;
  16263. }
  16264. }
  16265. else
  16266. {
  16267. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16268. {
  16269. temptransactionId = atoi(revbuf[2]);
  16270. //break;
  16271. }
  16272. }
  16273. }
  16274. }
  16275. }
  16276. else
  16277. DEBUG_INFO("EOF\n");
  16278. fclose(fptr1);
  16279. /*------- End of reading ---------------*/
  16280. return temptransactionId;
  16281. }
  16282. void SetTransactionIdZero(int transactionId)
  16283. {
  16284. char ch;
  16285. FILE *fptr1, *fptr2;
  16286. int temptransactionId = 0;
  16287. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16288. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16289. if (!fptr1)
  16290. {
  16291. //printf(" File not found or unable to open the input file!!\n");
  16292. return ;
  16293. }
  16294. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16295. if (!fptr2)
  16296. {
  16297. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16298. fclose(fptr1);
  16299. return ;
  16300. }
  16301. ch=fgetc(fptr1);
  16302. rewind(fptr1);
  16303. if(ch!=EOF)
  16304. {
  16305. // copy all contents to the temporary file except the specific line
  16306. while (fgets(str, 100, fptr1) != NULL)
  16307. {
  16308. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16309. if(str[0]=='\0')
  16310. {
  16311. break;
  16312. }
  16313. char *revbuf[8] = {0};
  16314. int num = 0;
  16315. strcpy(strtemp, str);
  16316. splitstring(str,",",revbuf,&num);
  16317. if(revbuf[2][0] != '\0')
  16318. {
  16319. temptransactionId = atoi(revbuf[2]);
  16320. if(transactionId != temptransactionId)
  16321. {
  16322. fprintf(fptr2, "%s\n", strtemp);
  16323. }
  16324. }
  16325. }
  16326. }
  16327. fclose(fptr1);
  16328. fclose(fptr2);
  16329. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16330. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16331. /*------ Read the file ----------------*/
  16332. }
  16333. int InternetDisconnect(void)
  16334. {
  16335. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16336. }
  16337. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16338. void storeTempStopTransaction(int gun_index)
  16339. {
  16340. char guid[37]={0};
  16341. int tempIndex = 0;
  16342. char TempStopTransaction[256];
  16343. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16344. DEBUG_INFO("storeTempStopTransaction...\n");
  16345. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16346. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16347. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16348. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16349. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16350. {
  16351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16352. {
  16353. tempIndex = ((gun_index==2) ? 1: 0);
  16354. }
  16355. else
  16356. {
  16357. tempIndex = gun_index;
  16358. }
  16359. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16360. {
  16361. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16362. {
  16363. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16364. }
  16365. }// END OF CHAdeMO_QUANTITY
  16366. }
  16367. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16368. {
  16369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16370. {
  16371. tempIndex = ((gun_index==2) ? 1: 0);
  16372. }
  16373. else
  16374. {
  16375. tempIndex = gun_index;
  16376. }
  16377. for (int index = 0; index < CCS_QUANTITY; index++)
  16378. {
  16379. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16380. {
  16381. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16382. }
  16383. }// END OF CCS_QUANTITY
  16384. }
  16385. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16386. {
  16387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16388. {
  16389. tempIndex = ((gun_index==2) ? 1: 0);
  16390. }
  16391. else
  16392. {
  16393. tempIndex = gun_index;
  16394. }
  16395. for (int index = 0; index < GB_QUANTITY; index++)
  16396. {
  16397. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16398. {
  16399. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16400. }
  16401. }// END OF GB_QUANTITY
  16402. }
  16403. else if(gunType[gun_index] == GUN_TYPE_DO)
  16404. {
  16405. tempIndex = gun_index;
  16406. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16407. {
  16408. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16409. {
  16410. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16411. }
  16412. }
  16413. }
  16414. else
  16415. {
  16416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16417. {
  16418. tempIndex = 2;
  16419. }
  16420. else
  16421. {
  16422. tempIndex = gun_index;
  16423. }
  16424. for (int index = 0; index < AC_QUANTITY; index++)
  16425. {
  16426. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16427. {
  16428. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16429. }
  16430. }// END OF AC_QUANTITY
  16431. }
  16432. //Stop Transaction Time
  16433. struct timeval tmnow;
  16434. struct tm *tm;
  16435. char buf[28];//, usec_buf[6];
  16436. gettimeofday(&tmnow, NULL);
  16437. time_t t;
  16438. t = time(NULL);
  16439. /*UTC time and date*/
  16440. tm = gmtime(&t);
  16441. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16442. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16443. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16444. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16445. random_uuid(guid);
  16446. /***********************************transactionData******************************************************/
  16447. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16449. //=================================
  16450. //1. Transaction_Begin
  16451. //=================================
  16452. //============================== Energy.Active.Import.Interval ===========================================
  16453. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16454. {
  16455. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16458. 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*/]);
  16459. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16460. 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))
  16461. {
  16462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16463. }
  16464. else
  16465. {
  16466. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16467. }
  16468. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16469. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16470. }
  16471. //=================================
  16472. //2. Transaction_End
  16473. //=================================
  16474. //2.1====================================== Current.Import L1 ==============================================
  16475. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16476. {
  16477. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16478. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16479. {
  16480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16481. {
  16482. tempIndex = ((gun_index==2) ? 1: 0);
  16483. }
  16484. else
  16485. {
  16486. tempIndex = gun_index;
  16487. }
  16488. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16489. {
  16490. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16491. {
  16492. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16493. }
  16494. }// End of for CHAdeMO_QUANTITY
  16495. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16496. }
  16497. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16498. {
  16499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16500. {
  16501. tempIndex = ((gun_index==2) ? 1: 0);
  16502. }
  16503. else
  16504. {
  16505. tempIndex = gun_index;
  16506. }
  16507. for (int index = 0; index < CCS_QUANTITY; index++)
  16508. {
  16509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16510. {
  16511. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16512. }
  16513. }// End of for CCS_QUANTITY
  16514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16515. }
  16516. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16517. {
  16518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16519. {
  16520. tempIndex = ((gun_index==2) ? 1: 0);
  16521. }
  16522. else
  16523. {
  16524. tempIndex = gun_index;
  16525. }
  16526. for (int index = 0; index < GB_QUANTITY; index++)
  16527. {
  16528. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16529. {
  16530. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16531. }
  16532. }// End of for GB_QUANTITY
  16533. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16534. }
  16535. else if(gunType[gun_index] == GUN_TYPE_DO)
  16536. {
  16537. tempIndex = gun_index;
  16538. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16539. {
  16540. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16541. {
  16542. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16543. }
  16544. }
  16545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16546. }
  16547. else
  16548. {
  16549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16550. {
  16551. tempIndex = 2;
  16552. }
  16553. else
  16554. {
  16555. tempIndex = gun_index;
  16556. }
  16557. for (int index = 0; index < AC_QUANTITY; index++)
  16558. {
  16559. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16560. {
  16561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16562. }
  16563. }// End of for AC_QUANTITY
  16564. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16565. }
  16566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16569. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16572. }
  16573. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16574. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16575. {
  16576. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16577. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16578. {
  16579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16580. {
  16581. tempIndex = ((gun_index==2) ? 1: 0);
  16582. }
  16583. else
  16584. {
  16585. tempIndex = gun_index;
  16586. }
  16587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16588. {
  16589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16590. {
  16591. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16592. }
  16593. }// END OF CHAdeMO_QUANTITY
  16594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16595. }
  16596. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16597. {
  16598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16599. {
  16600. tempIndex = ((gun_index==2) ? 1: 0);
  16601. }
  16602. else
  16603. {
  16604. tempIndex = gun_index;
  16605. }
  16606. for (int index = 0; index < CCS_QUANTITY; index++)
  16607. {
  16608. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16609. {
  16610. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16611. }
  16612. }// END OF CCS_QUANTITY
  16613. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16614. }
  16615. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16616. {
  16617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16618. {
  16619. tempIndex = ((gun_index==2) ? 1: 0);
  16620. }
  16621. else
  16622. {
  16623. tempIndex = gun_index;
  16624. }
  16625. for (int index = 0; index < GB_QUANTITY; index++)
  16626. {
  16627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16628. {
  16629. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16630. }
  16631. }// END OF GB_QUANTITY
  16632. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16633. }
  16634. else if(gunType[gun_index] == GUN_TYPE_DO)
  16635. {
  16636. tempIndex = gun_index;
  16637. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16638. {
  16639. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16640. {
  16641. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16642. }
  16643. }
  16644. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16645. }
  16646. else
  16647. {
  16648. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16649. {
  16650. tempIndex = 2;
  16651. }
  16652. else
  16653. {
  16654. tempIndex = gun_index;
  16655. }
  16656. for (int index = 0; index < AC_QUANTITY; index++)
  16657. {
  16658. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16659. {
  16660. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16661. }
  16662. }// END OF AC_QUANTITY
  16663. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16664. }
  16665. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16666. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16667. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16668. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16669. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16670. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16671. }
  16672. //2.3====================================== Power.Active.Import =========================================
  16673. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16674. {
  16675. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16676. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16677. {
  16678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16679. {
  16680. tempIndex = ((gun_index==2) ? 1: 0);
  16681. }
  16682. else
  16683. {
  16684. tempIndex = gun_index;
  16685. }
  16686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16687. {
  16688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16689. {
  16690. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16691. }
  16692. } // End for CHAdeMO_QUANTITY
  16693. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16694. }
  16695. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16696. {
  16697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16698. {
  16699. tempIndex = ((gun_index==2) ? 1: 0);
  16700. }
  16701. else
  16702. {
  16703. tempIndex = gun_index;
  16704. }
  16705. for (int index = 0; index < CCS_QUANTITY; index++)
  16706. {
  16707. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16708. {
  16709. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16710. }
  16711. } // END for CCS_QUANTITY
  16712. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16713. }
  16714. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16715. {
  16716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16717. {
  16718. tempIndex = ((gun_index==2) ? 1: 0);
  16719. }
  16720. else
  16721. {
  16722. tempIndex = gun_index;
  16723. }
  16724. for (int index = 0; index < GB_QUANTITY; index++)
  16725. {
  16726. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16727. {
  16728. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16729. }
  16730. }// END for GB_QUANTITY
  16731. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16732. }
  16733. else if(gunType[gun_index] == GUN_TYPE_DO)
  16734. {
  16735. tempIndex = gun_index;
  16736. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16737. {
  16738. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16739. {
  16740. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16741. }
  16742. }
  16743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16744. }
  16745. else
  16746. {
  16747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16748. {
  16749. tempIndex = 2;
  16750. }
  16751. else
  16752. {
  16753. tempIndex = gun_index;
  16754. }
  16755. for (int index = 0; index < AC_QUANTITY; index++)
  16756. {
  16757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16758. {
  16759. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16760. }
  16761. } // END for AC_QUANTITY
  16762. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16763. }
  16764. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16765. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16766. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16767. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16768. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16770. }
  16771. //2.4====================================== Voltage L1 ====================================================
  16772. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16773. {
  16774. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16775. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16776. {
  16777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16778. {
  16779. tempIndex = ((gun_index==2) ? 1: 0);
  16780. }
  16781. else
  16782. {
  16783. tempIndex = gun_index;
  16784. }
  16785. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16786. {
  16787. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16788. {
  16789. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16790. }
  16791. } // END OF FOR CHAdeMO_QUANTITY
  16792. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16793. }
  16794. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16795. {
  16796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16797. {
  16798. tempIndex = ((gun_index==2) ? 1: 0);
  16799. }
  16800. else
  16801. {
  16802. tempIndex = gun_index;
  16803. }
  16804. for (int index = 0; index < CCS_QUANTITY; index++)
  16805. {
  16806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16807. {
  16808. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16809. }
  16810. } // END OF FOR CCS_QUANTITY
  16811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16812. }
  16813. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16814. {
  16815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16816. {
  16817. tempIndex = ((gun_index==2) ? 1: 0);
  16818. }
  16819. else
  16820. {
  16821. tempIndex = gun_index;
  16822. }
  16823. for (int index = 0; index < GB_QUANTITY; index++)
  16824. {
  16825. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16826. {
  16827. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16828. }
  16829. } // END OF FOR GB_QUANTITY
  16830. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16831. }
  16832. else if(gunType[gun_index] == GUN_TYPE_DO)
  16833. {
  16834. tempIndex = gun_index;
  16835. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16836. {
  16837. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16838. {
  16839. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16840. }
  16841. }
  16842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16843. }
  16844. else
  16845. {
  16846. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16847. {
  16848. tempIndex = 2;
  16849. }
  16850. else
  16851. {
  16852. tempIndex = gun_index;
  16853. }
  16854. for (int index = 0; index < AC_QUANTITY; index++)
  16855. {
  16856. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16857. {
  16858. 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
  16859. }
  16860. } // END OF FOR AC_QUANTITY
  16861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16862. }
  16863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16864. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16866. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16867. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16868. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16869. }
  16870. //2.5============================================== End SoC =========================================================
  16871. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16872. {
  16873. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16874. 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))
  16875. {
  16876. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16877. {
  16878. tempIndex = ((gun_index==2) ? 1: 0);
  16879. }
  16880. else
  16881. {
  16882. tempIndex = gun_index;
  16883. }
  16884. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16885. {
  16886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16887. {
  16888. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16889. {
  16890. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16891. }
  16892. }
  16893. }
  16894. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16895. {
  16896. for (int index = 0; index < CCS_QUANTITY; index++)
  16897. {
  16898. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16899. {
  16900. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16901. }
  16902. }
  16903. }
  16904. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16905. {
  16906. for (int index = 0; index < GB_QUANTITY; index++)
  16907. {
  16908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16909. {
  16910. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16911. }
  16912. }
  16913. }
  16914. else if(gunType[gun_index] == GUN_TYPE_DO)
  16915. {
  16916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16917. {
  16918. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16919. {
  16920. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16921. }
  16922. }
  16923. }
  16924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16925. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16927. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16928. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16929. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16930. } // END FOR DC CASE
  16931. }
  16932. //2.6====================================== Current.Import L2 ==============================================
  16933. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16934. {
  16935. // AC 3 phase L2 current
  16936. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16937. {
  16938. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16939. {
  16940. tempIndex = 2;
  16941. }
  16942. else
  16943. {
  16944. tempIndex = gun_index;
  16945. }
  16946. for (int index = 0; index < AC_QUANTITY; index++)
  16947. {
  16948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16949. {
  16950. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16951. }
  16952. }// End of for AC_QUANTITY
  16953. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16954. }
  16955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16960. }
  16961. //2.7====================================== Current.Import L3 ==============================================
  16962. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16963. {
  16964. // AC 3 phase L3 current
  16965. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16966. {
  16967. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16968. {
  16969. tempIndex = 2;
  16970. }
  16971. else
  16972. {
  16973. tempIndex = gun_index;
  16974. }
  16975. for (int index = 0; index < AC_QUANTITY; index++)
  16976. {
  16977. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16978. {
  16979. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16980. }
  16981. }// End of for AC_QUANTITY
  16982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16983. }
  16984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16985. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16986. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16987. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16988. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16989. }
  16990. //2.9====================================== Voltage L2 ====================================================
  16991. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16992. {
  16993. // AC 3 phase L2 volatge
  16994. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16995. {
  16996. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16997. {
  16998. tempIndex = 2;
  16999. }
  17000. else
  17001. {
  17002. tempIndex = gun_index;
  17003. }
  17004. for (int index = 0; index < AC_QUANTITY; index++)
  17005. {
  17006. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17007. {
  17008. 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
  17009. }
  17010. } // END OF FOR AC_QUANTITY
  17011. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17012. }
  17013. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17014. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17018. }
  17019. //2.10====================================== Voltage L3 ====================================================
  17020. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17021. {
  17022. // AC 3 phase L3 volatge
  17023. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17024. {
  17025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17026. {
  17027. tempIndex = 2;
  17028. }
  17029. else
  17030. {
  17031. tempIndex = gun_index;
  17032. }
  17033. for (int index = 0; index < AC_QUANTITY; index++)
  17034. {
  17035. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17036. {
  17037. 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
  17038. }
  17039. } // END OF FOR AC_QUANTITY
  17040. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17041. }
  17042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17043. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17044. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17045. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17046. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17047. }
  17048. //====================== Start SoC ================================
  17049. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17050. {
  17051. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17052. 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))
  17053. {
  17054. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17055. {
  17056. tempIndex = ((gun_index==2) ? 1: 0);
  17057. }
  17058. else
  17059. {
  17060. tempIndex = gun_index;
  17061. }
  17062. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17063. {
  17064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17065. {
  17066. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17067. {
  17068. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17069. }
  17070. }
  17071. }
  17072. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17073. {
  17074. for (int index = 0; index < CCS_QUANTITY; index++)
  17075. {
  17076. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17077. {
  17078. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17079. }
  17080. }
  17081. }
  17082. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17083. {
  17084. for (int index = 0; index < GB_QUANTITY; index++)
  17085. {
  17086. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17087. {
  17088. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17089. }
  17090. }
  17091. }
  17092. else if(gunType[gun_index] == GUN_TYPE_DO)
  17093. {
  17094. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17095. {
  17096. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17097. {
  17098. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17099. }
  17100. }
  17101. }
  17102. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17103. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17108. } // END FOR DC CASE
  17109. }
  17110. //======================================== Message create ==============================================
  17111. json_object *StopTransaction = json_object_new_object();
  17112. json_object *transactionDatas = json_object_new_array();
  17113. json_object *sampledValues = json_object_new_array();
  17114. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17115. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17116. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17117. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17118. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17119. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17120. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17121. {
  17122. json_object *transactionData = json_object_new_object();
  17123. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17124. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17125. {
  17126. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17127. {
  17128. json_object *sampledValue = json_object_new_object();
  17129. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17130. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17131. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17132. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17133. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17134. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17135. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17136. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17137. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17138. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17139. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17140. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17141. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17142. json_object_array_add(sampledValues, sampledValue);
  17143. }
  17144. }
  17145. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17146. json_object_array_add(transactionDatas, transactionData);
  17147. }
  17148. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17149. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17150. ,MESSAGE_TYPE_CALL
  17151. ,guid
  17152. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17153. json_object_put(StopTransaction);
  17154. // Check File "TempStopTransaction" Exist
  17155. if((access(TempStopTransaction,F_OK))!=-1)
  17156. {
  17157. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17158. fclose(fopen(TempStopTransaction, "w"));
  17159. }
  17160. else
  17161. {
  17162. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17163. FILE *log = fopen(TempStopTransaction, "w+");
  17164. if(log == NULL)
  17165. {
  17166. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17167. return ;
  17168. }
  17169. else
  17170. {
  17171. fclose(log);
  17172. }
  17173. }
  17174. //Add TempStopTransaction | Update TempStopTransaction
  17175. // open file for writing
  17176. FILE *outfile;
  17177. outfile = fopen (TempStopTransaction, "a");
  17178. //DEBUG_INFO("data = %s\n", queuedata);
  17179. fputs(queuedata, outfile);
  17180. fputs("\n", outfile);
  17181. fclose (outfile);
  17182. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17183. }
  17184. void checkTempStopTransaction(int gun_index)
  17185. {
  17186. FILE *fptr1;
  17187. char ch;
  17188. char str[QUEUE_MESSAGE_LENGTH]={0};
  17189. char guid[37]={0};
  17190. char tempdata[65]={0};
  17191. char connectorStr[2]={0};
  17192. char TempStopTransaction[256];
  17193. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17194. fptr1 = fopen(TempStopTransaction, "r");
  17195. //TempStopTransaction格式: 槍號,StopTransaction封包
  17196. if (!fptr1)
  17197. {
  17198. //printf(" File not found or unable to open the input file!!\n");
  17199. return ;
  17200. }
  17201. ch=fgetc(fptr1);
  17202. //printf(" Now the content of the file %s is : \n",fname);
  17203. rewind(fptr1);
  17204. if(ch!=EOF)
  17205. {
  17206. // copy all contents to the temporary file except the specific line
  17207. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17208. {
  17209. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17210. if(str[0]=='\0')
  17211. {
  17212. break;
  17213. }
  17214. //TempStopTransaction格式: 槍號,StopTransaction封包
  17215. strncpy(connectorStr, str, 1);
  17216. if(atoi(connectorStr) != (gun_index+1))
  17217. {
  17218. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17219. fclose(fptr1);
  17220. return ;
  17221. }
  17222. //random_uuid(guid);
  17223. strncpy(guid, str+6, 36); //copy guid
  17224. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17225. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17226. {
  17227. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17228. }
  17229. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17230. OCPP_insert_transaction_msg(NO, str);
  17231. memset(str,0,ARRAY_SIZE(str));
  17232. }
  17233. }
  17234. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17235. fclose(fptr1);
  17236. remove(TempStopTransaction); // remove the original file
  17237. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17238. }
  17239. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17240. {
  17241. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17242. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17243. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17244. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17245. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17246. }
  17247. int GetWebSocketPingInterval(void)
  17248. {
  17249. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17250. }
  17251. int GetServerSign(void)
  17252. {
  17253. return server_sign;
  17254. }
  17255. uint8_t GetOcppSecurityProfile()
  17256. {
  17257. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17258. }
  17259. void GetOcppChargerBoxId(uint8_t *data)
  17260. {
  17261. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17262. }
  17263. void GetOcppSecurityPassword(uint8_t *data)
  17264. {
  17265. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17266. }
  17267. void SetOcppVersion(uint8_t *version)
  17268. {
  17269. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17270. DEBUG_INFO("ocpp version: %s\n", version);
  17271. if(strstr((char*)version, "ocpp1.6") != NULL)
  17272. {
  17273. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17274. }
  17275. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17276. {
  17277. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17278. system("pkill OcppBackend");
  17279. }
  17280. }
  17281. void SetServerSign(int value)
  17282. {
  17283. server_sign = value;
  17284. }
  17285. int GetBootNotificationInterval(void)
  17286. {
  17287. return BootNotificationInterval;
  17288. }
  17289. int GetInternetConn(void)
  17290. {
  17291. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17292. }
  17293. int GetBackendConnectionTimeout(void)
  17294. {
  17295. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17296. }
  17297. int isConnectorInitMode(int gun_index)
  17298. {
  17299. int tempIndex = 0;
  17300. int result = TRUE;
  17301. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17302. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17303. {
  17304. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17305. {
  17306. tempIndex = ((gun_index==2) ? 1: 0);
  17307. }
  17308. else
  17309. {
  17310. tempIndex = gun_index;
  17311. }
  17312. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17313. {
  17314. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17315. {
  17316. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17317. } //end of the same index
  17318. }//end of for CHAdeMO_QUANTITY
  17319. }
  17320. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17321. {
  17322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17323. {
  17324. tempIndex = ((gun_index==2) ? 1: 0);
  17325. }
  17326. else
  17327. {
  17328. tempIndex = gun_index;
  17329. }
  17330. for (int index = 0; index < CCS_QUANTITY; index++)
  17331. {
  17332. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17333. {
  17334. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17335. } //end of the same index
  17336. } // end of for CCS_QUANTITY
  17337. }
  17338. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17339. {
  17340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17341. {
  17342. tempIndex = ((gun_index==2) ? 1: 0);
  17343. }
  17344. else
  17345. {
  17346. tempIndex = gun_index;
  17347. }
  17348. for (int index = 0; index < GB_QUANTITY; index++)
  17349. {
  17350. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17351. {
  17352. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17353. } //end of the same index
  17354. } // end of for GB_QUANTITY
  17355. }
  17356. else if(gunType[gun_index] == GUN_TYPE_DO)
  17357. {
  17358. tempIndex = gun_index;
  17359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17360. {
  17361. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17362. {
  17363. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17364. } //end of the same index
  17365. }
  17366. }
  17367. else
  17368. {
  17369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17370. {
  17371. tempIndex = 2;
  17372. }
  17373. else
  17374. {
  17375. tempIndex = gun_index;
  17376. }
  17377. for (int index = 0; index < AC_QUANTITY; index++)
  17378. {
  17379. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17380. {
  17381. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17382. }//end of the same index
  17383. }//end of for AC_QUANTITY
  17384. }
  17385. return result;
  17386. }
  17387. void refreshProcDogTimer()
  17388. {
  17389. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17390. }
  17391. void InitialSystemValue(void)
  17392. {
  17393. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17394. locallistVersion=0;
  17395. BootNotificationInterval = 0;
  17396. authorizeRetryTimes = 0;
  17397. GunStatusInterval = 10;
  17398. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17399. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17400. //Hear Beat
  17401. HeartBeatWithNOResponse = 0;
  17402. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17403. FirstHeartBeat = 0;
  17404. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17405. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17406. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17407. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17408. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17409. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17410. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17411. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17412. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17413. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17414. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17415. //Status && ConnectorPlugIn Setting
  17416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17417. {
  17418. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17419. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17420. }
  17421. for (int index = 0; index < CCS_QUANTITY; index++)
  17422. {
  17423. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17424. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17425. }
  17426. for (int index = 0; index < GB_QUANTITY; index++)
  17427. {
  17428. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17429. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17430. }
  17431. for (int index = 0; index < AC_QUANTITY; index++)
  17432. {
  17433. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17434. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17435. }
  17436. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17437. {
  17438. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17439. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17440. }
  17441. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17442. {
  17443. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17444. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17445. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17446. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17447. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17448. }
  17449. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17450. refreshStartTimer(&clientTime.Heartbeat);
  17451. sleep(1);
  17452. }
  17453. void LWS_Send(char *str)
  17454. {
  17455. //=====================================================
  17456. // Check InternetConn 0: disconnected, 1: connected
  17457. //====================================================
  17458. if(GetOcppConnStatus() == 0)
  17459. {
  17460. DEBUG_INFO("offline now !!!\n");
  17461. return;
  17462. }
  17463. // Only disable isWebsocketSendable operation initiated by charger
  17464. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17465. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17466. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17467. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17468. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17469. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17470. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17471. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17472. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17473. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17474. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17475. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17476. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17477. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17478. {
  17479. isWebsocketSendable = 0;
  17480. }
  17481. pthread_mutex_lock(&lock_send);
  17482. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17483. sprintf((char *)SendBuffer, "%s", str);
  17484. SendBufLen = strlen(str);
  17485. pthread_mutex_unlock(&lock_send);
  17486. lws_callback_on_writable(wsi_client);
  17487. //lws_service(context, 0);
  17488. //sleep(1);
  17489. }
  17490. void LWS_SendNow(char *str)
  17491. {
  17492. //=====================================================
  17493. // Check InternetConn 0: disconnected, 1: connected
  17494. //====================================================
  17495. if(GetOcppConnStatus() == 0)
  17496. {
  17497. DEBUG_INFO("offline now !!!\n");
  17498. return;
  17499. }
  17500. // Only disable isWebsocketSendable operation initiated by charger
  17501. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17502. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17503. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17504. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17505. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17506. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17507. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17508. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17509. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17510. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17511. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17512. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17513. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17514. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17515. {
  17516. isWebsocketSendable = 0;
  17517. }
  17518. pthread_mutex_lock(&lock_send);
  17519. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17520. sprintf((char *)SendBuffer, "%s", str);
  17521. SendBufLen = strlen(str);
  17522. pthread_mutex_unlock(&lock_send);
  17523. lws_callback_on_writable(wsi_client);
  17524. lws_service(context, 0);
  17525. //sleep(1);
  17526. }