MessageHandler.c 881 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947
  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 HeartBeat Response Not Receive Counts
  82. //============================================
  83. static int HeartBeatWithNOResponse = 0;
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  97. struct ClientTime
  98. {
  99. struct timespec Heartbeat;
  100. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  101. struct timespec StartTransaction;
  102. struct timespec StopTransaction;
  103. struct timespec MeterValues[CONNECTOR_QUANTITY];
  104. struct timespec RemoteStartWait;
  105. }clientTime;
  106. typedef union
  107. {
  108. //Operations Initiated by Central System
  109. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  110. struct
  111. {
  112. //CsMsgValue[0]
  113. unsigned char StatusNotificationReq:1; //bit 0,
  114. unsigned char StatusNotificationConf:1; //bit 1,
  115. unsigned char TriggerMeterValue:1; //bit 2,
  116. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  117. unsigned char isOnCharging:1; //bit 4.
  118. unsigned char :3; //bit 5~7
  119. }bits[CONNECTOR_QUANTITY];
  120. }CpinitiateMsg;
  121. CpinitiateMsg cpinitateMsg;
  122. //GetConfiguration Array
  123. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  125. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  126. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  127. #if 0
  128. static char *ChargePointErrorCodeStr[] = {
  129. MACROSTR(ConnectorLockFailure),
  130. MACROSTR(EVCommunicationError),
  131. MACROSTR(GroundFailure),
  132. MACROSTR(HighTemperature),
  133. MACROSTR(InternalError),
  134. MACROSTR(LocalListConflict),
  135. MACROSTR(NoError),
  136. MACROSTR(OtherError),
  137. MACROSTR(OverCurrentFailure),
  138. MACROSTR(OverVoltage),
  139. MACROSTR(PowerMeterFailure),
  140. MACROSTR(PowerSwitchFailure),
  141. MACROSTR(ReaderFailure),
  142. MACROSTR(ResetFailure),
  143. MACROSTR(UnderVoltage),
  144. MACROSTR(WeakSignal)
  145. };
  146. #endif
  147. static char * ChargePointStatusStr[] = {
  148. MACROSTR(Available),
  149. MACROSTR(Preparing),
  150. MACROSTR(Charging),
  151. MACROSTR(SuspendedEVSE),
  152. MACROSTR(SuspendedEV),
  153. MACROSTR(Finishing),
  154. MACROSTR(Reserved),
  155. MACROSTR(Unavailable),
  156. MACROSTR(Faulted)
  157. };
  158. static char *RegistrationStatusStr[] = {
  159. MACROSTR(Accepted),
  160. MACROSTR(Pending),
  161. MACROSTR(Rejected)
  162. };
  163. static char *AvailabilityTypeStr[] = {
  164. MACROSTR(Inoperative),
  165. MACROSTR(Operative)
  166. };
  167. static char *AvailabilityStatusStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Scheduled)
  171. };
  172. static char *ConfigurationStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(RebootRequired),
  176. MACROSTR(NotSupported)
  177. };
  178. static char *ClearCacheStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected)
  181. };
  182. static char *ChargingProfilePurposeTypeStr[] = {
  183. MACROSTR(ChargePointMaxProfile),
  184. MACROSTR(TxDefaultProfile),
  185. MACROSTR(TxProfile)
  186. };
  187. static char *ChargingProfileStatusStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(NotSupported)
  191. };
  192. static char *ClearChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Unknown)
  195. };
  196. static char *GetCompositeScheduleStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Rejected)
  199. };
  200. static char *UpdateTypeStr[] = {
  201. MACROSTR(Differential),
  202. MACROSTR(Full)
  203. };
  204. static char *UpdateStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Failed),
  207. MACROSTR(NotSupported),
  208. MACROSTR(VersionMismatch)
  209. };
  210. static char *RemoteStartStopStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Rejected)
  213. };
  214. static char *ReservationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Faulted),
  217. MACROSTR(Occupied),
  218. MACROSTR(Rejected),
  219. MACROSTR(Unavailable)
  220. };
  221. static char *ResetTypeStr[] = {
  222. MACROSTR(Hard),
  223. MACROSTR(Soft)
  224. };
  225. static char *ResetStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Rejected)
  228. };
  229. static char * DiagnosticsStatusStr[] = {
  230. MACROSTR(Idle),
  231. MACROSTR(Uploaded),
  232. MACROSTR(UploadFailed),
  233. MACROSTR(Uploading)
  234. };
  235. static char * FirmwareStatusStr[] = {
  236. MACROSTR(Downloaded),
  237. MACROSTR(DownloadFailed),
  238. MACROSTR(Downloading),
  239. MACROSTR(Idle),
  240. MACROSTR(InstallationFailed),
  241. MACROSTR(Installing),
  242. MACROSTR(Installed)
  243. };
  244. static char * MessageTriggerStr[] = {
  245. MACROSTR(BootNotification),
  246. MACROSTR(DiagnosticsStatusNotification),
  247. MACROSTR(FirmwareStatusNotification),
  248. MACROSTR(Heartbeat),
  249. MACROSTR(MeterValues),
  250. MACROSTR(StatusNotification)
  251. };
  252. static char * TriggerMessageStatusStr[] = {
  253. MACROSTR(Accepted),
  254. MACROSTR(Rejected),
  255. MACROSTR(NotImplemented)
  256. };
  257. static char * UnlockStatusStr[] = {
  258. MACROSTR(Unlocked),
  259. MACROSTR(UnlockFailed),
  260. MACROSTR(NotSupported)
  261. };
  262. #if 0
  263. static char * StopTransactionReasonStr[] = {
  264. MACROSTR(EmergencyStop),
  265. MACROSTR(EVDisconnected),
  266. MACROSTR(HardReset),
  267. MACROSTR(Local),
  268. MACROSTR(Other),
  269. MACROSTR(PowerLoss),
  270. MACROSTR(Reboot),
  271. MACROSTR(Remote),
  272. MACROSTR(SoftReset),
  273. MACROSTR(UnlockCommand),
  274. MACROSTR(DeAuthorized)
  275. };
  276. #endif
  277. static char * CancelReservationStatusStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(Rejected)
  280. };
  281. static char * ReadingContextStr[] = {
  282. MACROSTR(Interruption.Begin),
  283. MACROSTR(Interruption.End),
  284. MACROSTR(Other),
  285. MACROSTR(Sample.Clock),
  286. MACROSTR(Sample.Periodic),
  287. MACROSTR(Transaction.Begin),
  288. MACROSTR(Transaction.End),
  289. MACROSTR(Trigger)
  290. };
  291. static char * ValueFormatStr[] = {
  292. MACROSTR(Raw),
  293. MACROSTR(SignedData)
  294. };
  295. static char * MeasurandStr[] = {
  296. MACROSTR(Current.Export),
  297. MACROSTR(Current.Import),
  298. MACROSTR(Current.Offered),
  299. MACROSTR(Energy.Active.Export.Register),
  300. MACROSTR(Energy.Active.Import.Register),
  301. MACROSTR(Energy.Reactive.Export.Register),
  302. MACROSTR(Energy.Reactive.Import.Register),
  303. MACROSTR(Energy.Active.Export.Interval),
  304. MACROSTR(Energy.Active.Import.Interval),
  305. MACROSTR(Energy.Reactive.Export.Interval),
  306. MACROSTR(Energy.Reactive.Import.Interval),
  307. MACROSTR(Frequency),
  308. MACROSTR(Power.Active.Export),
  309. MACROSTR(Power.Active.Import),
  310. MACROSTR(Power.Factor),
  311. MACROSTR(Power.Offered),
  312. MACROSTR(Power.Reactive.ExportMACROSTR),
  313. MACROSTR(Power.Reactive.Import),
  314. MACROSTR(RPM),
  315. MACROSTR(SoC),
  316. MACROSTR(Temperature),
  317. MACROSTR(Voltage)
  318. };
  319. static char * LocationStr[] = {
  320. MACROSTR(Body),
  321. MACROSTR(Cable),
  322. MACROSTR(EV),
  323. MACROSTR(Inlet),
  324. MACROSTR(Outlet)
  325. };
  326. static char * PhaseStr[] = {
  327. MACROSTR(L1),
  328. MACROSTR(L2),
  329. MACROSTR(L3),
  330. MACROSTR(N),
  331. MACROSTR(L1-N),
  332. MACROSTR(L2-N),
  333. MACROSTR(L3-N),
  334. MACROSTR(L1-L2),
  335. MACROSTR(L2-L3),
  336. MACROSTR(L3-L1)
  337. };
  338. static char * UnitOfMeasureStr[] = {
  339. MACROSTR(Wh),
  340. MACROSTR(kWh),
  341. MACROSTR(varh),
  342. MACROSTR(kvarh),
  343. MACROSTR(W),
  344. MACROSTR(kW),
  345. MACROSTR(VA),
  346. MACROSTR(kVA),
  347. MACROSTR(var),
  348. MACROSTR(kvar),
  349. MACROSTR(A),
  350. MACROSTR(V),
  351. MACROSTR(Celsius),
  352. MACROSTR(Fahrenheit),
  353. MACROSTR(K),
  354. MACROSTR(Percent)
  355. };
  356. //=========================================
  357. // Save configuration
  358. //=========================================
  359. int runShellCmd(const char*cmd)
  360. {
  361. int result = FAIL;
  362. char buf[256];
  363. FILE *fp;
  364. fp = popen(cmd, "r");
  365. if(fp != NULL)
  366. {
  367. while(fgets(buf, sizeof(buf), fp) != NULL)
  368. {
  369. DEBUG_INFO("%s\n", buf);
  370. }
  371. result = PASS;
  372. }
  373. pclose(fp);
  374. return result;
  375. }
  376. int StoreUsrConfigData(struct SysConfigData *UsrData)
  377. {
  378. int result = PASS;
  379. int fd,wrd;
  380. unsigned int i,Chk;
  381. unsigned char *ptr, *BufTmp;
  382. int MtdBlockSize = 0x300000;
  383. Chk=0;
  384. ptr=(unsigned char *)UsrData;
  385. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  386. {
  387. memset(BufTmp,0,MtdBlockSize);
  388. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  389. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  390. Chk+=*(BufTmp+i);
  391. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  392. // Output configuration to file.
  393. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  394. if (fd < 0)
  395. {
  396. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  397. free(BufTmp);
  398. return 0;
  399. }
  400. wrd=write(fd, BufTmp, MtdBlockSize);
  401. close(fd);
  402. if(wrd<MtdBlockSize)
  403. {
  404. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  405. free(BufTmp);
  406. return 0;
  407. }
  408. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  409. DEBUG_INFO("Erase /dev/mtd10.\n");
  410. runShellCmd("flash_erase /dev/mtd10 0 0");
  411. DEBUG_INFO("Write /dev/mtd10.\n");
  412. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  413. DEBUG_INFO("Erase /dev/mtd11.\n");
  414. runShellCmd("flash_erase /dev/mtd11 0 0");
  415. DEBUG_INFO("Write /dev/mtd11.\n");
  416. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  417. system("rm -f /mnt/EvseConfig.bin");
  418. DEBUG_INFO("EvseConfig write to flash OK\n");
  419. }
  420. else
  421. {
  422. DEBUG_ERROR("alloc BlockSize NG\r\n");
  423. result = FAIL;
  424. }
  425. if(BufTmp!=NULL)
  426. free(BufTmp);
  427. return result;
  428. }
  429. //=========================================
  430. // Sqlite3 related function
  431. //=========================================
  432. static int selectSqlCount = 0;
  433. static int callback(void *data, int argc, char **argv, char **azColName){
  434. int i;
  435. //printf("%s: ", (const char*)data);
  436. selectSqlCount = argc;
  437. for(i = 0; i<argc; i++){
  438. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  439. }
  440. //printf("\n");
  441. return 0;
  442. }
  443. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  444. //int i;
  445. //printf("%s:\n", (const char*)data);
  446. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  447. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  448. return 0;
  449. }
  450. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  451. //printf("%s:\n", (const char*)data);
  452. //idTag
  453. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  455. //parentIdTag
  456. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  457. //expir_date
  458. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  459. //status
  460. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  461. //version
  462. if(columenCount > 5)
  463. idTagQuery.listVersionInt = atoi(columnValue[5]);
  464. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  465. return 0;
  466. }
  467. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  468. {
  469. // localversion = argv[5] ? atoi(argv[5]) : 0;
  470. // printf("localversion=%d\n", localversion);
  471. return 0;
  472. }
  473. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  474. {
  475. for (int i = 0; i < n_columns; i++)
  476. {
  477. DEBUG_INFO("%s\t", col_values[i]);
  478. }
  479. DEBUG_INFO("\n");
  480. return 0;
  481. }
  482. int OCPP_cleanLocalCache()
  483. {
  484. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  485. char *errMsg = 0;
  486. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  487. if (SQLITE_OK != rc)
  488. {
  489. DEBUG_INFO("SQL error: %s\n",errMsg);
  490. return FALSE;
  491. }
  492. return TRUE;
  493. }
  494. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  495. {
  496. int isSuccess = TRUE;
  497. int ret = 0;
  498. //const char* data = "Callback function called";
  499. char sql[300];
  500. char zErrMsg[200];
  501. memset(sql, 0, 300);
  502. memset(zErrMsg, 0, 200);
  503. 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);
  504. //* Execute SQL statement */
  505. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  506. if( ret != SQLITE_OK )
  507. {
  508. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  509. isSuccess = FALSE;
  510. }
  511. return isSuccess;
  512. }
  513. void OCPP_getIdTagFromLocalCache(char idTag[])
  514. {
  515. int rc = 0;
  516. char sql[100];
  517. char zErrMsg[100];
  518. memset(sql, 0, 100);
  519. memset(zErrMsg, 0, 100);
  520. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  521. memset(&idTagQuery, 0, sizeof(idTagQuery));
  522. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  523. /* Execute SQL statement */
  524. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  525. if( rc != SQLITE_OK )
  526. {
  527. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  528. }
  529. }
  530. void OCPP_getListVerion()
  531. {
  532. int rc = 0;
  533. // const char* data = "Callback function called";
  534. char sql[100];
  535. char zErrMsg[100];
  536. memset(sql, 0, 100);
  537. memset(zErrMsg, 0, 100);
  538. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  539. /* Execute SQL statement */
  540. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  541. if( rc != SQLITE_OK )
  542. {
  543. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  544. }
  545. }
  546. void OCPP_get_TableAuthlocalAllData(void)
  547. {
  548. int rc = 0;
  549. char sql[100];
  550. char zErrMsg[100];
  551. memset(sql, 0, 100);
  552. memset(zErrMsg, 0, 100);
  553. sprintf(sql,"select * from ocpp_auth_local ");
  554. /* Execute SQL statement */
  555. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  556. if( rc != SQLITE_OK )
  557. {
  558. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  559. }
  560. //return ver;
  561. }
  562. int OCPP_cleanLocalList()
  563. {
  564. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  565. char *errMsg = 0;
  566. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  567. if (SQLITE_OK != rc)
  568. {
  569. DEBUG_INFO("%s\n",errMsg);
  570. return FALSE;
  571. }
  572. return TRUE;
  573. }
  574. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  575. {
  576. int isSuccess = FALSE;
  577. int ret = 0;
  578. //const char* data = "Callback function called";
  579. char sql[300];
  580. char zErrMsg[200];
  581. memset(sql, 0, 300);
  582. memset(zErrMsg, 0, 200);
  583. 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);
  584. //* Execute SQL statement */
  585. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  586. if( ret != SQLITE_OK )
  587. {
  588. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  589. return isSuccess;
  590. }
  591. memset(sql, 0, 300);
  592. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  593. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  594. if( ret != SQLITE_OK )
  595. {
  596. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  597. return isSuccess;
  598. }
  599. isSuccess = TRUE;
  600. return isSuccess;
  601. }
  602. void OCPP_getIdTagFromLocalList(char idTag[])
  603. {
  604. int rc = 0;
  605. // const char* data = "Callback function called";
  606. char sql[100];
  607. char zErrMsg[100];
  608. memset(sql, 0, 100);
  609. memset(zErrMsg, 0, 100);
  610. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  611. memset(&idTagQuery, 0, sizeof(idTagQuery));
  612. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  613. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  614. /* Execute SQL statement */
  615. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  616. if( rc != SQLITE_OK )
  617. {
  618. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  619. }
  620. //return ver;
  621. }
  622. void OCPP_deleteIdTagFromLocalList(char idTag[])
  623. {
  624. //int ver = 0;
  625. //int isSuccess = FALSE;
  626. int rc = 0;
  627. char sql[100];
  628. char zErrMsg[100];
  629. memset(sql, 0, 100);
  630. memset(zErrMsg, 0, 100);
  631. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  632. //* Execute SQL statement */
  633. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  634. if( rc != SQLITE_OK )
  635. {
  636. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  637. }
  638. }
  639. int getCurrentYear()
  640. {
  641. int result = 0;
  642. time_t CurrentTime;
  643. struct tm *tm;
  644. CurrentTime = time(NULL);
  645. tm=localtime(&CurrentTime);
  646. result = (tm->tm_year + 1900);
  647. return result;
  648. }
  649. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  650. {
  651. int result = PASS;
  652. char* errMsg = NULL;
  653. char sqlStr[8192];
  654. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  655. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  656. {
  657. result = FAIL;
  658. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  659. }
  660. 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));
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  665. }
  666. return result;
  667. }
  668. //==========================================
  669. // Check time passed since today
  670. //==========================================
  671. long long DiffTimebWithNow(struct timeb ST)
  672. {
  673. //return milli-second
  674. struct timeb ET;
  675. long long StartTime,StopTime;
  676. ftime(&ET);
  677. StartTime=(long long)ST.time;
  678. StopTime=(long long)ET.time;
  679. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  680. }
  681. int getTimePassSinceToday(uint8_t gun_index)
  682. {
  683. int result = -1;
  684. static time_t lastTime[4];
  685. time_t t;
  686. struct tm *tmStartToday;
  687. struct timeb tbStartToday;
  688. t=time(NULL);
  689. if(difftime(t, lastTime[gun_index])>0)
  690. {
  691. tmStartToday=localtime(&t);
  692. tmStartToday->tm_hour = 0;
  693. tmStartToday->tm_min = 0;
  694. tmStartToday->tm_sec = 0;
  695. tbStartToday.time = mktime(tmStartToday);
  696. tbStartToday.millitm = 0;
  697. result = DiffTimebWithNow(tbStartToday)/1000;
  698. lastTime[gun_index] = t;
  699. }
  700. return result;
  701. }
  702. void getNowDatetime(uint8_t *data)
  703. {
  704. time_t t = time(NULL);
  705. struct tm tm = *localtime(&t);
  706. 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);
  707. }
  708. int syncDateTimeRTC(uint8_t *data)
  709. {
  710. struct ParsingResult
  711. {
  712. int result;
  713. int scanedElement;
  714. int year;
  715. int month;
  716. int mday;
  717. int hour;
  718. int min;
  719. int sec;
  720. int tz_hour;
  721. int tz_min;
  722. float minSec;
  723. }result;
  724. struct tm tmOrg;
  725. struct tm *tmTarget;
  726. struct timeb tbTarget;
  727. char buf[128];
  728. memset(&result, 0x00, sizeof(struct ParsingResult));
  729. result.result = PASS;
  730. if(strstr((char*)data, ".") != NULL)
  731. {
  732. // Original data with mini second
  733. if(strstr((char*)data, "Z") != NULL)
  734. {
  735. // Original data with Z
  736. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  737. &result.year,
  738. &result.month,
  739. &result.mday,
  740. &result.hour,
  741. &result.min,
  742. &result.sec,
  743. &result.minSec);
  744. }
  745. else
  746. {
  747. // Original data without Z
  748. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  749. &result.year,
  750. &result.month,
  751. &result.mday,
  752. &result.hour,
  753. &result.min,
  754. &result.sec,
  755. &result.minSec,
  756. &result.tz_hour,
  757. &result.tz_min);
  758. }
  759. }
  760. else
  761. {
  762. // Original data without mini second
  763. if(strstr((char*)data, "Z") != NULL)
  764. {
  765. // Original data with Z
  766. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  767. &result.year,
  768. &result.month,
  769. &result.mday,
  770. &result.hour,
  771. &result.min,
  772. &result.sec);
  773. }
  774. else
  775. {
  776. // Original data without Z
  777. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  778. &result.year,
  779. &result.month,
  780. &result.mday,
  781. &result.hour,
  782. &result.min,
  783. &result.sec,
  784. &result.tz_hour,
  785. &result.tz_min);
  786. }
  787. }
  788. tmOrg.tm_year = result.year - 1900;
  789. tmOrg.tm_mon = result.month - 1;
  790. tmOrg.tm_mday = result.mday;
  791. tmOrg.tm_hour = result.hour;
  792. tmOrg.tm_min = result.min;
  793. tmOrg.tm_sec = result.sec;
  794. tmOrg.tm_gmtoff = 0;
  795. tbTarget.time = mktime(&tmOrg);
  796. tbTarget.timezone = 0;
  797. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  798. tmTarget = gmtime(&tbTarget.time);
  799. 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);
  800. //DEBUG_INFO(" org date time: %s\n", data);
  801. //DEBUG_INFO("parse date time: %s\n", buf);
  802. system(buf);
  803. system("/sbin/hwclock -w --systohc");
  804. if(result.scanedElement < 6)
  805. result.result = FAIL;
  806. return result.result;
  807. }
  808. //==========================================
  809. // GetCompositeSchedule logic related function
  810. //==========================================
  811. int DiffTimebSec(struct timeb ST, struct timeb ET)
  812. {
  813. //return milli-second
  814. unsigned int StartTime,StopTime;
  815. StartTime=(unsigned int)ST.time;
  816. StopTime=(unsigned int)ET.time;
  817. return (StopTime-StartTime);
  818. }
  819. int DiffTimebWithNowSec(struct timeb ST)
  820. {
  821. //return milli-second
  822. struct timeb ET;
  823. unsigned int StartTime,StopTime;
  824. ftime(&ET);
  825. StartTime=(unsigned int)ST.time;
  826. StopTime=(unsigned int)ET.time;
  827. return (StopTime-StartTime);
  828. }
  829. int getStartStop(uint8_t *start, uint8_t *stop)
  830. {
  831. int result = -1;
  832. struct tm tmStart;
  833. struct timeb tbStart;
  834. struct tm tmStop;
  835. struct timeb tbStop;
  836. 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) &&
  837. (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))
  838. {
  839. //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);
  840. //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);
  841. tmStart.tm_year -= 1900;
  842. tmStart.tm_mon -= 1;
  843. tbStart.time = mktime(&tmStart);
  844. tbStart.millitm = 0;
  845. tmStop.tm_year -= 1900;
  846. tmStop.tm_mon -= 1;
  847. tbStop.time = mktime(&tmStop);
  848. tbStop.millitm = 0;
  849. result = DiffTimebSec(tbStart, tbStop);
  850. //DEBUG_INFO("getStartStop(): %d\n", result);
  851. }
  852. else
  853. {
  854. DEBUG_WARN("Start or stop date parsing error.\r\n");
  855. }
  856. return result;
  857. }
  858. int isOvertNow(uint8_t *start)
  859. {
  860. int result = NO;
  861. struct ParsingResult
  862. {
  863. int result;
  864. int scanedElement;
  865. int year;
  866. int month;
  867. int mday;
  868. int hour;
  869. int min;
  870. int sec;
  871. int tz_hour;
  872. int tz_min;
  873. float minSec;
  874. }parsingResult;
  875. struct tm tmStart;
  876. struct timeb tbStart;
  877. if(strstr((char*)start, ".") != NULL)
  878. {
  879. // Original data with mini second
  880. if(strstr((char*)start, "Z") != NULL)
  881. {
  882. // Original data with Z
  883. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  884. &parsingResult.year,
  885. &parsingResult.month,
  886. &parsingResult.mday,
  887. &parsingResult.hour,
  888. &parsingResult.min,
  889. &parsingResult.sec,
  890. &parsingResult.minSec);
  891. }
  892. else
  893. {
  894. // Original data without Z
  895. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  896. &parsingResult.year,
  897. &parsingResult.month,
  898. &parsingResult.mday,
  899. &parsingResult.hour,
  900. &parsingResult.min,
  901. &parsingResult.sec,
  902. &parsingResult.minSec,
  903. &parsingResult.tz_hour,
  904. &parsingResult.tz_min);
  905. }
  906. }
  907. else
  908. {
  909. // Original data without mini second
  910. if(strstr((char*)start, "Z") != NULL)
  911. {
  912. // Original data with Z
  913. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  914. &parsingResult.year,
  915. &parsingResult.month,
  916. &parsingResult.mday,
  917. &parsingResult.hour,
  918. &parsingResult.min,
  919. &parsingResult.sec);
  920. }
  921. else
  922. {
  923. // Original data without Z
  924. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  925. &parsingResult.year,
  926. &parsingResult.month,
  927. &parsingResult.mday,
  928. &parsingResult.hour,
  929. &parsingResult.min,
  930. &parsingResult.sec,
  931. &parsingResult.tz_hour,
  932. &parsingResult.tz_min);
  933. }
  934. }
  935. if(parsingResult.scanedElement >= 6)
  936. {
  937. tmStart.tm_year = parsingResult.year - 1900;
  938. tmStart.tm_mon = parsingResult.month - 1;
  939. tmStart.tm_mday = parsingResult.mday;
  940. tmStart.tm_hour = parsingResult.hour;
  941. tmStart.tm_min = parsingResult.min;
  942. tmStart.tm_sec = parsingResult.sec;
  943. tmStart.tm_gmtoff = 0;
  944. tbStart.time = mktime(&tmStart);
  945. tbStart.timezone = 0;
  946. tbStart.millitm = 0;
  947. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  948. if(DiffTimebWithNowSec(tbStart) <= 0)
  949. result = NO;
  950. else
  951. result = YES;
  952. }
  953. else
  954. {
  955. DEBUG_WARN("Start date parsing error.\n");
  956. }
  957. return result;
  958. }
  959. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  960. {
  961. int result = -1;
  962. struct tm tmStart;
  963. struct timeb tbStart;
  964. struct tm tmStop;
  965. struct timeb tbStop;
  966. 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) &&
  967. (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))
  968. {
  969. tmStart.tm_year -= 1900;
  970. tmStart.tm_mon -= 1;
  971. tbStart.time = mktime(&tmStart);
  972. tbStart.millitm = 0;
  973. tmStop.tm_year -= 1900;
  974. tmStop.tm_mon -= 1;
  975. tbStop.time = mktime(&tmStop);
  976. tbStop.millitm = 0;
  977. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  978. }
  979. return result;
  980. }
  981. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  982. {
  983. FILE *fp;
  984. char profileFileName[128];
  985. char *line = NULL;
  986. size_t len = 0;
  987. time_t CurrentTime;
  988. struct tm *tmComposite;
  989. struct StructChargingProfile maxProfile;
  990. uint8_t limitMax=0;
  991. int compositePeriodIdx = 0;
  992. CurrentTime = time(NULL);
  993. tmComposite=localtime(&CurrentTime);
  994. 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);
  995. if(isUnitA)
  996. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  997. else
  998. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  999. compositeProfile->ChargingSchedule.Duration = durationReq;
  1000. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1001. {
  1002. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1004. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1005. }
  1006. compositeProfile->ChargingProfileId = 0;
  1007. compositeProfile->StackLevel = 99 ;
  1008. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1009. maxProfile.ChargingProfileId = -1;
  1010. maxProfile.ChargingSchedule.Duration = -1;
  1011. system("rm -f /tmp/*.json");
  1012. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1013. // Search max profile
  1014. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1015. if((access(profileFileName, F_OK))!=-1)
  1016. {
  1017. fp = fopen(profileFileName, "r");
  1018. while(getline(&line, &len, fp) != -1)
  1019. {
  1020. json_object *obj = NULL;
  1021. obj = json_tokener_parse(line);
  1022. if(is_error(obj))
  1023. {
  1024. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1025. }
  1026. else
  1027. {
  1028. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1029. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1030. )
  1031. {
  1032. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1033. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1034. )
  1035. {
  1036. struct tm tmFrom, tmTo;
  1037. struct timeb tbFrom, tbTo;
  1038. 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) &&
  1039. (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))
  1040. {
  1041. tmFrom.tm_year -= 1900;
  1042. tmFrom.tm_mon -= 1;
  1043. tbFrom.time = mktime(&tmFrom);
  1044. tmTo.tm_year -= 1900;
  1045. tmTo.tm_mon -= 1;
  1046. tbTo.time = mktime(&tmTo);
  1047. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1048. {
  1049. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1050. {
  1051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1053. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1054. }
  1055. maxProfile.ChargingProfileId = -1;
  1056. maxProfile.StackLevel = -1;
  1057. if(maxProfile.ChargingProfileId == -1)
  1058. DEBUG_INFO("MaxProfile found.\n");
  1059. else
  1060. DEBUG_INFO("MaxProfile updated.\n");
  1061. // Required item
  1062. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1063. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1064. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1065. if(isUnitA)
  1066. {
  1067. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1068. 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++)
  1069. {
  1070. 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"));
  1071. 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?
  1072. 3:
  1073. 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")));
  1074. 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")));
  1075. }
  1076. }
  1077. else
  1078. {
  1079. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1080. 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++)
  1081. {
  1082. 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"));
  1083. 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?
  1084. 3:
  1085. 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")));
  1086. 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));
  1087. }
  1088. }
  1089. // Optional item
  1090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1091. {
  1092. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1093. }
  1094. else
  1095. {
  1096. sprintf((char*)maxProfile.ValidFrom, " ");
  1097. }
  1098. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1099. {
  1100. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1101. }
  1102. else
  1103. {
  1104. sprintf((char*)maxProfile.ValidTo, " ");
  1105. }
  1106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1107. {
  1108. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1109. }
  1110. else
  1111. {
  1112. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1113. }
  1114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1115. {
  1116. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1117. }
  1118. else
  1119. {
  1120. maxProfile.TransactionId = -1;
  1121. }
  1122. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1123. {
  1124. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1125. }
  1126. else
  1127. {
  1128. maxProfile.ChargingSchedule.Duration = 86400;
  1129. }
  1130. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1131. {
  1132. 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")));
  1133. }
  1134. else
  1135. {
  1136. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1137. }
  1138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1139. {
  1140. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1141. }
  1142. else
  1143. {
  1144. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. else
  1150. {
  1151. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1152. {
  1153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1155. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1156. }
  1157. maxProfile.ChargingProfileId = -1;
  1158. maxProfile.StackLevel = -1;
  1159. if(maxProfile.ChargingProfileId == -1)
  1160. DEBUG_INFO("MaxProfile found.\n");
  1161. else
  1162. DEBUG_INFO("MaxProfile updated.\n");
  1163. // Required item
  1164. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1165. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1166. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1167. if(isUnitA)
  1168. {
  1169. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1170. 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++)
  1171. {
  1172. 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"));
  1173. 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?
  1174. 3:
  1175. 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")));
  1176. 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")));
  1177. }
  1178. }
  1179. else
  1180. {
  1181. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1182. 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++)
  1183. {
  1184. 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"));
  1185. 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?
  1186. 3:
  1187. 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")));
  1188. 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));
  1189. }
  1190. }
  1191. // Optional item
  1192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1193. {
  1194. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1195. }
  1196. else
  1197. {
  1198. sprintf((char*)maxProfile.ValidFrom, " ");
  1199. }
  1200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1201. {
  1202. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1203. }
  1204. else
  1205. {
  1206. sprintf((char*)maxProfile.ValidTo, " ");
  1207. }
  1208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1209. {
  1210. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1211. }
  1212. else
  1213. {
  1214. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1215. }
  1216. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1217. {
  1218. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1219. }
  1220. else
  1221. {
  1222. maxProfile.TransactionId = -1;
  1223. }
  1224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1225. {
  1226. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1227. }
  1228. else
  1229. {
  1230. maxProfile.ChargingSchedule.Duration = 86400;
  1231. }
  1232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1233. {
  1234. 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")));
  1235. }
  1236. else
  1237. {
  1238. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1239. }
  1240. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1241. {
  1242. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1243. }
  1244. else
  1245. {
  1246. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1247. }
  1248. }
  1249. }
  1250. }
  1251. json_object_put(obj);
  1252. }
  1253. fclose(fp);
  1254. /*
  1255. if(maxProfile.ChargingProfileId !=-1)
  1256. {
  1257. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1258. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1259. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1260. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1261. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1262. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1263. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1264. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1265. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1266. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1267. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1268. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1269. {
  1270. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1271. {
  1272. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1273. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1274. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1275. }
  1276. }
  1277. }
  1278. else
  1279. DEBUG_INFO("MaxProfile not found.\n");
  1280. DEBUG_INFO("------------------------------------\n");*/
  1281. }
  1282. if(maxProfile.ChargingProfileId != -1)
  1283. {
  1284. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1285. {
  1286. if(maxProfile.ChargingSchedule.Duration != -1)
  1287. {
  1288. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1289. 0:
  1290. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1291. }
  1292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1293. {
  1294. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1295. {
  1296. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1297. 0:
  1298. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1299. if(idxPeriod > 0)
  1300. {
  1301. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1302. {
  1303. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1310. {
  1311. if(maxProfile.ChargingSchedule.Duration != -1)
  1312. {
  1313. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1314. }
  1315. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1316. {
  1317. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1318. {
  1319. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1320. if(idxPeriod > 0)
  1321. {
  1322. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1323. {
  1324. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1333. {
  1334. if(maxProfile.ChargingSchedule.Duration != -1)
  1335. {
  1336. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1337. 0:
  1338. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1339. }
  1340. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1341. {
  1342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1343. {
  1344. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1345. 0:
  1346. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1347. if(idxPeriod > 0)
  1348. {
  1349. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1350. {
  1351. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1352. }
  1353. }
  1354. }
  1355. }
  1356. }
  1357. else
  1358. {
  1359. if(maxProfile.ChargingSchedule.Duration != -1)
  1360. {
  1361. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1362. 0:
  1363. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1364. }
  1365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1366. {
  1367. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1368. {
  1369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1370. 0:
  1371. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1372. if(idxPeriod > 0)
  1373. {
  1374. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1375. {
  1376. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. }
  1383. /*
  1384. DEBUG_INFO("MaxProfile after align.\n");
  1385. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1386. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1387. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1388. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1389. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1390. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1391. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1392. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1393. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1394. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1395. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1396. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1397. {
  1398. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1399. {
  1400. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1401. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1402. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1403. }
  1404. }
  1405. DEBUG_INFO("------------------------------------\n");*/
  1406. }
  1407. // Find each profile period quantity
  1408. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1409. {
  1410. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1411. limitMax = idx+1;
  1412. }
  1413. if(maxProfile.ChargingProfileId != -1)
  1414. {
  1415. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1416. {
  1417. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1418. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1419. (maxProfile.ChargingSchedule.Duration > 0))
  1420. {
  1421. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1422. {
  1423. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1424. compositePeriodIdx++;
  1425. }
  1426. else
  1427. {
  1428. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1429. }
  1430. }
  1431. }
  1432. }
  1433. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1434. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1435. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1436. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1437. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1438. {
  1439. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1440. {
  1441. compositeProfile->ChargingProfileId = 1;
  1442. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1443. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1444. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1445. }
  1446. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1447. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1448. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1449. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1450. }
  1451. if(line)
  1452. free(line);
  1453. }
  1454. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1455. {
  1456. FILE *fp;
  1457. char profileFileName[128];
  1458. char *line = NULL;
  1459. size_t len = 0;
  1460. time_t CurrentTime;
  1461. struct tm *tmComposite;
  1462. struct StructChargingProfile maxProfile;
  1463. struct StructChargingProfile defaultTxProfile;
  1464. struct StructChargingProfile txProfile;
  1465. struct StructChargingSchedulePeriod tmpPeriod;
  1466. uint8_t limitMax=0;
  1467. uint8_t limitDef=0;
  1468. uint8_t limitTx=0;
  1469. int compositePeriodIdx = 0;
  1470. CurrentTime = time(NULL);
  1471. tmComposite=localtime(&CurrentTime);
  1472. 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);
  1473. if(isUnitA)
  1474. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1475. else
  1476. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1477. compositeProfile->ChargingSchedule.Duration = durationReq;
  1478. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1479. {
  1480. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1481. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1482. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1483. }
  1484. compositeProfile->ChargingProfileId = 0;
  1485. compositeProfile->StackLevel = 99 ;
  1486. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1487. maxProfile.ChargingProfileId = -1;
  1488. defaultTxProfile.ChargingProfileId = -1;
  1489. txProfile.ChargingProfileId = -1;
  1490. maxProfile.ChargingSchedule.Duration = -1;
  1491. defaultTxProfile.ChargingSchedule.Duration = -1;
  1492. txProfile.ChargingSchedule.Duration = -1;
  1493. system("rm -f /tmp/*.json");
  1494. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1495. /*
  1496. * Search valid charging profile
  1497. */
  1498. //DEBUG_INFO("====================================\n");
  1499. // Search tx profile
  1500. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1501. if((access(profileFileName, F_OK))!=-1)
  1502. {
  1503. fp = fopen(profileFileName, "r");
  1504. while(getline(&line, &len, fp) != -1)
  1505. {
  1506. json_object *obj = NULL;
  1507. obj = json_tokener_parse(line);
  1508. if(is_error(obj))
  1509. {
  1510. DEBUG_ERROR("Parse txProfile from file error.\n");
  1511. }
  1512. else
  1513. {
  1514. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1515. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1516. )
  1517. {
  1518. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1519. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1520. )
  1521. {
  1522. struct tm tmFrom, tmTo;
  1523. struct timeb tbFrom, tbTo;
  1524. 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) &&
  1525. (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))
  1526. {
  1527. tmFrom.tm_year -= 1900;
  1528. tmFrom.tm_mon -= 1;
  1529. tbFrom.time = mktime(&tmFrom);
  1530. tmTo.tm_year -= 1900;
  1531. tmTo.tm_mon -= 1;
  1532. tbTo.time = mktime(&tmTo);
  1533. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1534. {
  1535. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1536. {
  1537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1539. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1540. }
  1541. txProfile.ChargingProfileId = -1;
  1542. txProfile.StackLevel = -1;
  1543. if(txProfile.ChargingProfileId == -1)
  1544. DEBUG_INFO("TxProfile found.\n");
  1545. else
  1546. DEBUG_INFO("TxProfile updated.\n");
  1547. // Required item
  1548. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1549. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1550. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1551. if(isUnitA)
  1552. {
  1553. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1554. 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++)
  1555. {
  1556. 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"));
  1557. 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?
  1558. 3:
  1559. 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")));
  1560. 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")));
  1561. }
  1562. }
  1563. else
  1564. {
  1565. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1566. 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++)
  1567. {
  1568. 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"));
  1569. 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?
  1570. 3:
  1571. 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")));
  1572. 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));
  1573. }
  1574. }
  1575. // Optional item
  1576. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1577. {
  1578. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1579. }
  1580. else
  1581. {
  1582. sprintf((char*)txProfile.ValidFrom, " ");
  1583. }
  1584. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1585. {
  1586. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1587. }
  1588. else
  1589. {
  1590. sprintf((char*)txProfile.ValidTo, " ");
  1591. }
  1592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1593. {
  1594. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1595. }
  1596. else
  1597. {
  1598. sprintf((char*)txProfile.RecurrencyKind, " ");
  1599. }
  1600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1601. {
  1602. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1603. }
  1604. else
  1605. {
  1606. txProfile.TransactionId = -1;
  1607. }
  1608. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1609. {
  1610. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1611. }
  1612. else
  1613. {
  1614. txProfile.ChargingSchedule.Duration = 86400;
  1615. }
  1616. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1617. {
  1618. 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")));
  1619. }
  1620. else
  1621. {
  1622. 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));
  1623. }
  1624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1625. {
  1626. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1627. }
  1628. else
  1629. {
  1630. txProfile.ChargingSchedule.MinChargingRate = -1;
  1631. }
  1632. }
  1633. }
  1634. }
  1635. else
  1636. {
  1637. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1638. {
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1641. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1642. }
  1643. txProfile.ChargingProfileId = -1;
  1644. txProfile.StackLevel = -1;
  1645. if(txProfile.ChargingProfileId == -1)
  1646. DEBUG_INFO("TxProfile found.\n");
  1647. else
  1648. DEBUG_INFO("TxProfile updated.\n");
  1649. // Required item
  1650. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1651. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1652. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1653. if(isUnitA)
  1654. {
  1655. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1656. 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++)
  1657. {
  1658. 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"));
  1659. 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?
  1660. 3:
  1661. 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")));
  1662. 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")));
  1663. }
  1664. }
  1665. else
  1666. {
  1667. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1668. 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++)
  1669. {
  1670. 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"));
  1671. 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?
  1672. 3:
  1673. 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")));
  1674. 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));
  1675. }
  1676. }
  1677. // Optional item
  1678. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1679. {
  1680. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1681. }
  1682. else
  1683. {
  1684. sprintf((char*)txProfile.ValidFrom, " ");
  1685. }
  1686. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1687. {
  1688. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1689. }
  1690. else
  1691. {
  1692. sprintf((char*)txProfile.ValidTo, " ");
  1693. }
  1694. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1695. {
  1696. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1697. }
  1698. else
  1699. {
  1700. sprintf((char*)txProfile.RecurrencyKind, " ");
  1701. }
  1702. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1703. {
  1704. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1705. }
  1706. else
  1707. {
  1708. txProfile.TransactionId = -1;
  1709. }
  1710. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1711. {
  1712. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1713. }
  1714. else
  1715. {
  1716. txProfile.ChargingSchedule.Duration = 86400;
  1717. }
  1718. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1719. {
  1720. 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")));
  1721. }
  1722. else
  1723. {
  1724. 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));
  1725. }
  1726. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1727. {
  1728. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1729. }
  1730. else
  1731. {
  1732. txProfile.ChargingSchedule.MinChargingRate = -1;
  1733. }
  1734. }
  1735. }
  1736. }
  1737. json_object_put(obj);
  1738. }
  1739. fclose(fp);
  1740. /*
  1741. if(txProfile.ChargingProfileId != -1)
  1742. {
  1743. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1744. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1745. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1746. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1747. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1748. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1749. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1750. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1751. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1752. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1753. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1754. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1755. {
  1756. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1757. {
  1758. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1759. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1760. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1761. }
  1762. }
  1763. }
  1764. else
  1765. DEBUG_INFO("TxProfile not found.\n");*/
  1766. }
  1767. // Search default tx profile
  1768. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1769. if((access(profileFileName, F_OK))==-1)
  1770. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1771. if((access(profileFileName, F_OK))!=-1)
  1772. {
  1773. fp = fopen(profileFileName, "r");
  1774. while(getline(&line, &len, fp) != -1)
  1775. {
  1776. json_object *obj = NULL;
  1777. obj = json_tokener_parse(line);
  1778. if(is_error(obj))
  1779. {
  1780. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1781. }
  1782. else
  1783. {
  1784. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1785. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1786. )
  1787. {
  1788. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1789. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1790. )
  1791. {
  1792. struct tm tmFrom, tmTo;
  1793. struct timeb tbFrom, tbTo;
  1794. 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) &&
  1795. (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))
  1796. {
  1797. tmFrom.tm_year -= 1900;
  1798. tmFrom.tm_mon -= 1;
  1799. tbFrom.time = mktime(&tmFrom);
  1800. tmTo.tm_year -= 1900;
  1801. tmTo.tm_mon -= 1;
  1802. tbTo.time = mktime(&tmTo);
  1803. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1804. {
  1805. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1806. {
  1807. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1809. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1810. }
  1811. defaultTxProfile.ChargingProfileId = -1;
  1812. defaultTxProfile.StackLevel = -1;
  1813. if(defaultTxProfile.ChargingProfileId == -1)
  1814. DEBUG_INFO("TxDefaultProfile found.\n");
  1815. else
  1816. DEBUG_INFO("TxDefaultProfile updated.\n");
  1817. // Required item
  1818. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1819. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1820. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1821. if(isUnitA)
  1822. {
  1823. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1824. 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++)
  1825. {
  1826. 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"));
  1827. 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?
  1828. 3:
  1829. 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")));
  1830. 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")));
  1831. }
  1832. }
  1833. else
  1834. {
  1835. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1836. 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++)
  1837. {
  1838. 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"));
  1839. 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?
  1840. 3:
  1841. 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")));
  1842. 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));
  1843. }
  1844. }
  1845. // Optional item
  1846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1847. {
  1848. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1849. }
  1850. else
  1851. {
  1852. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1853. }
  1854. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1855. {
  1856. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1857. }
  1858. else
  1859. {
  1860. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1861. }
  1862. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1863. {
  1864. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1865. }
  1866. else
  1867. {
  1868. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1869. }
  1870. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1871. {
  1872. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1873. }
  1874. else
  1875. {
  1876. defaultTxProfile.TransactionId = -1;
  1877. }
  1878. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1879. {
  1880. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1881. }
  1882. else
  1883. {
  1884. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1885. }
  1886. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1887. {
  1888. 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")));
  1889. }
  1890. else
  1891. {
  1892. 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));
  1893. }
  1894. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1895. {
  1896. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1897. }
  1898. else
  1899. {
  1900. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1901. }
  1902. }
  1903. }
  1904. }
  1905. else
  1906. {
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1912. }
  1913. defaultTxProfile.ChargingProfileId = -1;
  1914. defaultTxProfile.StackLevel = -1;
  1915. if(defaultTxProfile.ChargingProfileId == -1)
  1916. DEBUG_INFO("TxDefaultProfile found.\n");
  1917. else
  1918. DEBUG_INFO("TxDefaultProfile updated.\n");
  1919. // Required item
  1920. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1921. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1922. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1923. if(isUnitA)
  1924. {
  1925. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1926. 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++)
  1927. {
  1928. 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"));
  1929. 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?
  1930. 3:
  1931. 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")));
  1932. 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")));
  1933. }
  1934. }
  1935. else
  1936. {
  1937. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1938. 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++)
  1939. {
  1940. 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"));
  1941. 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?
  1942. 3:
  1943. 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")));
  1944. 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));
  1945. }
  1946. }
  1947. // Optional item
  1948. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1949. {
  1950. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1951. }
  1952. else
  1953. {
  1954. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1955. }
  1956. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1957. {
  1958. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1959. }
  1960. else
  1961. {
  1962. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1963. }
  1964. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1965. {
  1966. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1967. }
  1968. else
  1969. {
  1970. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1971. }
  1972. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1973. {
  1974. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1975. }
  1976. else
  1977. {
  1978. defaultTxProfile.TransactionId = -1;
  1979. }
  1980. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1981. {
  1982. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1983. }
  1984. else
  1985. {
  1986. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1987. }
  1988. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1989. {
  1990. 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")));
  1991. }
  1992. else
  1993. {
  1994. 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));
  1995. }
  1996. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1997. {
  1998. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1999. }
  2000. else
  2001. {
  2002. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2003. }
  2004. }
  2005. }
  2006. }
  2007. json_object_put(obj);
  2008. }
  2009. fclose(fp);
  2010. /*
  2011. if(defaultTxProfile.ChargingProfileId != -1)
  2012. {
  2013. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2014. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2015. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2016. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2017. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2018. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2019. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2020. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2021. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2022. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2023. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2024. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2025. {
  2026. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2027. {
  2028. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2029. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2030. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2031. }
  2032. }
  2033. }
  2034. else
  2035. DEBUG_INFO("TxDefaultProfile not found.\n");
  2036. DEBUG_INFO("------------------------------------\n");*/
  2037. }
  2038. // Search max profile
  2039. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2040. if((access(profileFileName, F_OK))!=-1)
  2041. {
  2042. fp = fopen(profileFileName, "r");
  2043. while(getline(&line, &len, fp) != -1)
  2044. {
  2045. json_object *obj = NULL;
  2046. obj = json_tokener_parse(line);
  2047. if(is_error(obj))
  2048. {
  2049. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2050. }
  2051. else
  2052. {
  2053. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2054. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2055. )
  2056. {
  2057. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2058. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2059. )
  2060. {
  2061. struct tm tmFrom, tmTo;
  2062. struct timeb tbFrom, tbTo;
  2063. 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) &&
  2064. (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))
  2065. {
  2066. tmFrom.tm_year -= 1900;
  2067. tmFrom.tm_mon -= 1;
  2068. tbFrom.time = mktime(&tmFrom);
  2069. tmTo.tm_year -= 1900;
  2070. tmTo.tm_mon -= 1;
  2071. tbTo.time = mktime(&tmTo);
  2072. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2073. {
  2074. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2075. {
  2076. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2077. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2079. }
  2080. maxProfile.ChargingProfileId = -1;
  2081. maxProfile.StackLevel = -1;
  2082. if(maxProfile.ChargingProfileId == -1)
  2083. DEBUG_INFO("MaxProfile found.\n");
  2084. else
  2085. DEBUG_INFO("MaxProfile updated.\n");
  2086. // Required item
  2087. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2088. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2089. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2090. if(isUnitA)
  2091. {
  2092. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2093. 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++)
  2094. {
  2095. 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"));
  2096. 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?
  2097. 3:
  2098. 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")));
  2099. 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")));
  2100. }
  2101. }
  2102. else
  2103. {
  2104. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2105. 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++)
  2106. {
  2107. 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"));
  2108. 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?
  2109. 3:
  2110. 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")));
  2111. 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));
  2112. }
  2113. }
  2114. // Optional item
  2115. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2116. {
  2117. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2118. }
  2119. else
  2120. {
  2121. sprintf((char*)maxProfile.ValidFrom, " ");
  2122. }
  2123. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2124. {
  2125. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2126. }
  2127. else
  2128. {
  2129. sprintf((char*)maxProfile.ValidTo, " ");
  2130. }
  2131. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2132. {
  2133. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2134. }
  2135. else
  2136. {
  2137. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2138. }
  2139. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2140. {
  2141. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2142. }
  2143. else
  2144. {
  2145. maxProfile.TransactionId = -1;
  2146. }
  2147. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2148. {
  2149. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2150. }
  2151. else
  2152. {
  2153. maxProfile.ChargingSchedule.Duration = 86400;
  2154. }
  2155. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2156. {
  2157. 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")));
  2158. }
  2159. else
  2160. {
  2161. 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));
  2162. }
  2163. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2164. {
  2165. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2166. }
  2167. else
  2168. {
  2169. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2170. }
  2171. }
  2172. }
  2173. }
  2174. else
  2175. {
  2176. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2177. {
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2181. }
  2182. maxProfile.ChargingProfileId = -1;
  2183. maxProfile.StackLevel = -1;
  2184. if(maxProfile.ChargingProfileId == -1)
  2185. DEBUG_INFO("MaxProfile found.\n");
  2186. else
  2187. DEBUG_INFO("MaxProfile updated.\n");
  2188. // Required item
  2189. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2190. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2191. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2192. if(isUnitA)
  2193. {
  2194. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2195. 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++)
  2196. {
  2197. 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"));
  2198. 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?
  2199. 3:
  2200. 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")));
  2201. 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")));
  2202. }
  2203. }
  2204. else
  2205. {
  2206. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2207. 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++)
  2208. {
  2209. 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"));
  2210. 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?
  2211. 3:
  2212. 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")));
  2213. 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));
  2214. }
  2215. }
  2216. // Optional item
  2217. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2218. {
  2219. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2220. }
  2221. else
  2222. {
  2223. sprintf((char*)maxProfile.ValidFrom, " ");
  2224. }
  2225. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2226. {
  2227. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2228. }
  2229. else
  2230. {
  2231. sprintf((char*)maxProfile.ValidTo, " ");
  2232. }
  2233. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2234. {
  2235. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2236. }
  2237. else
  2238. {
  2239. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2240. }
  2241. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2242. {
  2243. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2244. }
  2245. else
  2246. {
  2247. maxProfile.TransactionId = -1;
  2248. }
  2249. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2250. {
  2251. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2252. }
  2253. else
  2254. {
  2255. maxProfile.ChargingSchedule.Duration = 86400;
  2256. }
  2257. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2258. {
  2259. 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")));
  2260. }
  2261. else
  2262. {
  2263. 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));
  2264. }
  2265. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2266. {
  2267. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2268. }
  2269. else
  2270. {
  2271. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2272. }
  2273. }
  2274. }
  2275. }
  2276. json_object_put(obj);
  2277. }
  2278. fclose(fp);
  2279. /*
  2280. if(maxProfile.ChargingProfileId !=-1)
  2281. {
  2282. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2283. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2284. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2285. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2286. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2287. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2288. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2289. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2290. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2291. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2292. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2294. {
  2295. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2296. {
  2297. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2298. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2299. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2300. }
  2301. }
  2302. }
  2303. else
  2304. DEBUG_INFO("MaxProfile not found.\n");
  2305. DEBUG_INFO("------------------------------------\n");*/
  2306. }
  2307. /*
  2308. * Align found profile start schedule & periods
  2309. */
  2310. //DEBUG_INFO("====================================\n");
  2311. /*
  2312. // For local test usage, force modify found profile start schedule info
  2313. 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);
  2314. 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);
  2315. 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);
  2316. */
  2317. if(txProfile.ChargingProfileId != -1)
  2318. {
  2319. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2320. {
  2321. if(txProfile.ChargingSchedule.Duration != -1)
  2322. {
  2323. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2324. 0:
  2325. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2326. }
  2327. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2328. {
  2329. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2330. {
  2331. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2332. 0:
  2333. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2334. if(idxPeriod > 0)
  2335. {
  2336. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2337. {
  2338. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2345. {
  2346. if(txProfile.ChargingSchedule.Duration != -1)
  2347. {
  2348. 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?
  2349. 0:
  2350. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2351. }
  2352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2353. {
  2354. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2355. {
  2356. 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?
  2357. 0:
  2358. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2359. if(idxPeriod > 0)
  2360. {
  2361. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2362. {
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2364. }
  2365. }
  2366. }
  2367. }
  2368. }
  2369. else
  2370. {
  2371. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2372. {
  2373. if(txProfile.ChargingSchedule.Duration != -1)
  2374. {
  2375. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2376. 0:
  2377. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2378. }
  2379. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2380. {
  2381. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2382. {
  2383. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2384. 0:
  2385. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2386. if(idxPeriod > 0)
  2387. {
  2388. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2389. {
  2390. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. }
  2396. else
  2397. {
  2398. if(txProfile.ChargingSchedule.Duration != -1)
  2399. {
  2400. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2401. 0:
  2402. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2403. }
  2404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2405. {
  2406. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2407. {
  2408. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2409. 0:
  2410. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2411. if(idxPeriod > 0)
  2412. {
  2413. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2414. {
  2415. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. }
  2422. /*
  2423. DEBUG_INFO("txProfile after align.\n");
  2424. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2425. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2426. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2427. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2428. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2429. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2430. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2431. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2432. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2433. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2434. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2435. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2436. {
  2437. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2438. {
  2439. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2440. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2441. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2442. }
  2443. }*/
  2444. }
  2445. if(defaultTxProfile.ChargingProfileId != -1)
  2446. {
  2447. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2448. {
  2449. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2450. {
  2451. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2452. 0:
  2453. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2454. }
  2455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2456. {
  2457. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2458. {
  2459. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2460. 0:
  2461. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2462. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2463. {
  2464. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2465. }
  2466. if(idxPeriod > 0)
  2467. {
  2468. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2469. {
  2470. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2471. }
  2472. }
  2473. }
  2474. }
  2475. }
  2476. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2477. {
  2478. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2479. {
  2480. 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?
  2481. 0:
  2482. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2483. }
  2484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2485. {
  2486. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2487. {
  2488. 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?
  2489. 0:
  2490. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2491. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2492. {
  2493. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2494. }
  2495. if(idxPeriod > 0)
  2496. {
  2497. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2498. {
  2499. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. else
  2506. {
  2507. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2508. {
  2509. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2510. {
  2511. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2512. 0:
  2513. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2514. }
  2515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2516. {
  2517. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2518. {
  2519. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2520. 0:
  2521. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2522. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2523. {
  2524. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2525. }
  2526. if(idxPeriod > 0)
  2527. {
  2528. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2529. {
  2530. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2531. }
  2532. }
  2533. }
  2534. }
  2535. }
  2536. else
  2537. {
  2538. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2539. {
  2540. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2541. 0:
  2542. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2543. }
  2544. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2545. {
  2546. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2547. {
  2548. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2549. 0:
  2550. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2551. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2552. {
  2553. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2554. }
  2555. if(idxPeriod > 0)
  2556. {
  2557. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2558. {
  2559. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. /*
  2567. DEBUG_INFO("defaultTxProfile after align.\n");
  2568. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2569. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2570. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2571. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2572. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2573. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2574. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2575. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2576. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2577. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2578. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2579. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2580. {
  2581. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2582. {
  2583. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2584. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2585. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2586. }
  2587. }
  2588. DEBUG_INFO("------------------------------------\n");*/
  2589. }
  2590. if(maxProfile.ChargingProfileId != -1)
  2591. {
  2592. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2593. {
  2594. if(maxProfile.ChargingSchedule.Duration != -1)
  2595. {
  2596. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2597. 0:
  2598. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2599. }
  2600. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2601. {
  2602. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2603. {
  2604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2605. 0:
  2606. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2607. if(idxPeriod > 0)
  2608. {
  2609. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2610. {
  2611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2618. {
  2619. if(maxProfile.ChargingSchedule.Duration != -1)
  2620. {
  2621. 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?
  2622. 0:
  2623. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2624. }
  2625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2626. {
  2627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2628. {
  2629. 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?
  2630. 0:
  2631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2632. if(idxPeriod > 0)
  2633. {
  2634. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2635. {
  2636. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2637. }
  2638. }
  2639. }
  2640. }
  2641. }
  2642. else
  2643. {
  2644. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2645. {
  2646. if(maxProfile.ChargingSchedule.Duration != -1)
  2647. {
  2648. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2649. 0:
  2650. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2651. }
  2652. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2653. {
  2654. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2655. {
  2656. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2657. 0:
  2658. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2659. if(idxPeriod > 0)
  2660. {
  2661. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2662. {
  2663. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2664. }
  2665. }
  2666. }
  2667. }
  2668. }
  2669. else
  2670. {
  2671. if(maxProfile.ChargingSchedule.Duration != -1)
  2672. {
  2673. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2674. 0:
  2675. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2676. }
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2680. {
  2681. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2682. 0:
  2683. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2684. if(idxPeriod > 0)
  2685. {
  2686. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2687. {
  2688. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. /*
  2696. DEBUG_INFO("MaxProfile after align.\n");
  2697. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2698. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2699. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2700. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2701. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2702. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2703. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2704. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2705. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2706. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2707. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2709. {
  2710. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2711. {
  2712. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2713. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2714. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2715. }
  2716. }
  2717. DEBUG_INFO("------------------------------------\n");*/
  2718. }
  2719. /*
  2720. * Merge to conposite schedule
  2721. */
  2722. //DEBUG_INFO("====================================\n");
  2723. // Find each profile period quantity
  2724. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2725. {
  2726. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2727. limitMax = idx+1;
  2728. }
  2729. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2730. {
  2731. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2732. limitDef = idx+1;
  2733. }
  2734. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2735. {
  2736. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2737. limitTx = idx+1;
  2738. }
  2739. // TxProfile found, composite schedule based on it
  2740. if(txProfile.ChargingProfileId != -1)
  2741. {
  2742. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2743. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2744. {
  2745. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2746. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2747. (txProfile.ChargingSchedule.Duration > 0))
  2748. {
  2749. if(maxProfile.ChargingProfileId != -1)
  2750. {
  2751. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2752. {
  2753. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2754. {
  2755. if((maxProfile.ChargingSchedule.Duration > 0))
  2756. {
  2757. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2758. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2759. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2760. }
  2761. else
  2762. {
  2763. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2764. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2765. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2766. }
  2767. }
  2768. if(idxMaxPeriod == (limitMax-1))
  2769. {
  2770. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2771. {
  2772. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2773. {
  2774. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2775. compositePeriodIdx++;
  2776. }
  2777. else
  2778. {
  2779. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2780. }
  2781. }
  2782. }
  2783. }
  2784. }
  2785. else
  2786. {
  2787. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2788. {
  2789. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2790. compositePeriodIdx++;
  2791. }
  2792. else
  2793. {
  2794. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2795. }
  2796. }
  2797. }
  2798. if(idxTxPeriod == (limitTx-1))
  2799. {
  2800. if(defaultTxProfile.ChargingProfileId != -1)
  2801. {
  2802. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2803. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2804. {
  2805. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2806. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2807. (defaultTxProfile.ChargingSchedule.Duration>0))
  2808. {
  2809. if(maxProfile.ChargingProfileId != -1)
  2810. {
  2811. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2812. {
  2813. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2814. {
  2815. if((maxProfile.ChargingSchedule.Duration > 0))
  2816. {
  2817. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2818. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2819. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2820. }
  2821. else
  2822. {
  2823. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2824. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2825. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2826. }
  2827. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2828. {
  2829. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2830. {
  2831. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2832. compositePeriodIdx++;
  2833. }
  2834. else
  2835. {
  2836. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2837. }
  2838. }
  2839. // Delete duplicate period
  2840. if(compositePeriodIdx > 1)
  2841. {
  2842. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2843. {
  2844. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2845. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2846. compositePeriodIdx -= 1;
  2847. }
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2853. {
  2854. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2855. compositePeriodIdx++;
  2856. }
  2857. else
  2858. {
  2859. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2860. }
  2861. break;
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2868. {
  2869. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2870. compositePeriodIdx++;
  2871. }
  2872. else
  2873. {
  2874. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. }
  2883. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2884. else if(defaultTxProfile.ChargingProfileId != -1)
  2885. {
  2886. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2887. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2888. {
  2889. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2890. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2891. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2892. {
  2893. if(maxProfile.ChargingProfileId != -1)
  2894. {
  2895. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2896. {
  2897. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2898. {
  2899. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2900. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2901. if((maxProfile.ChargingSchedule.Duration > 0))
  2902. {
  2903. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2904. }
  2905. else
  2906. {
  2907. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2908. }
  2909. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2910. {
  2911. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2912. {
  2913. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2914. compositePeriodIdx++;
  2915. }
  2916. else
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2919. }
  2920. }
  2921. // Delete duplicate period
  2922. if(compositePeriodIdx > 1)
  2923. {
  2924. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2925. {
  2926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2928. compositePeriodIdx -= 1;
  2929. }
  2930. }
  2931. }
  2932. else
  2933. {
  2934. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2935. {
  2936. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2937. compositePeriodIdx++;
  2938. }
  2939. else
  2940. {
  2941. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2942. }
  2943. break;
  2944. }
  2945. }
  2946. }
  2947. else
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2950. {
  2951. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2952. compositePeriodIdx++;
  2953. }
  2954. else
  2955. {
  2956. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2957. }
  2958. }
  2959. }
  2960. }
  2961. }
  2962. // Fill other period by MaxProfile
  2963. if(maxProfile.ChargingProfileId != -1)
  2964. {
  2965. if(compositePeriodIdx==0)
  2966. {
  2967. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2968. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2969. {
  2970. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2971. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2972. (maxProfile.ChargingSchedule.Duration > 0))
  2973. {
  2974. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2975. {
  2976. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2977. compositePeriodIdx++;
  2978. }
  2979. else
  2980. {
  2981. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2982. }
  2983. }
  2984. }
  2985. }
  2986. else
  2987. {
  2988. int lastCompositePeriodIdx = compositePeriodIdx;
  2989. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2990. {
  2991. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2992. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2993. (maxProfile.ChargingSchedule.Duration > 0))
  2994. {
  2995. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2996. {
  2997. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2998. {
  2999. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3000. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3001. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3002. }
  3003. else
  3004. {
  3005. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3006. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3007. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3008. }
  3009. }
  3010. if(tmpPeriod.Limit != -1)
  3011. {
  3012. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3013. {
  3014. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3015. {
  3016. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3017. compositePeriodIdx++;
  3018. }
  3019. else
  3020. {
  3021. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3022. }
  3023. }
  3024. // Delete duplicate period
  3025. if(compositePeriodIdx > 1)
  3026. {
  3027. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3028. {
  3029. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3030. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3031. compositePeriodIdx -= 1;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. compositeProfile->ChargingSchedule.Duration = durationReq;
  3040. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3041. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3042. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3043. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3044. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3045. {
  3046. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3047. {
  3048. compositeProfile->ChargingProfileId = 1;
  3049. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3050. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3051. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3052. }
  3053. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3054. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3055. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3056. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3057. }
  3058. if(line)
  3059. free(line);
  3060. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3061. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3062. }
  3063. //==========================================
  3064. // Init all share memory
  3065. //==========================================
  3066. int InitShareMemory()
  3067. {
  3068. int result = PASS;
  3069. int MeterSMId;
  3070. //creat ShmSysConfigAndInfo
  3071. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3072. {
  3073. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3074. result = FAIL;
  3075. }
  3076. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3077. {
  3078. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3079. result = FAIL;
  3080. }
  3081. else
  3082. {}
  3083. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3084. {
  3085. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3086. result = FAIL;
  3087. }
  3088. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3089. {
  3090. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3091. result = FAIL;
  3092. }
  3093. else
  3094. {}
  3095. //creat ShmPsuData
  3096. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3097. {
  3098. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3099. result = FAIL;
  3100. }
  3101. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3102. {
  3103. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3104. result = FAIL;
  3105. }
  3106. else
  3107. {}
  3108. //link ShmOCPP16Data
  3109. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3110. {
  3111. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3112. result = FAIL;
  3113. }
  3114. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3115. {
  3116. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3117. result = FAIL;
  3118. }
  3119. else
  3120. {}
  3121. //creat ShmOCPP16DataPH
  3122. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3123. {
  3124. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3125. result = FAIL;
  3126. }
  3127. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3128. {
  3129. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3130. result = FAIL;
  3131. }
  3132. else
  3133. {}
  3134. /****************************** For Initial Settings************************************************/
  3135. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3136. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3137. // allocate Configuration memory address
  3138. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3139. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3140. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3141. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3142. //offline MeterValue Interval
  3143. TempMeterValueInterval = 0;
  3144. return result;
  3145. }
  3146. int ProcessShareMemory()
  3147. {
  3148. int result = PASS;
  3149. if(InitShareMemory() == FAIL)
  3150. {
  3151. DEBUG_ERROR("InitShareMemory NG\n");
  3152. if(ShmStatusCodeData!=NULL)
  3153. {
  3154. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3155. }
  3156. result = FAIL;
  3157. }
  3158. // Model name parsing
  3159. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3160. {
  3161. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3162. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3163. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3164. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3165. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3166. ) // 'D' means DC
  3167. {
  3168. // DO series
  3169. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3170. {
  3171. SystemInitial += 1;
  3172. gunTotalNumber += 1;
  3173. gunType[gun_index] = GUN_TYPE_DO;
  3174. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3175. {
  3176. case Gun_Type_Chademo:
  3177. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3178. break;
  3179. case Gun_Type_CCS_2:
  3180. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3181. break;
  3182. case Gun_Type_GB:
  3183. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3184. break;
  3185. case Gun_Type_AC:
  3186. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3187. break;
  3188. default:
  3189. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3190. break;
  3191. }
  3192. }
  3193. }
  3194. else
  3195. {
  3196. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3197. {
  3198. SystemInitial += 1;
  3199. gunTotalNumber += 1;
  3200. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3201. {
  3202. case Gun_Type_Chademo:
  3203. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3204. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3205. break;
  3206. case Gun_Type_CCS_2:
  3207. gunType[gun_index] = GUN_TYPE_CCS;
  3208. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3209. break;
  3210. case Gun_Type_GB:
  3211. gunType[gun_index] = GUN_TYPE_GBT;
  3212. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3213. break;
  3214. case Gun_Type_AC:
  3215. gunType[gun_index] = GUN_TYPE_AC;
  3216. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3217. break;
  3218. default:
  3219. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3220. break;
  3221. }
  3222. }
  3223. }
  3224. }
  3225. else
  3226. {
  3227. DEBUG_ERROR("Model name parsing fail.\n");
  3228. result = FAIL;
  3229. }
  3230. if(result != PASS)sleep(5);
  3231. return result;
  3232. }
  3233. void checkRemoteStart(uint8_t connectorIdInt)
  3234. {
  3235. uint8_t tempIndex;
  3236. int result = PASS;
  3237. char cmdBuf[512];
  3238. //check Transaction active
  3239. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3240. {
  3241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3242. {
  3243. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3244. }
  3245. else
  3246. {
  3247. tempIndex = connectorIdInt -1;
  3248. }
  3249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3250. {
  3251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3252. {
  3253. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3254. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3255. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3256. {
  3257. //Reserved
  3258. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3259. }
  3260. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3261. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3262. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3263. {
  3264. //Reserved
  3265. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3266. result = FAIL;
  3267. goto end;
  3268. }
  3269. else
  3270. {
  3271. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3272. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3273. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3274. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3275. {
  3276. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3277. result = FAIL;
  3278. goto end;
  3279. }
  3280. }//END FOR ELSE
  3281. }
  3282. }// END FOR CHAdeMO_QUANTITY
  3283. }
  3284. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3285. {
  3286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3287. {
  3288. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3289. }
  3290. else
  3291. {
  3292. tempIndex = connectorIdInt -1;
  3293. }
  3294. for (int index = 0; index < CCS_QUANTITY; index++)
  3295. {
  3296. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3297. {
  3298. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3300. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3301. {
  3302. //Reserved
  3303. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3304. }
  3305. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3307. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3308. {
  3309. //Reserved
  3310. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3311. result = FAIL;
  3312. goto end;
  3313. }
  3314. else
  3315. {
  3316. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3317. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3318. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3319. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3320. {
  3321. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3322. result = FAIL;
  3323. goto end;
  3324. }
  3325. }// END FOR ELSE
  3326. }
  3327. }// END FOR CCS_QUANTITY
  3328. }
  3329. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3330. {
  3331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3332. {
  3333. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3334. }
  3335. else
  3336. {
  3337. tempIndex = connectorIdInt -1;
  3338. }
  3339. for (int index = 0; index < GB_QUANTITY; index++)
  3340. {
  3341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3342. {
  3343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3344. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3345. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3346. {
  3347. //Reserved
  3348. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3349. }
  3350. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3351. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3352. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3353. {
  3354. //Reserved
  3355. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3356. result = FAIL;
  3357. goto end;
  3358. }
  3359. else
  3360. {
  3361. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3362. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3363. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3364. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3365. {
  3366. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3367. result = FAIL;
  3368. goto end;
  3369. }
  3370. }// END FOR ELSE
  3371. }
  3372. } // END FOR GB_QUANTITY
  3373. }
  3374. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3375. {
  3376. tempIndex = connectorIdInt -1;
  3377. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3380. {
  3381. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3382. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3383. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3384. {
  3385. //Reserved
  3386. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3387. }
  3388. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3389. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3390. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3391. {
  3392. //Reserved
  3393. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3394. result = FAIL;
  3395. goto end;
  3396. }
  3397. else
  3398. {
  3399. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3400. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3401. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3402. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3403. {
  3404. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3405. result = FAIL;
  3406. goto end;
  3407. }
  3408. }// END FOR ELSE
  3409. }
  3410. } // END FOR GB_QUANTITY
  3411. }
  3412. else
  3413. {
  3414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3415. {
  3416. tempIndex = 2;
  3417. }
  3418. else
  3419. {
  3420. tempIndex = connectorIdInt -1;
  3421. }
  3422. for (int index = 0; index < AC_QUANTITY; index++)
  3423. {
  3424. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3425. {
  3426. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3427. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3428. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3429. {
  3430. //Reserved
  3431. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3432. }
  3433. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3434. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3435. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3436. {
  3437. //Reserved
  3438. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3439. result = FAIL;
  3440. goto end;
  3441. }
  3442. else
  3443. {
  3444. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3445. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3446. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3447. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3448. {
  3449. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3450. result = FAIL;
  3451. goto end;
  3452. }
  3453. }//END FOR ELSE
  3454. }
  3455. }// END FOR AC_QUANTITY
  3456. }
  3457. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3458. {
  3459. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3460. {
  3461. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3462. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3463. {
  3464. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3465. system(cmdBuf);
  3466. }
  3467. }
  3468. else
  3469. {
  3470. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3471. result = FAIL;
  3472. }
  3473. }
  3474. end:
  3475. if(result == PASS)
  3476. {
  3477. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3478. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3479. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3480. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3482. }
  3483. }
  3484. void CheckSystemValue(void)
  3485. {
  3486. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3487. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3488. char filenmae[100]={0};
  3489. char str[100]={0};
  3490. int tempIndex = 0;
  3491. //===============================
  3492. // send Heartbeat
  3493. //===============================
  3494. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3495. {
  3496. //parameter for test
  3497. sendHeartbeatRequest(0);
  3498. //==============================================
  3499. // Reset Waiting Time
  3500. //==============================================
  3501. HeartBeatWithNOResponse += 2;
  3502. }
  3503. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3504. {
  3505. //==========================================
  3506. // Check remote start without connector id
  3507. //==========================================
  3508. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3509. {
  3510. int connectorIdInt = -1;
  3511. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3512. {
  3513. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3514. {
  3515. connectorIdInt = (gun_index+1);
  3516. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3517. checkRemoteStart(connectorIdInt);
  3518. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3519. break;
  3520. }
  3521. }
  3522. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3523. {
  3524. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3525. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3526. }
  3527. }
  3528. //==========================================
  3529. // csu trigger DataTransferReq
  3530. //==========================================
  3531. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3532. {
  3533. sendDataTransferRequest(gun_index);
  3534. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3535. }
  3536. //===============================
  3537. // CSU Trigger Authorize Request
  3538. //===============================
  3539. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3540. {
  3541. sendAuthorizeRequest(0);
  3542. authorizeRetryTimes = authorizeRetryTimes + 1;
  3543. if(authorizeRetryTimes < 3)
  3544. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3545. }
  3546. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3547. {
  3548. authorizeRetryTimes = 0;
  3549. SetOcppConnStatus(FALSE);
  3550. server_sign = FALSE;
  3551. }
  3552. 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))
  3553. {
  3554. sendAuthorizeRequest(0);
  3555. }
  3556. //==============================================
  3557. // Charger start transaction
  3558. //==============================================
  3559. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3560. {
  3561. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3562. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3563. sendStartTransactionRequest(gun_index);
  3564. refreshStartTimer(&clientTime.StartTransaction);
  3565. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3566. //storeTempStopTransaction(gun_index);
  3567. }
  3568. //==============================================
  3569. // Charger stop transaction
  3570. //==============================================
  3571. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3572. {
  3573. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3574. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3575. sendStopTransactionRequest(gun_index);
  3576. refreshStartTimer(&clientTime.StopTransaction);
  3577. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3578. }
  3579. //==============================================
  3580. // Charger status report
  3581. //==============================================
  3582. //--- Check Mode Change ---//
  3583. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3584. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3587. {
  3588. tempIndex = ((gun_index==2) ? 1: 0);
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3595. {
  3596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3597. {
  3598. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3599. {
  3600. // Sent unplug message for California pricing logic
  3601. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3602. {
  3603. uint8_t ts[20];
  3604. getNowDatetime(ts);
  3605. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3606. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3607. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3608. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3609. }
  3610. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3611. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3612. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3613. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3614. {
  3615. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3616. if((access(filenmae,F_OK))!=-1)
  3617. {
  3618. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3619. sprintf(str,"rm -f %s",filenmae);
  3620. system(str);
  3621. }
  3622. }
  3623. }
  3624. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3625. #if 1 // for TempStopTransaction
  3626. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3627. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3628. {
  3629. checkTempStopTransaction(gun_index);
  3630. }
  3631. #endif
  3632. }
  3633. }
  3634. }
  3635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3636. {
  3637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3638. {
  3639. tempIndex = ((gun_index==2) ? 1: 0);
  3640. }
  3641. else
  3642. {
  3643. tempIndex = gun_index;
  3644. }
  3645. for (int index = 0; index < CCS_QUANTITY; index++)
  3646. {
  3647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3648. {
  3649. 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]*/ )
  3650. {
  3651. // Sent unplug message for California pricing logic
  3652. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3653. {
  3654. uint8_t ts[20];
  3655. getNowDatetime(ts);
  3656. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3657. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3658. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3659. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3660. }
  3661. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3662. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3663. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3664. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3665. {
  3666. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3667. if((access(filenmae,F_OK))!=-1)
  3668. {
  3669. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3670. sprintf(str,"rm -f %s",filenmae);
  3671. system(str);
  3672. }
  3673. }
  3674. }
  3675. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3676. #if 1 // for TempStopTransaction
  3677. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3678. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3679. {
  3680. checkTempStopTransaction(gun_index);
  3681. }
  3682. #endif
  3683. }
  3684. }
  3685. }
  3686. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < GB_QUANTITY; index++)
  3697. {
  3698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3699. {
  3700. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3701. {
  3702. // Sent unplug message for California pricing logic
  3703. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3704. {
  3705. uint8_t ts[20];
  3706. getNowDatetime(ts);
  3707. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3710. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3711. }
  3712. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3713. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3714. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3715. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3716. {
  3717. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3718. if((access(filenmae,F_OK))!=-1)
  3719. {
  3720. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3721. sprintf(str,"rm -f %s",filenmae);
  3722. system(str);
  3723. }
  3724. }
  3725. }
  3726. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3727. #if 1 // for TempStopTransaction
  3728. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3729. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3730. {
  3731. checkTempStopTransaction(gun_index);
  3732. }
  3733. #endif
  3734. }
  3735. }
  3736. }
  3737. else if(gunType[gun_index] == GUN_TYPE_DO)
  3738. {
  3739. tempIndex = gun_index;
  3740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3741. {
  3742. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3743. {
  3744. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3745. {
  3746. // Sent unplug message for California pricing logic
  3747. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3748. {
  3749. uint8_t ts[20];
  3750. getNowDatetime(ts);
  3751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3754. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3755. }
  3756. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3757. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3758. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3759. 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
  3760. {
  3761. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3762. if((access(filenmae,F_OK))!=-1)
  3763. {
  3764. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3765. sprintf(str,"rm -f %s",filenmae);
  3766. system(str);
  3767. }
  3768. }
  3769. }
  3770. 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);
  3771. #if 1 // for TempStopTransaction
  3772. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3773. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3774. {
  3775. checkTempStopTransaction(gun_index);
  3776. }
  3777. #endif
  3778. }
  3779. }
  3780. }
  3781. else
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3784. {
  3785. tempIndex = 2;
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < AC_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3794. {
  3795. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3796. {
  3797. // Sent unplug message for California pricing logic
  3798. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3799. {
  3800. uint8_t ts[20];
  3801. getNowDatetime(ts);
  3802. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3803. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3804. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3805. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3806. }
  3807. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3808. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3809. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3810. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3811. {
  3812. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3813. if((access(filenmae,F_OK))!=-1)
  3814. {
  3815. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3816. sprintf(str,"rm -f %s",filenmae);
  3817. system(str);
  3818. }
  3819. }
  3820. }
  3821. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3822. #if 1 // for TempStopTransaction
  3823. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3824. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3825. {
  3826. checkTempStopTransaction(gun_index);
  3827. }
  3828. #endif
  3829. }
  3830. }// END
  3831. }
  3832. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  3833. (
  3834. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3835. )
  3836. )
  3837. {
  3838. if(SystemInitial > 0)
  3839. SystemInitial -= 1;
  3840. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3841. sendStatusNotificationRequest(gun_index);
  3842. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  3843. }
  3844. //==============================================
  3845. // CSU Trigger Smart Charging Profilw
  3846. //==============================================
  3847. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3848. {
  3849. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3850. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3851. }
  3852. //==============================================
  3853. // Meter report
  3854. //==============================================
  3855. // Trigger MeterValue
  3856. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3857. {
  3858. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3859. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3860. }
  3861. // ClockAlign MeterValue
  3862. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3863. {
  3864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3865. {
  3866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3867. {
  3868. tempIndex = ((gun_index==2) ? 1: 0);
  3869. }
  3870. else
  3871. {
  3872. tempIndex = gun_index;
  3873. }
  3874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3875. {
  3876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3877. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3878. {
  3879. reqClockAlignMeter[gun_index] = 1;
  3880. }
  3881. }// End for CHAdeMO
  3882. }
  3883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3884. {
  3885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3886. {
  3887. tempIndex = ((gun_index==2) ? 1: 0);
  3888. }
  3889. else
  3890. {
  3891. tempIndex = gun_index;
  3892. }
  3893. for (int index = 0; index < CCS_QUANTITY; index++)
  3894. {
  3895. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3896. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3897. {
  3898. reqClockAlignMeter[gun_index] = 1;
  3899. }
  3900. } // End for CCS
  3901. }
  3902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3903. {
  3904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3905. {
  3906. tempIndex = ((gun_index==2) ? 1: 0);
  3907. }
  3908. else
  3909. {
  3910. tempIndex = gun_index;
  3911. }
  3912. for (int index = 0; index < GB_QUANTITY; index++)
  3913. {
  3914. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3915. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3916. {
  3917. reqClockAlignMeter[gun_index] = 1;
  3918. }
  3919. }// End for GB
  3920. }
  3921. else if(gunType[gun_index] == GUN_TYPE_DO)
  3922. {
  3923. tempIndex = gun_index;
  3924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3925. {
  3926. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3927. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3928. {
  3929. reqClockAlignMeter[gun_index] = 1;
  3930. }
  3931. }
  3932. }
  3933. else
  3934. {
  3935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3936. {
  3937. tempIndex = 2;
  3938. }
  3939. else
  3940. {
  3941. tempIndex = gun_index;
  3942. }
  3943. for (int index = 0; index < AC_QUANTITY; index++)
  3944. {
  3945. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3946. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3947. {
  3948. reqClockAlignMeter[gun_index] = 1;
  3949. }
  3950. }//End for AC
  3951. }
  3952. if(reqClockAlignMeter[gun_index] == 1)
  3953. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3954. }
  3955. // Sample period MeterValue
  3956. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
  3957. {
  3958. //check Transaction active
  3959. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3960. {
  3961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3962. {
  3963. tempIndex = ((gun_index==2) ? 1: 0);
  3964. }
  3965. else
  3966. {
  3967. tempIndex = gun_index;
  3968. }
  3969. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3970. {
  3971. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3972. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3973. {
  3974. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3975. {
  3976. reqSampleMeter[gun_index] = 1;
  3977. }
  3978. }
  3979. }// End for CHAdeMO
  3980. }
  3981. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3982. {
  3983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3984. {
  3985. tempIndex = ((gun_index==2) ? 1: 0);
  3986. }
  3987. else
  3988. {
  3989. tempIndex = gun_index;
  3990. }
  3991. for (int index = 0; index < CCS_QUANTITY; index++)
  3992. {
  3993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3994. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3997. {
  3998. reqSampleMeter[gun_index] = 1;
  3999. }
  4000. }
  4001. } // End for CCS
  4002. }
  4003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4004. {
  4005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4006. {
  4007. tempIndex = ((gun_index==2) ? 1: 0);
  4008. }
  4009. else
  4010. {
  4011. tempIndex = gun_index;
  4012. }
  4013. for (int index = 0; index < GB_QUANTITY; index++)
  4014. {
  4015. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4016. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4017. {
  4018. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4019. {
  4020. reqSampleMeter[gun_index] = 1;
  4021. }
  4022. }
  4023. }// End for GB
  4024. }
  4025. else if(gunType[gun_index] == GUN_TYPE_DO)
  4026. {
  4027. tempIndex = gun_index;
  4028. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4029. {
  4030. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4031. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4032. {
  4033. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4034. {
  4035. reqSampleMeter[gun_index] = 1;
  4036. }
  4037. }
  4038. }
  4039. }
  4040. else
  4041. {
  4042. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4043. {
  4044. tempIndex = 2;
  4045. }
  4046. else
  4047. {
  4048. tempIndex = gun_index;
  4049. }
  4050. for (int index = 0; index < AC_QUANTITY; index++)
  4051. {
  4052. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4053. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4054. {
  4055. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4056. {
  4057. reqSampleMeter[gun_index] = 1;
  4058. }
  4059. }
  4060. }//End for AC
  4061. }
  4062. if(reqSampleMeter[gun_index] == 1)
  4063. {
  4064. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4065. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4066. //storeTempStopTransaction(gun_index);
  4067. }
  4068. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4069. }
  4070. //==============================================
  4071. // Check Connector reserved
  4072. //==============================================
  4073. //===============================
  4074. // Check if Reserve is expired
  4075. //===============================
  4076. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4077. {
  4078. double diff_t;
  4079. struct tm tp;
  4080. // current time
  4081. time_t t = time(NULL);
  4082. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4083. tp.tm_isdst = -1;
  4084. time_t utc = mktime(&tp);
  4085. diff_t = difftime(utc, t);
  4086. if(diff_t <= 0)
  4087. {
  4088. DEBUG_INFO("reserve expired.\n");
  4089. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4090. }
  4091. }//END OF Check if Reserve is expired
  4092. //==========================================
  4093. // csu trigger FirmwareStatusNotificationReq
  4094. //==========================================
  4095. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4096. {
  4097. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4098. }
  4099. //==========================================
  4100. // csu trigger DiagnosticsStatusNotificationReq
  4101. //==========================================
  4102. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4103. {
  4104. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4105. }
  4106. //==========================================
  4107. // csu trigger CancelReservationConf
  4108. //==========================================
  4109. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4110. {
  4111. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4112. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4113. }
  4114. //==========================================
  4115. // csu trigger ChangeAvailabilityConf
  4116. //==========================================
  4117. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4118. {
  4119. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4120. }
  4121. //==========================================
  4122. // csu trigger UnlockConnectorConf
  4123. //==========================================
  4124. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4125. {
  4126. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4127. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4128. }
  4129. //==========================================
  4130. // csu trigger ReserveNowConf
  4131. //==========================================
  4132. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4133. {
  4134. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4135. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4136. }
  4137. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4138. {
  4139. sendSignCertificateRequest();
  4140. }
  4141. }
  4142. }
  4143. //==========================================
  4144. // send request routine
  4145. //==========================================
  4146. int sendAuthorizeRequest(int gun_index)
  4147. {
  4148. mtrace();
  4149. int result = FAIL;
  4150. char message[100]={0};
  4151. char guid[37];
  4152. char tempdata[65]={0};
  4153. DEBUG_INFO("sendAuthorizeRequest...\n");
  4154. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4155. //Local Authorize
  4156. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4157. {
  4158. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4159. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4160. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4161. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4162. result = PASS;
  4163. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4164. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4165. authorizeRetryTimes = 0;
  4166. return result;
  4167. }
  4168. 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))||
  4169. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4170. {
  4171. // Query from cache
  4172. DEBUG_INFO("Authorize from cache.\n");
  4173. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4174. // Query from list
  4175. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4176. {
  4177. DEBUG_INFO("Authorize from list.\n");
  4178. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4179. }
  4180. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4181. {
  4182. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4183. {
  4184. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4185. }
  4186. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4187. {
  4188. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4189. }
  4190. if(!GetOcppConnStatus())
  4191. {
  4192. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4193. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4194. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4195. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4196. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4197. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4198. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4199. authorizeRetryTimes = 0;
  4200. return result;
  4201. }
  4202. }
  4203. else
  4204. {
  4205. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4206. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4207. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4208. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4209. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4210. else
  4211. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4212. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4213. result = PASS;
  4214. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4215. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4216. authorizeRetryTimes = 0;
  4217. return result;
  4218. }
  4219. }
  4220. //initialize struct Authorize
  4221. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4222. //get data from shared memory
  4223. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4224. random_uuid(guid);
  4225. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4226. LWS_Send(message);
  4227. sprintf(tempdata, "Authorize,%d", gun_index);
  4228. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4229. {
  4230. result = PASS;
  4231. DEBUG_INFO("Authorize mapItem pass\n");
  4232. }
  4233. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4234. return result;
  4235. }
  4236. int sendBootNotificationRequest(void)
  4237. {
  4238. mtrace();
  4239. int result = FAIL;
  4240. char message[500]={0}, payload[700]={0};
  4241. char guid[37]={0};
  4242. char tempdata[65]={0};
  4243. // Fill BootNotification fields
  4244. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4245. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4246. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4247. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4248. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4249. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4250. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4251. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4252. ShmOCPP16DataPH->ChargeBoxId
  4253. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4254. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4255. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4256. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4257. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4258. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4259. random_uuid(guid);
  4260. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4261. LWS_Send(message);
  4262. sprintf(tempdata, "BootNotification,0");
  4263. 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*/)
  4264. {
  4265. result = PASS;
  4266. }
  4267. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4268. strcpy(queuedata,message);
  4269. return result;
  4270. }
  4271. int sendDataTransferRequest(int gun_index)
  4272. {
  4273. mtrace();
  4274. char message[1000]={0};
  4275. char guid[37]={0};
  4276. char tempdata[65]={0};
  4277. int result = FAIL;
  4278. random_uuid(guid);
  4279. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4280. MESSAGE_TYPE_CALL,
  4281. guid,
  4282. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4283. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4284. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4285. LWS_Send(message);
  4286. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4287. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4288. {
  4289. result = PASS;
  4290. DEBUG_INFO("DataTransfer mapItem pass\n");
  4291. }
  4292. return result;
  4293. }
  4294. int sendDiagnosticsStatusNotificationRequest(char *status)
  4295. {
  4296. mtrace();
  4297. int result = FAIL;
  4298. char message[110]={0};
  4299. char guid[37]={0};
  4300. char tempdata[65]={0};
  4301. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4302. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4303. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4304. random_uuid(guid);
  4305. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4306. LWS_SendNow(message);
  4307. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4308. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4309. {
  4310. result = PASS;
  4311. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4312. }
  4313. //#ifdef SystemLogMessage
  4314. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4315. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4316. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4317. //#endif
  4318. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4319. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4320. //record status
  4321. if(strcmp(status,"Idle")==0)
  4322. {
  4323. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4324. }
  4325. else if(strcmp(status,"Uploaded")==0)
  4326. {
  4327. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4328. }
  4329. else if(strcmp(status,"UploadFailed")==0)
  4330. {
  4331. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4332. }
  4333. else if(strcmp(status,"Uploading")==0)
  4334. {
  4335. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4336. }
  4337. return result;
  4338. }
  4339. int sendFirmwareStatusNotificationRequest(char *status)
  4340. {
  4341. mtrace();
  4342. int result = FAIL;
  4343. char message[110]={0};
  4344. char guid[37]={0};
  4345. char tempdata[65]={0};
  4346. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4347. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4348. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4349. random_uuid(guid);
  4350. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4351. LWS_SendNow(message);
  4352. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4353. 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*/)
  4354. {
  4355. result = PASS;
  4356. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4357. }
  4358. //#ifdef SystemLogMessage
  4359. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4360. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4361. //#endif
  4362. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4363. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4364. //record status
  4365. if(strcmp(status,"Downloaded")==0)
  4366. {
  4367. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4368. }
  4369. else if(strcmp(status,"DownloadFailed")==0)
  4370. {
  4371. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4372. }
  4373. else if(strcmp(status,"Downloading")==0)
  4374. {
  4375. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4376. }
  4377. else if(strcmp(status,"Idle")==0)
  4378. {
  4379. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4380. }
  4381. else if(strcmp(status,"InstallationFailed")==0)
  4382. {
  4383. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4384. }
  4385. else if(strcmp(status,"Installing")==0)
  4386. {
  4387. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4388. }
  4389. else if(strcmp(status,"Installed")==0)
  4390. {
  4391. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4392. }
  4393. return result;
  4394. }
  4395. int sendHeartbeatRequest(int gun_index)
  4396. {
  4397. mtrace();
  4398. int result = FAIL;
  4399. char message[80]={0};
  4400. char guid[37]={0};
  4401. char tempdata[65]={0};
  4402. random_uuid(guid);
  4403. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4404. , MESSAGE_TYPE_CALL
  4405. , guid );
  4406. LWS_Send(message);
  4407. sprintf(tempdata, "Heartbeat,%d", 0);
  4408. 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*/)
  4409. {
  4410. result = PASS;
  4411. }
  4412. return result;
  4413. }
  4414. int sendStartTransactionRequest(int gun_index)
  4415. {
  4416. mtrace();
  4417. int result = FAIL;
  4418. char message[250]={0};
  4419. char guid[37]={0};
  4420. struct timeval tmnow;
  4421. struct tm *tm;
  4422. char buf[28];//, usec_buf[6];
  4423. char tempdata[65]={0};
  4424. int tempIndex = 0;
  4425. DEBUG_INFO("sendStartTransactionRequest...\n");
  4426. gettimeofday(&tmnow, NULL);
  4427. time_t t;
  4428. t = time(NULL);
  4429. /*UTC time and date*/
  4430. tm = gmtime(&t);
  4431. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4432. #if 0 // remove temporally
  4433. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4434. strcat(buf,".");
  4435. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4436. strcat(buf,usec_buf);
  4437. #endif
  4438. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4439. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4440. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4441. // clear StartTransaction Response
  4442. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4443. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4444. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4445. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4446. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4447. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4448. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4449. {
  4450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4451. {
  4452. tempIndex = ((gun_index==2) ? 1: 0);
  4453. }
  4454. else
  4455. {
  4456. tempIndex = gun_index;
  4457. }
  4458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4459. {
  4460. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4461. {
  4462. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4463. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4464. }
  4465. }
  4466. }
  4467. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4468. {
  4469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4470. {
  4471. tempIndex = ((gun_index==2) ? 1: 0);
  4472. }
  4473. else
  4474. {
  4475. tempIndex = gun_index;
  4476. }
  4477. for (int index = 0; index < CCS_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4480. {
  4481. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4482. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4483. }
  4484. }
  4485. }
  4486. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4487. {
  4488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4489. {
  4490. tempIndex = ((gun_index==2) ? 1: 0);
  4491. }
  4492. else
  4493. {
  4494. tempIndex = gun_index;
  4495. }
  4496. for (int index = 0; index < GB_QUANTITY; index++)
  4497. {
  4498. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4499. {
  4500. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4501. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4502. }
  4503. }
  4504. }
  4505. else if(gunType[gun_index] == GUN_TYPE_DO)
  4506. {
  4507. tempIndex = gun_index;
  4508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4509. {
  4510. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4511. {
  4512. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4513. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4514. }
  4515. }
  4516. }
  4517. else
  4518. {
  4519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4520. {
  4521. tempIndex = 2;
  4522. }
  4523. else
  4524. {
  4525. tempIndex = gun_index;
  4526. }
  4527. for (int index = 0; index < AC_QUANTITY; index++)
  4528. {
  4529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4530. {
  4531. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4532. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4533. }
  4534. }
  4535. }
  4536. random_uuid(guid);
  4537. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4538. {
  4539. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4540. , gun_index +1
  4541. , MESSAGE_TYPE_CALL
  4542. , guid
  4543. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4544. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4545. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4546. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4547. }
  4548. else
  4549. {
  4550. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%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].ReservationId
  4558. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4559. }
  4560. #if 1
  4561. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4562. 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*/)
  4563. {
  4564. result = PASS;
  4565. }
  4566. #endif
  4567. strcpy(queuedata, message);
  4568. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4569. OCPP_insert_transaction_msg(YES, queuedata);
  4570. return result;
  4571. }
  4572. int sendStatusNotificationRequest(int gun_index)
  4573. {
  4574. mtrace();
  4575. int result = FAIL;
  4576. char message[600]={0};
  4577. char guid[37];
  4578. int currentStatus = 0;
  4579. struct timeval tmnow;
  4580. struct tm *tm;
  4581. char buf[28];//, usec_buf[6];
  4582. char tempdata[65]={0};
  4583. int tempIndex = 0;
  4584. uint8_t isStateChanged = TRUE;
  4585. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4586. gettimeofday(&tmnow, NULL);
  4587. time_t t;
  4588. t = time(NULL);
  4589. /*UTC time and date*/
  4590. tm = gmtime(&t);
  4591. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4592. #if 0 // remove temporally
  4593. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4594. strcat(buf,".");
  4595. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4596. strcat(buf,usec_buf);
  4597. #endif
  4598. //printf("%s",buf);
  4599. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4600. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4601. // it's option
  4602. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4603. /*
  4604. enum _SYSTEM_STATUS
  4605. {
  4606. S_BOOTING = 0,
  4607. S_IDLE, = 1
  4608. S_AUTHORIZING, =2
  4609. S_REASSIGN_CHECK, =3
  4610. S_REASSIGN, =4
  4611. S_PRECHARGE, =5
  4612. S_PREPARING_FOR_EV, =6
  4613. S_PREPARING_FOR_EVSE, =7
  4614. S_CHARGING, =8
  4615. S_TERMINATING, =9
  4616. S_COMPLETE, =10
  4617. S_ALARM, =11
  4618. S_FAULT =12
  4619. }
  4620. */
  4621. //check Transaction active
  4622. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4623. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4624. {
  4625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4626. {
  4627. tempIndex = ((gun_index==2) ? 1: 0);
  4628. }
  4629. else
  4630. {
  4631. tempIndex = gun_index;
  4632. }
  4633. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4634. {
  4635. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4636. {
  4637. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4638. {
  4639. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4640. {
  4641. currentStatus = Preparing; //OCPP Status: Preparing
  4642. }
  4643. else
  4644. {
  4645. currentStatus = Available; //OCPP Status: Available
  4646. }
  4647. }
  4648. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4649. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4650. ) //S_PRECHARGE
  4651. {
  4652. currentStatus = Preparing; //OCPP Status: Preparing
  4653. }
  4654. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4655. {
  4656. currentStatus = Charging; //OCPP Status: Charging
  4657. }
  4658. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4659. {
  4660. currentStatus = Finishing; //OCPP Status: Finishing
  4661. }
  4662. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4663. {
  4664. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4665. }
  4666. 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
  4667. {
  4668. currentStatus = Unavailable; //OCPP Status: Unavailable
  4669. }
  4670. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4671. {
  4672. currentStatus = Faulted; //OCPP Status: Faulted
  4673. }
  4674. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4675. {
  4676. currentStatus = Reserved; //OCPP Status: Reserved
  4677. }
  4678. } //end of the same index
  4679. }//end of for CHAdeMO_QUANTITY
  4680. }
  4681. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4682. {
  4683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4684. {
  4685. tempIndex = ((gun_index==2) ? 1: 0);
  4686. }
  4687. else
  4688. {
  4689. tempIndex = gun_index;
  4690. }
  4691. for (int index = 0; index < CCS_QUANTITY; index++)
  4692. {
  4693. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4694. {
  4695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4696. {
  4697. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4698. {
  4699. currentStatus = Preparing; //OCPP Status: Preparing
  4700. }
  4701. else
  4702. {
  4703. currentStatus = Available; //OCPP Status: Available
  4704. }
  4705. }
  4706. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4707. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4708. ) //S_PRECHARGE
  4709. {
  4710. currentStatus = Preparing; //OCPP Status: Preparing
  4711. }
  4712. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4713. {
  4714. currentStatus = Charging; //OCPP Status: Charging
  4715. }
  4716. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4717. {
  4718. currentStatus = Finishing; //OCPP Status: Finishing
  4719. }
  4720. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4721. {
  4722. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4723. }
  4724. 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
  4725. {
  4726. currentStatus = Unavailable; //OCPP Status : Unavailable
  4727. }
  4728. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4729. {
  4730. currentStatus = Faulted; //OCPP Status: Faulted
  4731. }
  4732. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4733. {
  4734. currentStatus = Reserved; //OCPP Status: Reserved
  4735. }
  4736. } //end of the same index
  4737. } // end of for CCS_QUANTITY
  4738. }
  4739. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4740. {
  4741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4742. {
  4743. tempIndex = ((gun_index==2) ? 1: 0);
  4744. }
  4745. else
  4746. {
  4747. tempIndex = gun_index;
  4748. }
  4749. for (int index = 0; index < GB_QUANTITY; index++)
  4750. {
  4751. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4752. {
  4753. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4754. {
  4755. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4756. {
  4757. currentStatus = Preparing; //OCPP Status: Preparing
  4758. }
  4759. else
  4760. {
  4761. currentStatus = Available; //OCPP Status: Available
  4762. }
  4763. }
  4764. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4765. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4766. ) //S_PRECHARGE
  4767. {
  4768. currentStatus = Preparing; //OCPP Status: Preparing
  4769. }
  4770. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4771. {
  4772. currentStatus = Charging; //OCPP Status: Charging
  4773. }
  4774. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4775. {
  4776. currentStatus = Finishing; //OCPP Status: Finishing
  4777. }
  4778. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4779. {
  4780. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4781. }
  4782. 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
  4783. {
  4784. currentStatus = Unavailable; //OCPP Status: Unavailable
  4785. }
  4786. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4787. {
  4788. currentStatus = Faulted; //OCPP Status: Faulted
  4789. }
  4790. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4791. {
  4792. currentStatus = Reserved; //OCPP Status: Reserved
  4793. }
  4794. } //end of the same index
  4795. } // end of for GB_QUANTITY
  4796. }
  4797. else if(gunType[gun_index] == GUN_TYPE_DO)
  4798. {
  4799. tempIndex = gun_index;
  4800. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4801. {
  4802. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4803. {
  4804. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4805. {
  4806. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4807. {
  4808. currentStatus = Preparing; //OCPP Status: Preparing
  4809. }
  4810. else
  4811. {
  4812. currentStatus = Available; //OCPP Status: Available
  4813. }
  4814. }
  4815. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4816. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4817. ) //S_PRECHARGE
  4818. {
  4819. currentStatus = Preparing; //OCPP Status: Preparing
  4820. }
  4821. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4822. {
  4823. currentStatus = Charging; //OCPP Status: Charging
  4824. }
  4825. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4826. {
  4827. currentStatus = Finishing; //OCPP Status: Finishing
  4828. }
  4829. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4830. {
  4831. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4832. }
  4833. 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
  4834. {
  4835. currentStatus = Unavailable; //OCPP Status: Unavailable
  4836. }
  4837. 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
  4838. {
  4839. currentStatus = Faulted; //OCPP Status: Faulted
  4840. }
  4841. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4842. {
  4843. currentStatus = Reserved; //OCPP Status: Reserved
  4844. }
  4845. } //end of the same index
  4846. }
  4847. }
  4848. else
  4849. {
  4850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4851. {
  4852. tempIndex = 2;
  4853. }
  4854. else
  4855. {
  4856. tempIndex = gun_index;
  4857. }
  4858. for (int index = 0; index < AC_QUANTITY; index++)
  4859. {
  4860. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4861. {
  4862. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4863. {
  4864. 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))
  4865. {
  4866. currentStatus = Preparing; //OCPP Status: Preparing
  4867. }
  4868. else
  4869. {
  4870. currentStatus = Available; //OCPP Status: Available
  4871. }
  4872. }
  4873. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4874. {
  4875. currentStatus = Preparing; //OCPP Status: Preparing
  4876. }
  4877. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4878. {
  4879. currentStatus = Charging; //OCPP Status: Charging
  4880. }
  4881. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4882. {
  4883. currentStatus = Finishing; //OCPP Status: Finishing
  4884. }
  4885. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4886. {
  4887. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4888. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4889. else
  4890. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4891. }
  4892. 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
  4893. {
  4894. currentStatus = Unavailable; //OCPP Status: Unavailable
  4895. }
  4896. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4897. {
  4898. currentStatus = Faulted; //OCPP Status: Faulted
  4899. }
  4900. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4901. {
  4902. currentStatus = Reserved; //OCPP Status: Reserved
  4903. }
  4904. }//end of the same index
  4905. }//end of for AC_QUANTITY
  4906. }
  4907. //it's option
  4908. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4909. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4910. {
  4911. isStateChanged = FALSE;
  4912. }
  4913. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4914. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4915. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4916. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4917. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4918. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4919. random_uuid(guid);
  4920. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4921. , MESSAGE_TYPE_CALL
  4922. , guid
  4923. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4924. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4925. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4926. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4927. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4928. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4929. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4930. if((server_sign == TRUE) && isStateChanged)
  4931. {
  4932. LWS_Send(message);
  4933. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4934. 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*/)
  4935. {
  4936. //DEBUG_ERROR("statusNotification mapitem pass");
  4937. result = PASS;
  4938. }
  4939. }
  4940. else
  4941. {
  4942. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4943. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4944. result = PASS;
  4945. }
  4946. return result;
  4947. }
  4948. int sendStopTransactionRequest(int gun_index)
  4949. {
  4950. mtrace();
  4951. int result = FAIL;
  4952. //char message[1500]={0};
  4953. char guid[37]={0};
  4954. char tempdata[65]={0};
  4955. int tempIndex = 0;
  4956. char TempStopTransaction[256];
  4957. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4958. //int idx_sample=0;
  4959. DEBUG_INFO("sendStopTransactionRequest \n");
  4960. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4961. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4962. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4963. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4964. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4965. {
  4966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4967. {
  4968. tempIndex = ((gun_index==2) ? 1: 0);
  4969. }
  4970. else
  4971. {
  4972. tempIndex = gun_index;
  4973. }
  4974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4975. {
  4976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4977. {
  4978. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4979. }
  4980. }// END OF CHAdeMO_QUANTITY
  4981. }
  4982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4983. {
  4984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4985. {
  4986. tempIndex = ((gun_index==2) ? 1: 0);
  4987. }
  4988. else
  4989. {
  4990. tempIndex = gun_index;
  4991. }
  4992. for (int index = 0; index < CCS_QUANTITY; index++)
  4993. {
  4994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4995. {
  4996. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4997. }
  4998. }// END OF CCS_QUANTITY
  4999. }
  5000. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5001. {
  5002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5003. {
  5004. tempIndex = ((gun_index==2) ? 1: 0);
  5005. }
  5006. else
  5007. {
  5008. tempIndex = gun_index;
  5009. }
  5010. for (int index = 0; index < GB_QUANTITY; index++)
  5011. {
  5012. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5013. {
  5014. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5015. }
  5016. }// END OF GB_QUANTITY
  5017. }
  5018. else if(gunType[gun_index] == GUN_TYPE_DO)
  5019. {
  5020. tempIndex = gun_index;
  5021. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5022. {
  5023. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5024. {
  5025. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5026. }
  5027. }// END OF GB_QUANTITY
  5028. }
  5029. else
  5030. {
  5031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5032. {
  5033. tempIndex = 2;
  5034. }
  5035. else
  5036. {
  5037. tempIndex = gun_index;
  5038. }
  5039. for (int index = 0; index < AC_QUANTITY; index++)
  5040. {
  5041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5042. {
  5043. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5044. }
  5045. }// END OF AC_QUANTITY
  5046. }
  5047. //====================================== Stop Transaction Time =====================================================
  5048. struct timeval tmnow;
  5049. struct tm *tm;
  5050. char buf[28];//, usec_buf[6];
  5051. gettimeofday(&tmnow, NULL);
  5052. time_t t;
  5053. t = time(NULL);
  5054. /*UTC time and date*/
  5055. tm = gmtime(&t);
  5056. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5058. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5059. random_uuid(guid);
  5060. /***********************************transactionData******************************************************/
  5061. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5063. //=================================
  5064. // Transaction_Begin
  5065. //=================================
  5066. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5067. {
  5068. //============================================ Energy.Active.Import.Interval ================================
  5069. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5070. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5072. 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*/]);
  5073. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5074. 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))
  5075. {
  5076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5077. }
  5078. else
  5079. {
  5080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5081. }
  5082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5084. }
  5085. //=================================
  5086. // Transaction_End
  5087. //=================================
  5088. // ================================= Current.Import L1 ===============================================
  5089. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5090. {
  5091. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5093. {
  5094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5095. {
  5096. tempIndex = ((gun_index==2) ? 1: 0);
  5097. }
  5098. else
  5099. {
  5100. tempIndex = gun_index;
  5101. }
  5102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5103. {
  5104. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5105. {
  5106. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5107. }
  5108. }// End of for CHAdeMO_QUANTITY
  5109. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5110. }
  5111. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5112. {
  5113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5114. {
  5115. tempIndex = ((gun_index==2) ? 1: 0);
  5116. }
  5117. else
  5118. {
  5119. tempIndex = gun_index;
  5120. }
  5121. for (int index = 0; index < CCS_QUANTITY; index++)
  5122. {
  5123. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5124. {
  5125. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5126. }
  5127. }// End of for CCS_QUANTITY
  5128. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5129. }
  5130. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5131. {
  5132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5133. {
  5134. tempIndex = ((gun_index==2) ? 1: 0);
  5135. }
  5136. else
  5137. {
  5138. tempIndex = gun_index;
  5139. }
  5140. for (int index = 0; index < GB_QUANTITY; index++)
  5141. {
  5142. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5143. {
  5144. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5145. }
  5146. }// End of for GB_QUANTITY
  5147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5148. }
  5149. else if(gunType[gun_index] == GUN_TYPE_DO)
  5150. {
  5151. tempIndex = gun_index;
  5152. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5153. {
  5154. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5155. {
  5156. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5157. }
  5158. }
  5159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5160. }
  5161. else
  5162. {
  5163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5164. {
  5165. tempIndex = 2;
  5166. }
  5167. else
  5168. {
  5169. tempIndex = gun_index;
  5170. }
  5171. for (int index = 0; index < AC_QUANTITY; index++)
  5172. {
  5173. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5174. {
  5175. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5176. }
  5177. }// End of for AC_QUANTITY
  5178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5179. }
  5180. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5182. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5185. }
  5186. // ================================= Energy.Active.Import.Interval ==============================================
  5187. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5188. {
  5189. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5190. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5191. {
  5192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5193. {
  5194. tempIndex = ((gun_index==2) ? 1: 0);
  5195. }
  5196. else
  5197. {
  5198. tempIndex = gun_index;
  5199. }
  5200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5201. {
  5202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5203. {
  5204. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5205. }
  5206. }// END OF CHAdeMO_QUANTITY
  5207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5208. }
  5209. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5210. {
  5211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5212. {
  5213. tempIndex = ((gun_index==2) ? 1: 0);
  5214. }
  5215. else
  5216. {
  5217. tempIndex = gun_index;
  5218. }
  5219. for (int index = 0; index < CCS_QUANTITY; index++)
  5220. {
  5221. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5222. {
  5223. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5224. }
  5225. }// END OF CCS_QUANTITY
  5226. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5227. }
  5228. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5229. {
  5230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5231. {
  5232. tempIndex = ((gun_index==2) ? 1: 0);
  5233. }
  5234. else
  5235. {
  5236. tempIndex = gun_index;
  5237. }
  5238. for (int index = 0; index < GB_QUANTITY; index++)
  5239. {
  5240. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5241. {
  5242. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5243. }
  5244. }// END OF GB_QUANTITY
  5245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5246. }
  5247. else if(gunType[gun_index] == GUN_TYPE_DO)
  5248. {
  5249. tempIndex = gun_index;
  5250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5251. {
  5252. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5253. {
  5254. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5255. }
  5256. }
  5257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5258. }
  5259. else
  5260. {
  5261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5262. {
  5263. tempIndex = 2;
  5264. }
  5265. else
  5266. {
  5267. tempIndex = gun_index;
  5268. }
  5269. for (int index = 0; index < AC_QUANTITY; index++)
  5270. {
  5271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5272. {
  5273. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5274. }
  5275. }// END OF AC_QUANTITY
  5276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5277. }
  5278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5283. }
  5284. //=================================== Power.Active.Import ==================================================
  5285. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5286. {
  5287. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5288. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5289. {
  5290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5291. {
  5292. tempIndex = ((gun_index==2) ? 1: 0);
  5293. }
  5294. else
  5295. {
  5296. tempIndex = gun_index;
  5297. }
  5298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5299. {
  5300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5301. {
  5302. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5303. }
  5304. } // End for CHAdeMO_QUANTITY
  5305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5306. }
  5307. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5308. {
  5309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5310. {
  5311. tempIndex = ((gun_index==2) ? 1: 0);
  5312. }
  5313. else
  5314. {
  5315. tempIndex = gun_index;
  5316. }
  5317. for (int index = 0; index < CCS_QUANTITY; index++)
  5318. {
  5319. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5320. {
  5321. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5322. }
  5323. } // END for CCS_QUANTITY
  5324. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5325. }
  5326. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5327. {
  5328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5329. {
  5330. tempIndex = ((gun_index==2) ? 1: 0);
  5331. }
  5332. else
  5333. {
  5334. tempIndex = gun_index;
  5335. }
  5336. for (int index = 0; index < GB_QUANTITY; index++)
  5337. {
  5338. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5339. {
  5340. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5341. }
  5342. }// END for GB_QUANTITY
  5343. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5344. }
  5345. else if(gunType[gun_index] == GUN_TYPE_DO)
  5346. {
  5347. tempIndex = gun_index;
  5348. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5349. {
  5350. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5351. {
  5352. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5353. }
  5354. }
  5355. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5356. }
  5357. else
  5358. {
  5359. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5360. {
  5361. tempIndex = 2;
  5362. }
  5363. else
  5364. {
  5365. tempIndex = gun_index;
  5366. }
  5367. for (int index = 0; index < AC_QUANTITY; index++)
  5368. {
  5369. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5370. {
  5371. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5372. }
  5373. } // END for AC_QUANTITY
  5374. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5375. }
  5376. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5378. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5381. }
  5382. //============================ Voltage L1 ====================================
  5383. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5384. {
  5385. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5386. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5387. {
  5388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5389. {
  5390. tempIndex = ((gun_index==2) ? 1: 0);
  5391. }
  5392. else
  5393. {
  5394. tempIndex = gun_index;
  5395. }
  5396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5397. {
  5398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5399. {
  5400. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5401. }
  5402. } // END OF FOR CHAdeMO_QUANTITY
  5403. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5404. }
  5405. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5408. {
  5409. tempIndex = ((gun_index==2) ? 1: 0);
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < CCS_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5418. {
  5419. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5420. }
  5421. } // END OF FOR CCS_QUANTITY
  5422. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5423. }
  5424. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5425. {
  5426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5427. {
  5428. tempIndex = ((gun_index==2) ? 1: 0);
  5429. }
  5430. else
  5431. {
  5432. tempIndex = gun_index;
  5433. }
  5434. for (int index = 0; index < GB_QUANTITY; index++)
  5435. {
  5436. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5437. {
  5438. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5439. }
  5440. } // END OF FOR GB_QUANTITY
  5441. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5442. }
  5443. else if(gunType[gun_index] == GUN_TYPE_DO)
  5444. {
  5445. tempIndex = gun_index;
  5446. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5447. {
  5448. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5449. {
  5450. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5451. }
  5452. }
  5453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5454. }
  5455. else
  5456. {
  5457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5458. {
  5459. tempIndex = 2;
  5460. }
  5461. else
  5462. {
  5463. tempIndex = gun_index;
  5464. }
  5465. for (int index = 0; index < AC_QUANTITY; index++)
  5466. {
  5467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5468. {
  5469. 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
  5470. }
  5471. } // END OF FOR AC_QUANTITY
  5472. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5473. }
  5474. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5476. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5479. }
  5480. //====================== End SoC ================================
  5481. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5482. {
  5483. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5484. 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))
  5485. {
  5486. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5487. {
  5488. tempIndex = ((gun_index==2) ? 1: 0);
  5489. }
  5490. else
  5491. {
  5492. tempIndex = gun_index;
  5493. }
  5494. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5495. {
  5496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5497. {
  5498. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5499. {
  5500. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5501. }
  5502. }
  5503. }
  5504. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5505. {
  5506. for (int index = 0; index < CCS_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5509. {
  5510. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5511. }
  5512. }
  5513. }
  5514. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5515. {
  5516. for (int index = 0; index < GB_QUANTITY; index++)
  5517. {
  5518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5519. {
  5520. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5521. }
  5522. }
  5523. }
  5524. else if(gunType[gun_index] == GUN_TYPE_DO)
  5525. {
  5526. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5527. {
  5528. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5529. {
  5530. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5531. }
  5532. }
  5533. }
  5534. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5535. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5536. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5537. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5539. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5540. } // END FOR DC CASE
  5541. }
  5542. // ================================= Current.Import L2 ===============================================
  5543. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5544. {
  5545. // AC 3 phse L2 current
  5546. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5547. {
  5548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5549. {
  5550. tempIndex = 2;
  5551. }
  5552. else
  5553. {
  5554. tempIndex = gun_index;
  5555. }
  5556. for (int index = 0; index < AC_QUANTITY; index++)
  5557. {
  5558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5559. {
  5560. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5561. }
  5562. }// End of for AC_QUANTITY
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5564. }
  5565. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5570. }
  5571. // ================================= Current.Import L3 ===============================================
  5572. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5573. {
  5574. // AC 3 phse L3 current
  5575. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5576. {
  5577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5578. {
  5579. tempIndex = 2;
  5580. }
  5581. else
  5582. {
  5583. tempIndex = gun_index;
  5584. }
  5585. for (int index = 0; index < AC_QUANTITY; index++)
  5586. {
  5587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5588. {
  5589. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5590. }
  5591. }// End of for AC_QUANTITY
  5592. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5593. }
  5594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5596. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5599. }
  5600. //============================ Voltage L2 ====================================
  5601. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5602. {
  5603. // AC 3 phse L2 voltage
  5604. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5605. {
  5606. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5607. {
  5608. tempIndex = 2;
  5609. }
  5610. else
  5611. {
  5612. tempIndex = gun_index;
  5613. }
  5614. for (int index = 0; index < AC_QUANTITY; index++)
  5615. {
  5616. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5617. {
  5618. 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
  5619. }
  5620. } // END OF FOR AC_QUANTITY
  5621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5622. }
  5623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5628. }
  5629. //============================ Voltage L3 ====================================
  5630. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5631. {
  5632. // AC 3 phse L3 voltage
  5633. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5634. {
  5635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5636. {
  5637. tempIndex = 2;
  5638. }
  5639. else
  5640. {
  5641. tempIndex = gun_index;
  5642. }
  5643. for (int index = 0; index < AC_QUANTITY; index++)
  5644. {
  5645. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5646. {
  5647. 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
  5648. }
  5649. } // END OF FOR AC_QUANTITY
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5651. }
  5652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5657. }
  5658. //====================== Start SoC ================================
  5659. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5660. {
  5661. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5662. 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))
  5663. {
  5664. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5665. {
  5666. tempIndex = ((gun_index==2) ? 1: 0);
  5667. }
  5668. else
  5669. {
  5670. tempIndex = gun_index;
  5671. }
  5672. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5673. {
  5674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5675. {
  5676. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5677. {
  5678. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5679. }
  5680. }
  5681. }
  5682. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5683. {
  5684. for (int index = 0; index < CCS_QUANTITY; index++)
  5685. {
  5686. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5687. {
  5688. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5689. }
  5690. }
  5691. }
  5692. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5693. {
  5694. for (int index = 0; index < GB_QUANTITY; index++)
  5695. {
  5696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5697. {
  5698. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5699. }
  5700. }
  5701. }
  5702. else if(gunType[gun_index] == GUN_TYPE_DO)
  5703. {
  5704. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5705. {
  5706. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5707. {
  5708. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5709. }
  5710. }
  5711. }
  5712. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5713. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5714. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5718. } // END FOR DC CASE
  5719. }
  5720. //================================================ Message create ====================================================
  5721. json_object *StopTransaction = json_object_new_object();
  5722. json_object *transactionDatas = json_object_new_array();
  5723. json_object *sampledValues = json_object_new_array();
  5724. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5725. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5726. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5727. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5728. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5729. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5730. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5731. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5732. {
  5733. json_object *transactionData = json_object_new_object();
  5734. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5735. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5736. {
  5737. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5738. {
  5739. json_object *sampledValue = json_object_new_object();
  5740. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5741. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5742. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5743. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5744. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5745. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5746. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5747. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5748. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5749. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5750. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5751. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5752. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5753. json_object_array_add(sampledValues, sampledValue);
  5754. }
  5755. }
  5756. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5757. json_object_array_add(transactionDatas, transactionData);
  5758. }
  5759. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5760. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5761. ,MESSAGE_TYPE_CALL
  5762. ,guid
  5763. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5764. json_object_put(StopTransaction);
  5765. #if 1 // for TempStopTransaction
  5766. //Delete TempStopTransaction
  5767. if((access(TempStopTransaction,F_OK))!=-1)
  5768. {
  5769. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5770. }
  5771. #endif
  5772. #if 1
  5773. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5774. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5775. {
  5776. result = PASS;
  5777. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5778. }
  5779. #endif
  5780. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5781. OCPP_insert_transaction_msg(NO, queuedata);
  5782. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5783. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5784. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5785. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5786. {
  5787. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5788. }
  5789. //for test
  5790. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5791. return result;
  5792. }
  5793. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5794. {
  5795. mtrace();
  5796. int result = FAIL;
  5797. char guid[37]={0};
  5798. char tempdata[65]={0};
  5799. int tempIndex = 0;
  5800. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5801. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5802. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5803. //set value
  5804. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5805. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5806. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5807. -1);
  5808. random_uuid(guid);
  5809. //UTC Date time
  5810. struct timeval tmnow;
  5811. struct tm *tm;
  5812. char buf[28];//, usec_buf[6];
  5813. gettimeofday(&tmnow, NULL);
  5814. time_t t;
  5815. t = time(NULL);
  5816. /*UTC time and date*/
  5817. tm = gmtime(&t);
  5818. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5819. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5820. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5821. //********************************(1)Current.Import L1************************************************/
  5822. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5823. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5824. (dataType == ReadingContext_Trigger))
  5825. {
  5826. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5827. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5828. {
  5829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5830. {
  5831. tempIndex = ((gun_index==2) ? 1: 0);
  5832. }
  5833. else
  5834. {
  5835. tempIndex = gun_index;
  5836. }
  5837. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5838. {
  5839. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5840. {
  5841. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5842. }
  5843. }
  5844. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5845. }
  5846. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5847. {
  5848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5849. {
  5850. tempIndex = ((gun_index==2) ? 1: 0);
  5851. }
  5852. else
  5853. {
  5854. tempIndex = gun_index;
  5855. }
  5856. for (int index = 0; index < CCS_QUANTITY; index++)
  5857. {
  5858. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5859. {
  5860. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5861. }
  5862. }
  5863. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5864. }
  5865. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5866. {
  5867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5868. {
  5869. tempIndex = ((gun_index==2) ? 1: 0);
  5870. }
  5871. else
  5872. {
  5873. tempIndex = gun_index;
  5874. }
  5875. for (int index = 0; index < GB_QUANTITY; index++)
  5876. {
  5877. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5878. {
  5879. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5880. }
  5881. }
  5882. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5883. }
  5884. else if(gunType[gun_index] == GUN_TYPE_DO)
  5885. {
  5886. tempIndex = gun_index;
  5887. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5888. {
  5889. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5890. {
  5891. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5892. }
  5893. }
  5894. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5895. }
  5896. else
  5897. {
  5898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5899. {
  5900. tempIndex = 2;
  5901. }
  5902. else
  5903. {
  5904. tempIndex = gun_index;
  5905. }
  5906. for (int index = 0; index < AC_QUANTITY; index++)
  5907. {
  5908. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5909. {
  5910. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5911. }
  5912. }
  5913. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5914. }
  5915. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5916. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5917. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5919. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5920. }
  5921. //********************************(2)Energy.Active.Import.Register ************************************************/
  5922. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5923. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5924. (dataType == ReadingContext_Trigger))
  5925. {
  5926. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5927. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5928. {
  5929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5930. {
  5931. tempIndex = ((gun_index==2) ? 1: 0);
  5932. }
  5933. else
  5934. {
  5935. tempIndex = gun_index;
  5936. }
  5937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5938. {
  5939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5940. {
  5941. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5942. }
  5943. }
  5944. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5945. }
  5946. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5947. {
  5948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5949. {
  5950. tempIndex = ((gun_index==2) ? 1: 0);
  5951. }
  5952. else
  5953. {
  5954. tempIndex = gun_index;
  5955. }
  5956. for (int index = 0; index < CCS_QUANTITY; index++)
  5957. {
  5958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5959. {
  5960. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5961. }
  5962. }
  5963. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5964. }
  5965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5966. {
  5967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5968. {
  5969. tempIndex = ((gun_index==2) ? 1: 0);
  5970. }
  5971. else
  5972. {
  5973. tempIndex = gun_index;
  5974. }
  5975. for (int index = 0; index < GB_QUANTITY; index++)
  5976. {
  5977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5978. {
  5979. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5980. }
  5981. }
  5982. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5983. }
  5984. else if(gunType[gun_index] == GUN_TYPE_DO)
  5985. {
  5986. tempIndex = gun_index;
  5987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5988. {
  5989. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5990. {
  5991. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5992. }
  5993. }
  5994. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5995. }
  5996. else
  5997. {
  5998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5999. {
  6000. tempIndex = 2;
  6001. }
  6002. else
  6003. {
  6004. tempIndex = gun_index;
  6005. }
  6006. for (int index = 0; index < AC_QUANTITY; index++)
  6007. {
  6008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6009. {
  6010. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6011. }
  6012. }
  6013. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6014. }
  6015. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6016. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6017. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6020. }
  6021. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6022. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6023. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6024. (dataType == ReadingContext_Trigger))
  6025. {
  6026. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6027. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6028. {
  6029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6030. {
  6031. tempIndex = ((gun_index==2) ? 1: 0);
  6032. }
  6033. else
  6034. {
  6035. tempIndex = gun_index;
  6036. }
  6037. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6038. {
  6039. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6040. {
  6041. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6042. }
  6043. } // END OF FOR CHAdeMO_QUANTITY
  6044. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6045. }
  6046. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6047. {
  6048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6049. {
  6050. tempIndex = ((gun_index==2) ? 1: 0);
  6051. }
  6052. else
  6053. {
  6054. tempIndex = gun_index;
  6055. }
  6056. for (int index = 0; index < CCS_QUANTITY; index++)
  6057. {
  6058. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6059. {
  6060. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6061. }
  6062. } // END OF CCS_QUANTITY
  6063. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6064. }
  6065. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6066. {
  6067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6068. {
  6069. tempIndex = ((gun_index==2) ? 1: 0);
  6070. }
  6071. else
  6072. {
  6073. tempIndex = gun_index;
  6074. }
  6075. for (int index = 0; index < GB_QUANTITY; index++)
  6076. {
  6077. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6078. {
  6079. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6080. }
  6081. } // END OF GB_QUANTITY
  6082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6083. }
  6084. else if(gunType[gun_index] == GUN_TYPE_DO)
  6085. {
  6086. tempIndex = gun_index;
  6087. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6088. {
  6089. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6090. {
  6091. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6092. }
  6093. }
  6094. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6095. }
  6096. else
  6097. {
  6098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6099. {
  6100. tempIndex = 2;
  6101. }
  6102. else
  6103. {
  6104. tempIndex = gun_index;
  6105. }
  6106. for (int index = 0; index < AC_QUANTITY; index++)
  6107. {
  6108. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6109. {
  6110. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6111. }
  6112. }
  6113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6114. }
  6115. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6117. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6119. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6120. }
  6121. //********************************(4)Power.Active.Import************************************************/
  6122. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6123. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6124. (dataType == ReadingContext_Trigger))
  6125. {
  6126. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6127. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6128. {
  6129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6130. {
  6131. tempIndex = ((gun_index==2) ? 1: 0);
  6132. }
  6133. else
  6134. {
  6135. tempIndex = gun_index;
  6136. }
  6137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6140. {
  6141. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6142. }
  6143. } // END OF FOR
  6144. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6145. }
  6146. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6147. {
  6148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6149. {
  6150. tempIndex = ((gun_index==2) ? 1: 0);
  6151. }
  6152. else
  6153. {
  6154. tempIndex = gun_index;
  6155. }
  6156. for (int index = 0; index < CCS_QUANTITY; index++)
  6157. {
  6158. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6159. {
  6160. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6161. }
  6162. }
  6163. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6164. }
  6165. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6166. {
  6167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6168. {
  6169. tempIndex = ((gun_index==2) ? 1: 0);
  6170. }
  6171. else
  6172. {
  6173. tempIndex = gun_index;
  6174. }
  6175. for (int index = 0; index < GB_QUANTITY; index++)
  6176. {
  6177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6178. {
  6179. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6180. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6181. }
  6182. }
  6183. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6184. }
  6185. else if(gunType[gun_index] == GUN_TYPE_DO)
  6186. {
  6187. tempIndex = gun_index;
  6188. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6189. {
  6190. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6191. {
  6192. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6193. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6194. }
  6195. }
  6196. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6197. }
  6198. else
  6199. {
  6200. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6201. {
  6202. tempIndex = 2;
  6203. }
  6204. else
  6205. {
  6206. tempIndex = gun_index;
  6207. }
  6208. for (int index = 0; index < AC_QUANTITY; index++)
  6209. {
  6210. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6211. {
  6212. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6213. }
  6214. }
  6215. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6216. }
  6217. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6222. }
  6223. //***********************************************(5)VOLTAGE L1******************************************************/
  6224. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6225. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6226. (dataType == ReadingContext_Trigger))
  6227. {
  6228. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6229. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6230. {
  6231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6232. {
  6233. tempIndex = ((gun_index==2) ? 1: 0);
  6234. }
  6235. else
  6236. {
  6237. tempIndex = gun_index;
  6238. }
  6239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6240. {
  6241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6242. {
  6243. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6244. }
  6245. }
  6246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6247. }
  6248. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6249. {
  6250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6251. {
  6252. tempIndex = ((gun_index==2) ? 1: 0);
  6253. }
  6254. else
  6255. {
  6256. tempIndex = gun_index;
  6257. }
  6258. for (int index = 0; index < CCS_QUANTITY; index++)
  6259. {
  6260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6261. {
  6262. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6263. }
  6264. }
  6265. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6266. }
  6267. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6268. {
  6269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6270. {
  6271. tempIndex = ((gun_index==2) ? 1: 0);
  6272. }
  6273. else
  6274. {
  6275. tempIndex = gun_index;
  6276. }
  6277. for (int index = 0; index < GB_QUANTITY; index++)
  6278. {
  6279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6280. {
  6281. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6282. }
  6283. }
  6284. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6285. }
  6286. else if(gunType[gun_index] == GUN_TYPE_DO)
  6287. {
  6288. tempIndex = gun_index;
  6289. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6290. {
  6291. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6292. {
  6293. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6294. }
  6295. }
  6296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6297. }
  6298. else
  6299. {
  6300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6301. {
  6302. tempIndex = 2;
  6303. }
  6304. else
  6305. {
  6306. tempIndex = gun_index;
  6307. }
  6308. for (int index = 0; index < AC_QUANTITY; index++)
  6309. {
  6310. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6311. {
  6312. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6313. }
  6314. }
  6315. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6316. }
  6317. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6318. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6319. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6320. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6321. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6322. }
  6323. //***********************************************(6)SOC******************************************************/
  6324. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6325. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6326. (dataType == ReadingContext_Trigger))
  6327. {
  6328. 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))
  6329. {
  6330. //idx_sample=5;
  6331. //sampledValue = NULL;
  6332. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6333. {
  6334. tempIndex = ((gun_index==2) ? 1: 0);
  6335. }
  6336. else
  6337. {
  6338. tempIndex = gun_index;
  6339. }
  6340. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6341. {
  6342. //tempIndex = ((gun_index==2) ? 1: 0);
  6343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6344. {
  6345. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6346. {
  6347. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6348. }
  6349. }
  6350. }
  6351. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6352. {
  6353. //tempIndex = ((gun_index==2) ? 1: 0);
  6354. for (int index = 0; index < CCS_QUANTITY; index++)
  6355. {
  6356. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6357. {
  6358. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6359. }
  6360. }
  6361. }
  6362. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6363. {
  6364. //tempIndex = ((gun_index==2) ? 1: 0);
  6365. for (int index = 0; index < GB_QUANTITY; index++)
  6366. {
  6367. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6368. {
  6369. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6370. }
  6371. }
  6372. }
  6373. else if(gunType[gun_index] == GUN_TYPE_DO)
  6374. {
  6375. //tempIndex = ((gun_index==2) ? 1: 0);
  6376. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6379. {
  6380. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6381. }
  6382. }
  6383. }
  6384. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6385. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6386. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6387. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6388. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6389. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6390. }
  6391. }
  6392. //********************************(7)Current.Import L2************************************************/
  6393. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6394. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6395. (dataType == ReadingContext_Trigger))
  6396. {
  6397. // Only for AC 3 phase
  6398. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6399. {
  6400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6401. {
  6402. tempIndex = 2;
  6403. }
  6404. else
  6405. {
  6406. tempIndex = gun_index;
  6407. }
  6408. for (int index = 0; index < AC_QUANTITY; index++)
  6409. {
  6410. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6411. {
  6412. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6413. }
  6414. }
  6415. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6416. }
  6417. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6419. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6422. }
  6423. //********************************(8)Current.Import L3************************************************/
  6424. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6425. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6426. (dataType == ReadingContext_Trigger))
  6427. {
  6428. // Only for AC 3 phase
  6429. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6430. {
  6431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6432. {
  6433. tempIndex = 2;
  6434. }
  6435. else
  6436. {
  6437. tempIndex = gun_index;
  6438. }
  6439. for (int index = 0; index < AC_QUANTITY; index++)
  6440. {
  6441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6442. {
  6443. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6444. }
  6445. }
  6446. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6447. }
  6448. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6450. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6453. }
  6454. //***********************************************(9)VOLTAGE L2******************************************************/
  6455. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6456. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6457. (dataType == ReadingContext_Trigger))
  6458. {
  6459. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6460. {
  6461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6462. {
  6463. tempIndex = 2;
  6464. }
  6465. else
  6466. {
  6467. tempIndex = gun_index;
  6468. }
  6469. for (int index = 0; index < AC_QUANTITY; index++)
  6470. {
  6471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6472. {
  6473. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6474. }
  6475. }
  6476. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6477. }
  6478. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6483. }
  6484. //***********************************************(10)VOLTAGE L3******************************************************/
  6485. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6486. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6487. (dataType == ReadingContext_Trigger))
  6488. {
  6489. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6490. {
  6491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6492. {
  6493. tempIndex = 2;
  6494. }
  6495. else
  6496. {
  6497. tempIndex = gun_index;
  6498. }
  6499. for (int index = 0; index < AC_QUANTITY; index++)
  6500. {
  6501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6502. {
  6503. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6504. }
  6505. }
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6507. }
  6508. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6513. }
  6514. //***********************************************(11)Current.Offered******************************************************/
  6515. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6516. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6517. (dataType == ReadingContext_Trigger))
  6518. {
  6519. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6520. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6521. {
  6522. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6523. {
  6524. tempIndex = ((gun_index==2) ? 1: 0);
  6525. }
  6526. else
  6527. {
  6528. tempIndex = gun_index;
  6529. }
  6530. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6531. {
  6532. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6533. {
  6534. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6535. }
  6536. } // END OF FOR CHAdeMO_QUANTITY
  6537. }
  6538. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6539. {
  6540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6541. {
  6542. tempIndex = ((gun_index==2) ? 1: 0);
  6543. }
  6544. else
  6545. {
  6546. tempIndex = gun_index;
  6547. }
  6548. for (int index = 0; index < CCS_QUANTITY; index++)
  6549. {
  6550. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6551. {
  6552. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6553. }
  6554. } // END OF CCS_QUANTITY
  6555. }
  6556. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6557. {
  6558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6559. {
  6560. tempIndex = ((gun_index==2) ? 1: 0);
  6561. }
  6562. else
  6563. {
  6564. tempIndex = gun_index;
  6565. }
  6566. for (int index = 0; index < GB_QUANTITY; index++)
  6567. {
  6568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6569. {
  6570. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6571. }
  6572. } // END OF GB_QUANTITY
  6573. }
  6574. else if(gunType[gun_index] == GUN_TYPE_DO)
  6575. {
  6576. tempIndex = gun_index;
  6577. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6578. {
  6579. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6580. {
  6581. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6582. }
  6583. }
  6584. }
  6585. else
  6586. {
  6587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6588. {
  6589. tempIndex = 2;
  6590. }
  6591. else
  6592. {
  6593. tempIndex = gun_index;
  6594. }
  6595. for (int index = 0; index < AC_QUANTITY; index++)
  6596. {
  6597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6598. {
  6599. uint16_t currentOffer;
  6600. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6601. {
  6602. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6603. }
  6604. else
  6605. {
  6606. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6607. }
  6608. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6609. }
  6610. }
  6611. }
  6612. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6613. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6614. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6615. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6616. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6617. }
  6618. //***********************************************(12)Power.Offered******************************************************/
  6619. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6620. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6621. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6622. {
  6623. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6624. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6625. {
  6626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6627. {
  6628. tempIndex = ((gun_index==2) ? 1: 0);
  6629. }
  6630. else
  6631. {
  6632. tempIndex = gun_index;
  6633. }
  6634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6635. {
  6636. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6637. {
  6638. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6639. }
  6640. } // END OF FOR CHAdeMO_QUANTITY
  6641. }
  6642. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6643. {
  6644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6645. {
  6646. tempIndex = ((gun_index==2) ? 1: 0);
  6647. }
  6648. else
  6649. {
  6650. tempIndex = gun_index;
  6651. }
  6652. for (int index = 0; index < CCS_QUANTITY; index++)
  6653. {
  6654. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6655. {
  6656. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6657. }
  6658. } // END OF CCS_QUANTITY
  6659. }
  6660. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6661. {
  6662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6663. {
  6664. tempIndex = ((gun_index==2) ? 1: 0);
  6665. }
  6666. else
  6667. {
  6668. tempIndex = gun_index;
  6669. }
  6670. for (int index = 0; index < GB_QUANTITY; index++)
  6671. {
  6672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6673. {
  6674. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6675. }
  6676. } // END OF GB_QUANTITY
  6677. }
  6678. else if(gunType[gun_index] == GUN_TYPE_DO)
  6679. {
  6680. tempIndex = gun_index;
  6681. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6682. {
  6683. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6684. {
  6685. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6686. }
  6687. }
  6688. }
  6689. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6690. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6691. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6692. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6693. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6694. }
  6695. // Message create ====================================================================================================
  6696. if(TRUE)
  6697. {
  6698. json_object *MeterValueReq = json_object_new_object();
  6699. json_object *MeterValues = json_object_new_array();
  6700. json_object *sampledValues = json_object_new_array();
  6701. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6702. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6703. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6704. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6705. {
  6706. json_object *MeterValue = json_object_new_object();
  6707. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6708. {
  6709. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6710. {
  6711. json_object *sampledValue = json_object_new_object();
  6712. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6713. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6714. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6715. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6716. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6717. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6718. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6719. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6720. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6721. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6722. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6723. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6724. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6725. json_object_array_add(sampledValues, sampledValue);
  6726. }
  6727. }
  6728. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6729. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6730. json_object_array_add(MeterValues, MeterValue);
  6731. }
  6732. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6733. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6734. ,gun_index + 1
  6735. ,MESSAGE_TYPE_CALL
  6736. ,guid
  6737. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6738. json_object_put(MeterValueReq);
  6739. }
  6740. // Put request guid to hash map
  6741. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6742. 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*/)
  6743. {
  6744. result = PASS;
  6745. //DEBUG_INFO("MeterValues mapitem pass\n");
  6746. }
  6747. if((dataType != ReadingContext_Trigger) &&
  6748. (dataType != ReadingContext_Sample_Clock) &&
  6749. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6750. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6751. else
  6752. {
  6753. if(FirstHeartBeat)
  6754. LWS_Send(queuedata +2);
  6755. }
  6756. return result;
  6757. }
  6758. int sendLogStatusNotificationRequest(char *status)
  6759. {
  6760. mtrace();
  6761. int result = PASS;
  6762. char message[4096]={0};
  6763. char guid[37]={0};
  6764. char tempdata[128]={0};
  6765. json_object *LogStatusNotification = json_object_new_object();
  6766. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6767. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6768. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6769. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6770. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6771. random_uuid(guid);
  6772. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6773. json_object_put(LogStatusNotification);
  6774. LWS_Send(message);
  6775. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6776. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6777. {
  6778. result = PASS;
  6779. }
  6780. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6781. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6782. return result;
  6783. }
  6784. int sendSecurityEventNotificationRequest()
  6785. {
  6786. mtrace();
  6787. int result = PASS;
  6788. char message[4096]={0};
  6789. char guid[37]={0};
  6790. char tempdata[128]={0};
  6791. json_object *SecurityEventNotification = json_object_new_object();
  6792. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6793. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6794. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6795. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6796. random_uuid(guid);
  6797. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6798. json_object_put(SecurityEventNotification);
  6799. LWS_Send(message);
  6800. sprintf(tempdata, "SecurityEventNotification,0");
  6801. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6802. {
  6803. result = PASS;
  6804. }
  6805. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6806. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6807. return result;
  6808. }
  6809. int sendSignCertificateRequest()
  6810. {
  6811. mtrace();
  6812. int result = PASS;
  6813. char message[4096]={0};
  6814. char guid[37]={0};
  6815. char tempdata[128]={0};
  6816. json_object *SignCertificate = json_object_new_object();
  6817. DEBUG_INFO("sendSignCertificateRequest...\n");
  6818. // Read csr file content
  6819. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6820. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6821. char *line = NULL;
  6822. size_t len = 0;
  6823. while(getline(&line, &len, fp) != -1)
  6824. {
  6825. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6826. {
  6827. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6828. }
  6829. }
  6830. fclose(fp);
  6831. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6832. random_uuid(guid);
  6833. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6834. json_object_put(SignCertificate);
  6835. LWS_Send(message);
  6836. sprintf(tempdata, "SignCertificate,0");
  6837. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6838. {
  6839. result = PASS;
  6840. }
  6841. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6842. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6843. return result;
  6844. }
  6845. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6846. {
  6847. mtrace();
  6848. int result = PASS;
  6849. char message[110]={0};
  6850. char guid[37]={0};
  6851. char tempdata[65]={0};
  6852. json_object *FirmwareStatusNotification = json_object_new_object();
  6853. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6854. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6855. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6856. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6857. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6858. random_uuid(guid);
  6859. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6860. json_object_put(FirmwareStatusNotification);
  6861. LWS_Send(message);
  6862. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6863. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6864. {
  6865. result = PASS;
  6866. }
  6867. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6868. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6869. return result;
  6870. }
  6871. //==========================================
  6872. // send confirm routine
  6873. //==========================================
  6874. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6875. {
  6876. mtrace();
  6877. int result = FAIL;
  6878. char message[100]={0};
  6879. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6880. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6881. LWS_Send(message);
  6882. result = TRUE;
  6883. return result;
  6884. }
  6885. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6886. {
  6887. mtrace();
  6888. int result = FAIL;
  6889. char message[100]={0};
  6890. DEBUG_INFO("sendChangeAvailabilityConfirmation...\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 sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6897. {
  6898. mtrace();
  6899. int result = FAIL;
  6900. char message[100]={0};
  6901. DEBUG_INFO("sendChangeConfigurationConfirmation...\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 sendClearCacheConfirmation(char *uuid,char *payload)
  6908. {
  6909. mtrace();
  6910. int result = FAIL;
  6911. char message[500]={0};
  6912. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6913. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6914. LWS_Send(message);
  6915. return result;
  6916. }
  6917. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6918. {
  6919. mtrace();
  6920. int result = FAIL;
  6921. char message[500]={0};
  6922. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6923. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6924. LWS_Send(message);
  6925. return result;
  6926. }
  6927. int sendDataTransferConfirmation(char *uuid,char *payload)
  6928. {
  6929. mtrace();
  6930. char statusStr[20]={0};
  6931. char dataStr[10]={0};
  6932. char sstr[20]={0};
  6933. int c = 0;
  6934. char *loc;
  6935. int result = FAIL;
  6936. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6937. /**********************status**************************/
  6938. loc = strstr(payload, "status");
  6939. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6940. c = 0;
  6941. while (loc[3+strlen("status")+c] != '\"')
  6942. {
  6943. sstr[c] = loc[3+strlen("status")+c];
  6944. c++;
  6945. }
  6946. sstr[c] = '\0';
  6947. strcpy(statusStr, sstr);
  6948. /**********************data**************************/
  6949. loc = strstr(payload, "data");
  6950. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6951. c = 0;
  6952. while (loc[3+strlen("data")+c] != '\"')
  6953. {
  6954. sstr[c] = loc[3+strlen("data")+c];
  6955. c++;
  6956. }
  6957. sstr[c] = '\0';
  6958. strcpy(dataStr, sstr);
  6959. return result;
  6960. }
  6961. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6962. {
  6963. mtrace();
  6964. int result = FAIL;
  6965. char message[1000]={0};
  6966. int CompositeScheduleIndex = 0;
  6967. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6968. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6969. if(nPeriod == 0)
  6970. {
  6971. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6972. {
  6973. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6974. ,MESSAGE_TYPE_CALLRESULT
  6975. ,uuid
  6976. ,payload
  6977. ,connectorIdInt);
  6978. }
  6979. else
  6980. {
  6981. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6982. ,MESSAGE_TYPE_CALLRESULT
  6983. ,uuid
  6984. ,payload
  6985. ,connectorIdInt
  6986. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6987. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6988. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6989. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6990. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6991. }
  6992. }
  6993. else
  6994. {
  6995. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6996. ,MESSAGE_TYPE_CALLRESULT
  6997. ,uuid
  6998. ,payload
  6999. ,connectorIdInt
  7000. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7001. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7002. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7003. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7004. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7005. {
  7006. if (idx_sample == 0)
  7007. {
  7008. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7009. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7010. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7011. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7012. }
  7013. else
  7014. {
  7015. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7016. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7017. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7018. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7019. }
  7020. }
  7021. sprintf(message + strlen(message), "]}}]");
  7022. }
  7023. LWS_Send(message);
  7024. result = TRUE;
  7025. return result;
  7026. }
  7027. int sendGetConfigurationConfirmation(char *uuid)
  7028. {
  7029. mtrace();
  7030. int result = FAIL;
  7031. int MaxKeySupported = 0;
  7032. int sentConfigurationNumber= 0;
  7033. int sentunConfigurationNumber= 0;
  7034. char message[1024*10]={0};
  7035. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7036. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7037. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7038. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7039. ,MESSAGE_TYPE_CALLRESULT
  7040. ,uuid );
  7041. //configuration key
  7042. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7043. {
  7044. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7045. {
  7046. if (sentConfigurationNumber == 0)
  7047. {
  7048. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7049. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7050. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7051. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7052. }
  7053. else
  7054. {
  7055. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7056. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7057. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7058. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7059. }
  7060. sentConfigurationNumber = sentConfigurationNumber + 1;
  7061. }
  7062. }
  7063. sprintf(message + strlen(message), "]");
  7064. if(UnknownKeynum != 0)
  7065. {
  7066. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7067. //unkown key
  7068. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7069. {
  7070. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7071. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7072. if(sentunConfigurationNumber == 0)
  7073. {
  7074. sprintf(message + strlen(message), "\"%s\""
  7075. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7076. }
  7077. else
  7078. {
  7079. sprintf(message + strlen(message), ",\"%s\""
  7080. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7081. }
  7082. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7083. }
  7084. sprintf(message + strlen(message), "]");
  7085. }
  7086. sprintf(message + strlen(message), "}]");
  7087. LWS_Send(message);
  7088. return result;
  7089. }
  7090. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7091. {
  7092. mtrace();
  7093. int result = FAIL;
  7094. char message[400]={0};
  7095. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7096. if(strcmp(payload,"")==0)
  7097. {
  7098. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7099. }
  7100. else
  7101. {
  7102. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7103. }
  7104. LWS_Send(message);
  7105. result = TRUE;
  7106. return result;
  7107. }
  7108. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7109. {
  7110. mtrace();
  7111. int result = FAIL;
  7112. char message[80]={0};
  7113. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7114. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7115. LWS_Send(message);
  7116. result = TRUE;
  7117. return result;
  7118. }
  7119. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7120. {
  7121. mtrace();
  7122. int result = FAIL;
  7123. char message[80]={0};
  7124. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7125. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7126. LWS_Send(message);
  7127. result = TRUE;
  7128. return result;
  7129. }
  7130. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7131. {
  7132. mtrace();
  7133. int result = FAIL;
  7134. char message[80]={0};
  7135. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\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 sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7142. {
  7143. mtrace();
  7144. int result = FAIL;
  7145. char message[80]={0};
  7146. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7147. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7148. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7149. LWS_Send(message);
  7150. result = TRUE;
  7151. return result;
  7152. }
  7153. int sendResetConfirmation(char *uuid,char *payload)
  7154. {
  7155. mtrace();
  7156. int result = FAIL;
  7157. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7158. char message[80]={0};
  7159. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7160. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7161. LWS_Send(message);
  7162. result = TRUE;
  7163. return result;
  7164. }
  7165. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7166. {
  7167. mtrace();
  7168. int result = FAIL;
  7169. char message[500]={0};
  7170. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7171. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7172. LWS_Send(message);
  7173. result = TRUE;
  7174. return result;
  7175. }
  7176. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7177. {
  7178. mtrace();
  7179. int result = FAIL;
  7180. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7181. char message[80]={0};
  7182. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7183. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7184. LWS_Send(message);
  7185. result = TRUE;
  7186. return result;
  7187. }
  7188. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7189. {
  7190. mtrace();
  7191. int result = FAIL;
  7192. char message[80]={0};
  7193. DEBUG_INFO("sendTriggerMessageConfirmation...\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 sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7200. {
  7201. mtrace();
  7202. int result = FAIL;
  7203. char message[80]={0};
  7204. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7205. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7206. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7207. LWS_Send(message);
  7208. result = TRUE;
  7209. return result;
  7210. }
  7211. int sendUpdateFirmwareConfirmation(char *uuid)
  7212. {
  7213. mtrace();
  7214. int result = FAIL;
  7215. char message[60]={0};
  7216. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7217. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7218. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7219. LWS_Send(message);
  7220. result = TRUE;
  7221. return result;
  7222. }
  7223. int sendCertificateSignedConfirmation(char *uuid)
  7224. {
  7225. mtrace();
  7226. int result = PASS;
  7227. char message[4096]={0};
  7228. json_object *CertificateSigned = json_object_new_object();
  7229. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7230. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7231. sprintf(message,"[%d,\"%s\",%s]"
  7232. ,MESSAGE_TYPE_CALLRESULT
  7233. ,uuid
  7234. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7235. json_object_put(CertificateSigned);
  7236. LWS_Send(message);
  7237. return result;
  7238. }
  7239. int sendDeleteCertificateConfirmation(char *uuid)
  7240. {
  7241. mtrace();
  7242. int result = PASS;
  7243. char message[4096]={0};
  7244. json_object *DeleteCertificate = json_object_new_object();
  7245. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7246. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7247. sprintf(message,"[%d,\"%s\",%s]"
  7248. ,MESSAGE_TYPE_CALLRESULT
  7249. ,uuid
  7250. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7251. json_object_put(DeleteCertificate);
  7252. LWS_Send(message);
  7253. return result;
  7254. }
  7255. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7256. {
  7257. mtrace();
  7258. int result = PASS;
  7259. char message[4096]={0};
  7260. json_object *ExtendedTriggerMessage = json_object_new_object();
  7261. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7262. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7263. sprintf(message,"[%d,\"%s\",%s]"
  7264. ,MESSAGE_TYPE_CALLRESULT
  7265. ,uuid
  7266. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7267. json_object_put(ExtendedTriggerMessage);
  7268. LWS_Send(message);
  7269. return result;
  7270. }
  7271. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7272. {
  7273. mtrace();
  7274. int result = PASS;
  7275. char message[4096]={0};
  7276. json_object *GetInstalledCertificateIds = json_object_new_object();
  7277. json_object *certificateHashDataDatas = json_object_new_array();
  7278. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7279. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7280. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7281. {
  7282. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7283. {
  7284. json_object *certificateHashData = json_object_new_object();
  7285. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7286. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7287. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7288. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7289. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7290. }
  7291. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7292. }
  7293. else
  7294. {
  7295. json_object_put(certificateHashDataDatas);
  7296. }
  7297. sprintf(message,"[%d,\"%s\",%s]"
  7298. ,MESSAGE_TYPE_CALLRESULT
  7299. ,uuid
  7300. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7301. json_object_put(GetInstalledCertificateIds);
  7302. LWS_Send(message);
  7303. return result;
  7304. }
  7305. int sendGetLogConfirmation(char *uuid)
  7306. {
  7307. mtrace();
  7308. int result = PASS;
  7309. char message[4096]={0};
  7310. json_object *GetLog = json_object_new_object();
  7311. DEBUG_INFO("sendGetLogConfirmation...\n");
  7312. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7313. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7314. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7315. sprintf(message,"[%d,\"%s\",%s]"
  7316. ,MESSAGE_TYPE_CALLRESULT
  7317. ,uuid
  7318. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7319. json_object_put(GetLog);
  7320. LWS_Send(message);
  7321. return result;
  7322. }
  7323. int sendInstallCertificateConfirmation(char *uuid)
  7324. {
  7325. mtrace();
  7326. int result = PASS;
  7327. char message[4096]={0};
  7328. json_object *InstallCertificate = json_object_new_object();
  7329. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7330. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7331. sprintf(message,"[%d,\"%s\",%s]"
  7332. ,MESSAGE_TYPE_CALLRESULT
  7333. ,uuid
  7334. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7335. json_object_put(InstallCertificate);
  7336. LWS_Send(message);
  7337. return result;
  7338. }
  7339. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7340. {
  7341. mtrace();
  7342. int result = PASS;
  7343. char message[4096]={0};
  7344. json_object *SignedUpdateFirmware = json_object_new_object();
  7345. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7346. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7347. sprintf(message,"[%d,\"%s\",%s]"
  7348. ,MESSAGE_TYPE_CALLRESULT
  7349. ,uuid
  7350. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7351. json_object_put(SignedUpdateFirmware);
  7352. LWS_Send(message);
  7353. return result;
  7354. }
  7355. int sendUnknownConfirmation(char *uuid)
  7356. {
  7357. mtrace();
  7358. int result = PASS;
  7359. char message[256]={0};
  7360. DEBUG_INFO("sendUnknownConfirmation...\n");
  7361. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7362. LWS_Send(message);
  7363. return result;
  7364. }
  7365. //==========================================
  7366. // Handle server request routine Start
  7367. //==========================================
  7368. int handleCancelReservationRequest(char *uuid, char *payload)
  7369. {
  7370. mtrace();
  7371. int result = FAIL;
  7372. int gunNO = 0;
  7373. int reservationIdInt = -1;
  7374. char comfirmstr[20];
  7375. DEBUG_INFO("handleCancelReservationRequest...\n");
  7376. json_object *CancelReservation;
  7377. CancelReservation = json_tokener_parse(payload);
  7378. if(!is_error(CancelReservation))
  7379. {
  7380. // Required data
  7381. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7382. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7383. }
  7384. json_object_put(CancelReservation);
  7385. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7386. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7387. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7388. if(reservationIdInt != -1)
  7389. {
  7390. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7391. //check Transaction active
  7392. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7393. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7394. {
  7395. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7396. {
  7397. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7398. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7399. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7400. {
  7401. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7402. }
  7403. else
  7404. {
  7405. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7406. }
  7407. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7408. goto end;
  7409. }
  7410. }
  7411. for (int index = 0; index < CCS_QUANTITY; index++)
  7412. {
  7413. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7414. {
  7415. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7416. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7417. if(gunType[2] == GUN_TYPE_CCS)
  7418. {
  7419. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7420. }
  7421. else
  7422. {
  7423. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7424. }
  7425. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7426. goto end;
  7427. }
  7428. }
  7429. for (int index = 0; index < GB_QUANTITY; index++)
  7430. {
  7431. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7432. {
  7433. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7434. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7435. if(gunType[2] == GUN_TYPE_GBT)
  7436. {
  7437. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7438. }
  7439. else
  7440. {
  7441. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7442. }
  7443. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7444. goto end;
  7445. }
  7446. }
  7447. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7448. {
  7449. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7450. {
  7451. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7452. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7453. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7454. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7455. goto end;
  7456. }
  7457. }
  7458. for (int index = 0; index < AC_QUANTITY; index++)
  7459. {
  7460. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7461. {
  7462. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7463. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7465. {
  7466. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7467. }
  7468. else
  7469. {
  7470. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7471. }
  7472. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7473. goto end;
  7474. }
  7475. }
  7476. }
  7477. //The reservationId does NOT match the reservationId
  7478. sendCancelReservationConfirmation(uuid, comfirmstr);
  7479. end:
  7480. // Fill in ocpp packet uuid
  7481. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7482. return result;
  7483. }
  7484. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7485. {
  7486. mtrace();
  7487. int result = FAIL;
  7488. int gunIndex = -1;
  7489. char typeStr[16]={0};
  7490. char comfirmstr[20];
  7491. int specificId = FALSE;
  7492. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7493. json_object *ChangeAvailability;
  7494. ChangeAvailability = json_tokener_parse(payload);
  7495. if(!is_error(ChangeAvailability))
  7496. {
  7497. // Required data
  7498. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7499. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7500. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7501. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7502. }
  7503. json_object_put(ChangeAvailability);
  7504. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7505. {
  7506. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7507. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7508. }
  7509. else if(gunIndex == 0)
  7510. {
  7511. for(int i=0; i < gunTotalNumber; i++)
  7512. {
  7513. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7514. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7515. }
  7516. }
  7517. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7518. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7519. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7520. {
  7521. specificId = TRUE;
  7522. }
  7523. if(specificId == FALSE)
  7524. goto end;
  7525. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7526. {
  7527. //----------------------gunIndex is 0 ------------------------------------------------//
  7528. if(gunIndex == 0)
  7529. {
  7530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7531. {
  7532. for(int i=0; i < gunTotalNumber; i++)
  7533. {
  7534. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7535. {
  7536. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7537. {
  7538. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7539. {
  7540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7541. goto end;
  7542. }
  7543. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7544. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7545. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7546. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7547. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7548. {
  7549. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7550. goto end;
  7551. }
  7552. }
  7553. }//END FOR CHAdeMO_QUANTITY
  7554. for (int index = 0; index < CCS_QUANTITY; index++)
  7555. {
  7556. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7557. {
  7558. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7559. {
  7560. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7561. goto end;
  7562. }
  7563. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7564. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7565. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7566. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7567. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7568. {
  7569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7570. goto end;
  7571. }
  7572. }
  7573. }//END FOR CCS_QUANTITY
  7574. for (int index = 0; index < GB_QUANTITY; index++)
  7575. {
  7576. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7577. {
  7578. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7579. {
  7580. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7581. goto end;
  7582. }
  7583. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7584. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7585. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7586. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7588. {
  7589. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7590. goto end;
  7591. }
  7592. }
  7593. }// END FOR GB_QUANTITY
  7594. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7595. {
  7596. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7597. {
  7598. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7599. {
  7600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7601. goto end;
  7602. }
  7603. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7604. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7605. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7606. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7608. {
  7609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7610. goto end;
  7611. }
  7612. }
  7613. }// END FOR GENERAL_GUN_QUANTITY
  7614. for (int index = 0; index < AC_QUANTITY; index++)
  7615. {
  7616. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7617. {
  7618. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7619. {
  7620. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7621. goto end;
  7622. }
  7623. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7624. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7625. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7626. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7628. {
  7629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7630. goto end;
  7631. }
  7632. }
  7633. }//END FOR AC_QUANTITY
  7634. }// END FOR gunTotalNumber
  7635. }
  7636. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7637. {
  7638. for(int i=0; i < gunTotalNumber; i++)
  7639. {
  7640. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7641. {
  7642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7643. goto end;
  7644. }
  7645. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7646. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7647. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7648. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7650. {
  7651. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7652. goto end;
  7653. }
  7654. }
  7655. }
  7656. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7657. goto end;
  7658. }
  7659. //----------------------gunIndex is not 0 ------------------------------------------------//
  7660. //check Transaction active
  7661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7662. {
  7663. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7664. {
  7665. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7666. {
  7667. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7668. goto end;
  7669. }
  7670. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7671. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7672. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7673. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7675. {
  7676. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7677. goto end;
  7678. }
  7679. else
  7680. {
  7681. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7682. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7683. goto end;
  7684. }
  7685. }
  7686. }//END FOR CHAdeMO_QUANTITY
  7687. for (int index = 0; index < CCS_QUANTITY; index++)
  7688. {
  7689. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7690. {
  7691. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7692. {
  7693. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7694. goto end;
  7695. }
  7696. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7697. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7698. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7699. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7700. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7701. {
  7702. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7703. goto end;
  7704. }
  7705. else
  7706. {
  7707. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7709. goto end;
  7710. }
  7711. }
  7712. }//END FOR CCS_QUANTITY
  7713. for (int index = 0; index < GB_QUANTITY; index++)
  7714. {
  7715. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7716. {
  7717. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7718. {
  7719. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7720. goto end;
  7721. }
  7722. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7723. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7724. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7725. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7726. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7727. {
  7728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7729. goto end;
  7730. }
  7731. else
  7732. {
  7733. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7734. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7735. goto end;
  7736. }
  7737. }
  7738. }// END FOR GB_QUANTITY
  7739. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7740. {
  7741. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7742. {
  7743. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7744. {
  7745. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7746. goto end;
  7747. }
  7748. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7749. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7750. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7751. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7753. {
  7754. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7755. goto end;
  7756. }
  7757. else
  7758. {
  7759. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7760. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7761. goto end;
  7762. }
  7763. }
  7764. }// END FOR GENERAL_GUN_QUANTITY
  7765. for (int index = 0; index < AC_QUANTITY; index++)
  7766. {
  7767. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7768. {
  7769. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7770. {
  7771. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7772. goto end;
  7773. }
  7774. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7776. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7777. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7779. {
  7780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7781. goto end;
  7782. }
  7783. else
  7784. {
  7785. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7786. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7787. goto end;
  7788. }
  7789. }
  7790. }//END FOR AC_QUANTITY
  7791. }//END FOR AvailabilityTypeStr[Inoperative]
  7792. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7793. {
  7794. //----------------------gunIndex is 0 ------------------------------------------------//
  7795. if(gunIndex == 0)
  7796. {
  7797. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7798. {
  7799. for(int i=0; i < gunTotalNumber; i++)
  7800. {
  7801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7802. {
  7803. 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
  7804. {
  7805. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7806. goto end;
  7807. }
  7808. }//END FOR CHAdeMO_QUANTITY
  7809. for (int index = 0; index < CCS_QUANTITY; index++)
  7810. {
  7811. 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
  7812. {
  7813. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7814. goto end;
  7815. }
  7816. }//END FOR CCS_QUANTITY
  7817. for (int index = 0; index < GB_QUANTITY; index++)
  7818. {
  7819. 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
  7820. {
  7821. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7822. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7823. goto end;
  7824. }
  7825. }// END FOR GB_QUANTITY
  7826. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7827. {
  7828. 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
  7829. {
  7830. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7831. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7832. goto end;
  7833. }
  7834. }// END FOR GENERAL_GUN_QUANTITY
  7835. for (int index = 0; index < AC_QUANTITY; index++)
  7836. {
  7837. 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
  7838. {
  7839. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7840. goto end;
  7841. }
  7842. }//END FOR CHAdeMO_QUANTITY
  7843. }// END FOR gunTotalNumber
  7844. }
  7845. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7846. {
  7847. for(int i=0; i < gunTotalNumber; i++)
  7848. {
  7849. for (int index = 0; index < AC_QUANTITY; index++)
  7850. {
  7851. 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
  7852. {
  7853. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7854. goto end;
  7855. }
  7856. }//END FOR CHAdeMO_QUANTITY
  7857. } // END FOR gunTotalNumber
  7858. }
  7859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7860. goto end;
  7861. }
  7862. //----------------------gunIndex is not 0 ------------------------------------------------//
  7863. //check Transaction active
  7864. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7865. {
  7866. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7867. {
  7868. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7869. goto end;
  7870. }
  7871. }//END FOR CHAdeMO_QUANTITY
  7872. for (int index = 0; index < CCS_QUANTITY; index++)
  7873. {
  7874. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7875. {
  7876. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7877. goto end;
  7878. }
  7879. }//END FOR CCS_QUANTITY
  7880. for (int index = 0; index < GB_QUANTITY; index++)
  7881. {
  7882. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7883. {
  7884. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7885. goto end;
  7886. }
  7887. }// END FOR GB_QUANTITY
  7888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7889. {
  7890. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7891. {
  7892. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7893. goto end;
  7894. }
  7895. }// END FOR GENERAL_GUN_QUANTITY
  7896. for (int index = 0; index < AC_QUANTITY; index++)
  7897. {
  7898. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7899. {
  7900. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7901. goto end;
  7902. }
  7903. }//END FOR AC_QUANTITY
  7904. }//END FOR AvailabilityTypeStr[Operative]
  7905. end:
  7906. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7907. {
  7908. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7909. }
  7910. else
  7911. {
  7912. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7913. }
  7914. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7915. {
  7916. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7917. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7918. }
  7919. else if(gunIndex == 0)
  7920. {
  7921. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7922. {
  7923. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7924. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7925. }
  7926. }
  7927. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7928. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7929. return result;
  7930. }
  7931. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7932. {
  7933. mtrace();
  7934. int result = FAIL;
  7935. char keystr[40]={0};
  7936. char valuestr[256]={0};
  7937. char comfirmstr[20]={0};
  7938. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7939. json_object *ChangeConfiguration;
  7940. ChangeConfiguration = json_tokener_parse(payload);
  7941. if(!is_error(ChangeConfiguration))
  7942. {
  7943. // Required data
  7944. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7945. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7946. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7947. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7948. }
  7949. json_object_put(ChangeConfiguration);
  7950. if((uuid==NULL) || (payload ==NULL) )
  7951. {
  7952. DEBUG_ERROR("Payload is null\n");
  7953. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7954. }
  7955. else
  7956. {
  7957. int status = setKeyValue(keystr, valuestr);
  7958. switch(status)
  7959. {
  7960. case ConfigurationStatus_Accepted:
  7961. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7962. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7963. StoreConfigurationTable();
  7964. break;
  7965. case RebootRequired:
  7966. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7967. StoreConfigurationTable();
  7968. break;
  7969. case NotSupported:
  7970. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7971. break;
  7972. case ConfigurationStatus_Rejected:
  7973. default:
  7974. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7975. break;
  7976. }
  7977. }
  7978. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7979. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7980. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7981. {
  7982. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7983. SetOcppConnStatus(FALSE);
  7984. }
  7985. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7986. {
  7987. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7988. }
  7989. return result;
  7990. }
  7991. int handleClearCacheRequest(char *uuid, char *payload)
  7992. {
  7993. mtrace();
  7994. int result = FAIL;
  7995. char comfirmstr[20];
  7996. char rmFileCmd[100]={0};
  7997. struct stat stats;
  7998. DEBUG_INFO("handleClearCacheRequest...\n");
  7999. stat("/Storage/OCPP_PH", &stats);
  8000. // Check for directory existence
  8001. if (S_ISDIR(stats.st_mode) == 1)
  8002. {}
  8003. else
  8004. {
  8005. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8006. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8007. system(rmFileCmd);
  8008. }
  8009. if(OCPP_cleanLocalCache())
  8010. {
  8011. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8012. }
  8013. else
  8014. {
  8015. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8016. }
  8017. sendClearCacheConfirmation(uuid, comfirmstr);
  8018. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8019. return result;
  8020. }
  8021. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8022. {
  8023. mtrace();
  8024. int result = FAIL;
  8025. int resultRename;
  8026. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8027. char chargingProfilePurposeStr[26]={0};
  8028. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8029. char tempchargingProfilePurposeStr[26]={0};
  8030. char str[100]={0};
  8031. char fname[200]={0};
  8032. char comfirmstr[20]={0};
  8033. char word[1600]={0};
  8034. int clearflag = FALSE;
  8035. int chargingProfileIdIsNULL = FALSE;
  8036. int connectorIsNULL = FALSE;
  8037. int chargingProfilePurposeIsNULL = FALSE;
  8038. int stackLevelIsNULL = FALSE;
  8039. //int GotoEnd = FALSE;
  8040. FILE *fptr1, *fptr2;
  8041. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8042. int n_chargingProfile=0;
  8043. int isEmptyFile = FALSE;
  8044. char sLineWord[1600]={0};
  8045. char chargingProfiles[10][100]={0};
  8046. int ChargeProfileCount = 0;
  8047. int ch;
  8048. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8049. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8050. json_object *ClearChargingProfile;
  8051. ClearChargingProfile = json_tokener_parse(payload);
  8052. if(!is_error(ClearChargingProfile))
  8053. {
  8054. // Optional data
  8055. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8056. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8057. else
  8058. chargingProfileIdIsNULL = TRUE;
  8059. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8060. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8061. else
  8062. connectorIsNULL = TRUE;
  8063. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8064. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8065. else
  8066. chargingProfilePurposeIsNULL = TRUE;
  8067. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8068. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8069. else
  8070. stackLevelIsNULL = TRUE;
  8071. }
  8072. json_object_put(ClearChargingProfile);
  8073. if(connectorIsNULL == FALSE)
  8074. {
  8075. switch(connectorIdInt)
  8076. {
  8077. case 0:
  8078. if(chargingProfilePurposeIsNULL == TRUE)
  8079. {
  8080. int l = 0;
  8081. strcpy(fname, ChargePointMaxProfile_JSON);
  8082. if((access(fname,F_OK))!=-1)
  8083. {
  8084. strcpy(chargingProfiles[l], fname);
  8085. l = l + 1;
  8086. }
  8087. strcpy(fname, TxDefaultProfile_0_JSON);
  8088. if((access(fname,F_OK))!=-1)
  8089. {
  8090. strcpy(chargingProfiles[l], fname);
  8091. l = l + 1;
  8092. }
  8093. ChargeProfileCount = l;
  8094. }
  8095. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8096. {
  8097. strcpy(fname, ChargePointMaxProfile_JSON);
  8098. if((access(fname,F_OK))!=-1)
  8099. {
  8100. strcpy(chargingProfiles[0], fname);
  8101. ChargeProfileCount = 1;
  8102. }
  8103. }
  8104. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8105. {
  8106. strcpy(fname, TxDefaultProfile_0_JSON);
  8107. if((access(fname,F_OK))!=-1)
  8108. {
  8109. strcpy(chargingProfiles[0], fname);
  8110. ChargeProfileCount = 1;
  8111. }
  8112. }
  8113. break;
  8114. default:
  8115. if(chargingProfilePurposeIsNULL == TRUE)
  8116. {
  8117. int m = 0;
  8118. memset(fname, 0, ARRAY_SIZE(fname));
  8119. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8120. if((access(fname,F_OK))!=-1)
  8121. {
  8122. strcpy(chargingProfiles[m], fname);
  8123. m = m + 1;
  8124. }
  8125. memset(fname, 0, ARRAY_SIZE(fname));
  8126. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8127. if((access(fname,F_OK))!=-1)
  8128. {
  8129. strcpy(chargingProfiles[m], fname);
  8130. m = m + 1;
  8131. }
  8132. ChargeProfileCount = m;
  8133. }
  8134. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8135. {
  8136. //strcpy(fname, TxDefaultProfile_1_JSON);
  8137. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8138. if((access(fname,F_OK))!=-1)
  8139. {
  8140. strcpy(chargingProfiles[0], fname);
  8141. ChargeProfileCount = 1;
  8142. }
  8143. }
  8144. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8145. {
  8146. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8147. if((access(fname,F_OK))!=-1)
  8148. {
  8149. strcpy(chargingProfiles[0], fname);
  8150. ChargeProfileCount = 1;
  8151. }
  8152. //strcpy(fname, TxProfile_1_JSON);
  8153. }
  8154. //strcpy(fname, ChargePointMaxProfile_JSON );
  8155. break;
  8156. }
  8157. }
  8158. else // Check all Charging Profiles
  8159. {
  8160. int i = 0;
  8161. char fnametemp[200]={0};
  8162. ChargeProfileCount = 0;
  8163. //Check ChargePointMaxProfile.json exit
  8164. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8165. {
  8166. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8167. i = i + 1;
  8168. }
  8169. //Check TxDefaultProfile_0.json exit
  8170. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8171. {
  8172. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8173. i = i + 1;
  8174. }
  8175. //Check TxDefaultProfile_%d.json
  8176. for(int j=1; j <= gunTotalNumber; j++)
  8177. {
  8178. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8179. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8180. if((access(fnametemp,F_OK))!=-1)
  8181. {
  8182. strcpy(chargingProfiles[i], fnametemp);
  8183. i = i + 1;
  8184. }
  8185. }
  8186. //Check TxProfile_%d.json
  8187. for(int j=1; j <= gunTotalNumber; j++)
  8188. {
  8189. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8190. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8191. if((access(fnametemp,F_OK))!=-1)
  8192. {
  8193. strcpy(chargingProfiles[i], fnametemp);
  8194. i = i + 1;
  8195. }
  8196. }
  8197. ChargeProfileCount = i;
  8198. }// End connectorIsNULL is TRUE
  8199. if(ChargeProfileCount == 0)
  8200. {
  8201. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8202. goto end;
  8203. }
  8204. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8205. {
  8206. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8207. goto end;
  8208. }
  8209. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8210. {
  8211. memset(str, 0, ARRAY_SIZE(str));
  8212. // clear temp file
  8213. sprintf(str,"rm -f %s",temp);
  8214. system(str);
  8215. for(int k=0; k < ChargeProfileCount; k++)
  8216. {
  8217. memset(str, 0, ARRAY_SIZE(str));
  8218. //clear file in C
  8219. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8220. system(str);
  8221. }
  8222. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8223. goto end;
  8224. }
  8225. else if(connectorIsNULL == TRUE)
  8226. {
  8227. for(int k=0; k < ChargeProfileCount; k++)
  8228. {
  8229. fptr1 = fopen(chargingProfiles[k], "r");
  8230. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8231. //Check Charging Profile Count
  8232. while(fscanf(fptr1, "%s", word) != EOF)
  8233. {
  8234. //DEBUG_INFO("word=%s\n",word);
  8235. if(strstr(word, "chargingProfileId")!= NULL)
  8236. {
  8237. //DEBUG_INFO("test chargingProfileId \n");
  8238. n_chargingProfile = n_chargingProfile + 1;
  8239. //DEBUG_INFO("chargingProfileId Found\n");
  8240. }
  8241. }
  8242. rewind(fptr1);
  8243. //search Charging Profile Element
  8244. //int i= 0;
  8245. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8246. {
  8247. json_object *tmpProfilee;
  8248. tmpProfilee = json_tokener_parse(sLineWord);
  8249. if(!is_error(tmpProfilee))
  8250. {
  8251. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8252. {
  8253. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8254. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8255. }
  8256. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8257. {
  8258. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8259. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8260. }
  8261. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8262. {
  8263. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8264. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8265. }
  8266. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8267. {
  8268. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8269. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8270. }
  8271. }
  8272. json_object_put(tmpProfilee);
  8273. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8274. {
  8275. //------- not write to fptr2-------//
  8276. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8277. //clearflag = TRUE;
  8278. }
  8279. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8280. {
  8281. //------- not write to fptr2-------//
  8282. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8283. }
  8284. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8285. {
  8286. //------- not write to fptr2-------//
  8287. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8288. }
  8289. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8290. {
  8291. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8292. }
  8293. else
  8294. {
  8295. fprintf(fptr2, sLineWord);//writing data into file
  8296. }
  8297. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8298. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8299. if(clearflag == TRUE)
  8300. {
  8301. fclose(fptr1);
  8302. fclose(fptr2);
  8303. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8304. system(str);
  8305. // clear temp file
  8306. sprintf(str,"rm -f %s",temp);
  8307. system(str);
  8308. }
  8309. else
  8310. {
  8311. fclose(fptr1);
  8312. fclose(fptr2);
  8313. memset(str, 0, ARRAY_SIZE(str));
  8314. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8315. system(str);
  8316. resultRename = rename(temp, chargingProfiles[k]);
  8317. if(resultRename == 0)
  8318. {
  8319. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8320. }
  8321. else
  8322. {
  8323. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8324. }
  8325. if(comfirmstr[0]== 0)
  8326. {
  8327. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8328. }
  8329. //Check chargingProfile is empty file
  8330. /*------ Read the file ----------------*/
  8331. fptr1=fopen(chargingProfiles[k],"r");
  8332. ch=fgetc(fptr1);
  8333. rewind(fptr1);
  8334. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8335. if(ch!=EOF)
  8336. {
  8337. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8338. {
  8339. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8340. if(sLineWord[0]=='\0')
  8341. {
  8342. isEmptyFile = TRUE;
  8343. break;
  8344. }
  8345. else
  8346. {
  8347. isEmptyFile = FALSE;
  8348. break;
  8349. }
  8350. }
  8351. }
  8352. else
  8353. isEmptyFile = TRUE;
  8354. fclose(fptr1);
  8355. if(isEmptyFile == TRUE)
  8356. {
  8357. memset(str, 0, ARRAY_SIZE(str));
  8358. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8359. system(str);
  8360. }
  8361. }
  8362. }// End of while(int k=0; k < ChargePointCount; k++)
  8363. }
  8364. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8365. {
  8366. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8367. for(int k=0; k < ChargeProfileCount; k++)
  8368. {
  8369. fptr1 = fopen(chargingProfiles[k], "r");
  8370. fptr2 = fopen(temp, "w+");
  8371. //Check Charging Profile Count
  8372. while(fscanf(fptr1, "%s", word) != EOF)
  8373. {
  8374. //DEBUG_INFO("word=%s\n",word);
  8375. if(strstr(word, "chargingProfileId")!= NULL)
  8376. {
  8377. n_chargingProfile = n_chargingProfile + 1;
  8378. }
  8379. }
  8380. rewind(fptr1);
  8381. //search Charging Profile Element
  8382. //int i= 0;
  8383. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8384. {
  8385. json_object *tmpProfilee;
  8386. tmpProfilee = json_tokener_parse(sLineWord);
  8387. if(!is_error(tmpProfilee))
  8388. {
  8389. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8390. {
  8391. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8392. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8393. }
  8394. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8395. {
  8396. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8397. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8398. }
  8399. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8400. {
  8401. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8402. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8403. }
  8404. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8405. {
  8406. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8407. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8408. }
  8409. }
  8410. json_object_put(tmpProfilee);
  8411. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8412. {
  8413. //------- not write to fptr2-------//
  8414. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8415. //clearflag = TRUE;
  8416. }
  8417. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8418. {
  8419. //------- not write to fptr2-------//
  8420. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8421. }
  8422. else if(stackLevelIsNULL == TRUE)
  8423. {
  8424. //Clear Whole File
  8425. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8426. clearflag = TRUE;
  8427. break;
  8428. }
  8429. else
  8430. {
  8431. fprintf(fptr2, sLineWord);//writing data into file
  8432. }
  8433. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8434. }
  8435. if(clearflag == TRUE)
  8436. {
  8437. fclose(fptr1);
  8438. fclose(fptr2);
  8439. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8440. system(str);
  8441. // clear temp file
  8442. sprintf(str,"rm -f %s",temp);
  8443. system(str);
  8444. }
  8445. else
  8446. {
  8447. fclose(fptr1);
  8448. fclose(fptr2);
  8449. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8450. system(str);
  8451. resultRename = rename(temp, chargingProfiles[k]);
  8452. if(resultRename == 0)
  8453. {
  8454. DEBUG_INFO("File ChargingProfile renamed successfully");
  8455. }
  8456. else
  8457. {
  8458. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8459. }
  8460. if(comfirmstr[0]== 0)
  8461. {
  8462. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8463. }
  8464. //Check chargingProfile is empty file
  8465. /*------ Read the file ----------------*/
  8466. fptr1=fopen(chargingProfiles[k],"r");
  8467. ch=fgetc(fptr1);
  8468. rewind(fptr1);
  8469. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8470. if(ch!=EOF)
  8471. {
  8472. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8473. {
  8474. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8475. if(sLineWord[0]=='\0')
  8476. {
  8477. isEmptyFile = TRUE;
  8478. break;
  8479. }
  8480. else
  8481. {
  8482. isEmptyFile = FALSE;
  8483. break;
  8484. }
  8485. }
  8486. }
  8487. else
  8488. isEmptyFile = TRUE;
  8489. fclose(fptr1);
  8490. if(isEmptyFile == TRUE)
  8491. {
  8492. memset(str, 0, ARRAY_SIZE(str));
  8493. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8494. system(str);
  8495. }
  8496. /*------- End of reading ---------------*/
  8497. }
  8498. } // while(int k=0; k < ChargeProfileCount; k++)
  8499. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8500. end:
  8501. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8502. {
  8503. if(connectorIdInt == 0)
  8504. {
  8505. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8506. {
  8507. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8508. }
  8509. }
  8510. else
  8511. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8512. }
  8513. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8514. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8515. return result;
  8516. }
  8517. void createFirmwareVersionByDataTransfer(void)
  8518. {
  8519. json_object *FirmwareDataTransfer = json_object_new_object();
  8520. // AC & DC model
  8521. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8522. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8523. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8524. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8525. // DC model
  8526. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8527. {
  8528. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8529. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8530. (gunType[3] != GUN_TYPE_UNKNOWN))
  8531. {
  8532. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8533. }
  8534. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8535. {
  8536. // DS DM DW
  8537. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8538. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8539. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8540. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8541. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8542. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8543. }
  8544. else
  8545. {
  8546. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8547. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8548. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8549. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8550. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8551. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8552. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8553. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8554. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8555. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8556. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8557. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8558. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8559. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8560. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8561. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8562. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8563. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8564. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8565. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8566. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8567. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8568. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8569. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8570. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8571. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8572. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8573. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8574. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8575. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8576. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8577. }
  8578. }
  8579. // 4G model
  8580. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8581. {
  8582. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8583. }
  8584. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8585. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8586. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8587. json_object_put(FirmwareDataTransfer);
  8588. }
  8589. int handleDataTransferRequest(char *uuid, char *payload)
  8590. {
  8591. mtrace();
  8592. json_object *response = json_object_new_object();
  8593. int result = FAIL;
  8594. char tempvendorId[255]={0};
  8595. char tempmessageId[50]={0};
  8596. char tempdata[512]={0};
  8597. char message[2048]={0};
  8598. DEBUG_INFO("handleDataTransferRequest...\n");
  8599. if((uuid != NULL) && (payload != NULL))
  8600. {
  8601. json_object *DataTransfer;
  8602. DataTransfer = json_tokener_parse(payload);
  8603. if(!is_error(DataTransfer))
  8604. {
  8605. // Required data
  8606. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8607. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8608. // Optional data
  8609. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8610. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8611. if(json_object_object_get(DataTransfer, "data") != NULL)
  8612. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8613. result = PASS;
  8614. }
  8615. json_object_put(DataTransfer);
  8616. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8617. {
  8618. // Send all moudle firmware version on EVSE
  8619. createFirmwareVersionByDataTransfer();
  8620. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8621. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  8622. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8623. json_object_put(response);
  8624. }
  8625. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8626. {
  8627. system("/usr/bin/run_tmate_restart.sh &");
  8628. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8629. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8630. json_object_put(response);
  8631. }
  8632. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8633. {
  8634. json_object *data;
  8635. data = json_tokener_parse(tempdata);
  8636. if(!is_error(data))
  8637. {
  8638. 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))
  8639. {
  8640. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8641. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8642. if(json_object_object_get(data, "SOC") != NULL)
  8643. {
  8644. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8645. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8646. }
  8647. if(json_object_object_get(data, "Energy") != NULL)
  8648. {
  8649. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8650. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8651. }
  8652. if(json_object_object_get(data, "Duration") != NULL)
  8653. {
  8654. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8655. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8656. }
  8657. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8658. }
  8659. else
  8660. {
  8661. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8662. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8663. }
  8664. }
  8665. else
  8666. {
  8667. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8668. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8669. }
  8670. json_object_put(data);
  8671. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8672. json_object_put(response);
  8673. }
  8674. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8675. {
  8676. json_object *data;
  8677. data = json_tokener_parse(tempdata);
  8678. if(!is_error(data))
  8679. {
  8680. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8681. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8682. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8683. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8684. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8685. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8686. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8687. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8688. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8689. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8690. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8691. }
  8692. else
  8693. {
  8694. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8695. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8696. }
  8697. json_object_put(data);
  8698. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8699. json_object_put(response);
  8700. }
  8701. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8702. {
  8703. json_object *data;
  8704. data = json_tokener_parse(tempdata);
  8705. if(!is_error(data))
  8706. {
  8707. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8708. if(json_object_object_get(data, "idToken") != NULL)
  8709. {
  8710. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8711. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8712. }
  8713. if(json_object_object_get(data, "price") != NULL)
  8714. {
  8715. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8716. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8717. }
  8718. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8719. }
  8720. else
  8721. {
  8722. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8723. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8724. }
  8725. json_object_put(data);
  8726. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8727. json_object_put(response);
  8728. }
  8729. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8730. {
  8731. json_object *data;
  8732. data = json_tokener_parse(tempdata);
  8733. if(!is_error(data))
  8734. {
  8735. if(json_object_object_get(data, "txId") != NULL)
  8736. {
  8737. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8738. for(int idx = 0;idx<gunTotalNumber;idx++)
  8739. {
  8740. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8741. {
  8742. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8743. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8744. if(json_object_object_get(data, "description") != NULL)
  8745. {
  8746. // California pricing V1.0
  8747. DEBUG_INFO("California pricing V1.0\n");
  8748. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8749. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8750. }
  8751. else
  8752. {
  8753. // California pricing V1.1
  8754. DEBUG_INFO("California pricing V1.1\n");
  8755. if(json_object_object_get(data, "timestamp") != NULL)
  8756. {
  8757. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8758. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8759. }
  8760. if(json_object_object_get(data, "meterValue") != NULL)
  8761. {
  8762. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8763. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8764. }
  8765. if(json_object_object_get(data, "cost") != NULL)
  8766. {
  8767. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8768. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8769. }
  8770. if(json_object_object_get(data, "state") != NULL)
  8771. {
  8772. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8773. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8774. }
  8775. if(json_object_object_get(data, "chargingPrice") != NULL)
  8776. {
  8777. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8778. {
  8779. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8780. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8781. }
  8782. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8783. {
  8784. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8785. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8786. }
  8787. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8788. {
  8789. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8790. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8791. }
  8792. }
  8793. if(json_object_object_get(data, "idlePrice") != NULL)
  8794. {
  8795. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8796. {
  8797. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8798. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8799. }
  8800. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8801. {
  8802. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8803. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8804. }
  8805. }
  8806. if(json_object_object_get(data, "nextPeriod") != NULL)
  8807. {
  8808. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8809. {
  8810. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8811. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8812. }
  8813. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8814. {
  8815. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8816. {
  8817. 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")));
  8818. 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"));
  8819. }
  8820. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8821. {
  8822. 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")));
  8823. 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"));
  8824. }
  8825. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8826. {
  8827. 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")));
  8828. 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"));
  8829. }
  8830. }
  8831. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8832. {
  8833. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8834. {
  8835. 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")));
  8836. 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"));
  8837. }
  8838. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8839. {
  8840. 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")));
  8841. 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"));
  8842. }
  8843. }
  8844. }
  8845. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8846. {
  8847. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8848. {
  8849. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8850. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8851. }
  8852. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8853. {
  8854. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8855. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8856. }
  8857. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8858. {
  8859. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8860. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8861. }
  8862. }
  8863. }
  8864. }
  8865. }
  8866. }
  8867. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8868. }
  8869. else
  8870. {
  8871. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8872. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8873. }
  8874. json_object_put(data);
  8875. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8876. json_object_put(response);
  8877. }
  8878. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8879. {
  8880. json_object *data;
  8881. data = json_tokener_parse(tempdata);
  8882. if(!is_error(data))
  8883. {
  8884. if(json_object_object_get(data, "txId") != NULL)
  8885. {
  8886. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8887. for(int idx = 0;idx<gunTotalNumber;idx++)
  8888. {
  8889. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8890. {
  8891. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8892. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8893. if(json_object_object_get(data, "description") != NULL)
  8894. {
  8895. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8896. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8897. }
  8898. }
  8899. }
  8900. }
  8901. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8902. }
  8903. else
  8904. {
  8905. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8906. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8907. }
  8908. json_object_put(data);
  8909. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8910. json_object_put(response);
  8911. }
  8912. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8913. {
  8914. json_object *data;
  8915. data = json_tokener_parse(tempdata);
  8916. if(!is_error(data))
  8917. {
  8918. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8919. if(json_object_object_get(data, "Content_Type") != NULL)
  8920. {
  8921. 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))
  8922. {
  8923. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8924. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8925. {
  8926. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8927. }
  8928. }
  8929. else
  8930. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8931. }
  8932. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8933. }
  8934. else
  8935. {
  8936. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8937. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8938. }
  8939. json_object_put(data);
  8940. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8941. json_object_put(response);
  8942. }
  8943. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8944. {
  8945. json_object *data;
  8946. data = json_tokener_parse(tempdata);
  8947. if(!is_error(data))
  8948. {
  8949. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8950. if(json_object_object_get(data, "Page_Index") != NULL)
  8951. {
  8952. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8953. }
  8954. if(json_object_object_get(data, "Duration") != NULL)
  8955. {
  8956. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8957. }
  8958. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8959. }
  8960. else
  8961. {
  8962. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8963. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8964. }
  8965. json_object_put(data);
  8966. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8967. json_object_put(response);
  8968. }
  8969. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8970. {
  8971. json_object *data;
  8972. data = json_tokener_parse(tempdata);
  8973. if(!is_error(data))
  8974. {
  8975. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8976. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8977. {
  8978. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8979. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8980. else
  8981. {
  8982. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8983. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8984. }
  8985. }
  8986. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8987. {
  8988. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8989. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8990. else
  8991. {
  8992. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8993. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8994. }
  8995. }
  8996. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8997. {
  8998. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8999. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9000. else
  9001. {
  9002. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9003. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9004. }
  9005. }
  9006. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9007. {
  9008. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9009. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9010. else
  9011. {
  9012. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9013. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9014. }
  9015. }
  9016. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9017. {
  9018. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9019. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9020. else
  9021. {
  9022. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9023. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9024. }
  9025. }
  9026. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9027. {
  9028. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9029. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9030. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9031. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9032. else
  9033. {
  9034. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9035. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9036. }
  9037. }
  9038. if(json_object_object_get(data, "isAuthentication") != NULL)
  9039. {
  9040. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9041. {
  9042. case 0:
  9043. case 1:
  9044. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9045. break;
  9046. default:
  9047. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9048. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9049. break;
  9050. }
  9051. }
  9052. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9053. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9054. }
  9055. else
  9056. {
  9057. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9058. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9059. }
  9060. json_object_put(data);
  9061. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9062. json_object_put(response);
  9063. }
  9064. else
  9065. {
  9066. // Can not find valid message id
  9067. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9068. }
  9069. }
  9070. else
  9071. {
  9072. // Payload is null
  9073. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9074. }
  9075. LWS_Send(message);
  9076. return result;
  9077. }
  9078. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9079. {
  9080. mtrace();
  9081. int result = FAIL;
  9082. int connectorIdInt, durationInt;
  9083. char chargingRateUnitStr[4]={0};
  9084. char comfirmstr[20];
  9085. int confirmPeriods = 0;
  9086. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9087. json_object *GetCompositeSchedule;
  9088. GetCompositeSchedule = json_tokener_parse(payload);
  9089. if(!is_error(GetCompositeSchedule))
  9090. {
  9091. // Required data
  9092. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9093. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9094. else
  9095. connectorIdInt = -1;
  9096. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9097. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9098. else
  9099. durationInt = 86400;
  9100. // Optional data
  9101. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9102. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9103. }
  9104. json_object_put(GetCompositeSchedule);
  9105. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9106. if((connectorIdInt == 0) ||
  9107. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9108. {
  9109. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9110. struct StructChargingProfile tmpProfile[1];
  9111. if(strstr(chargingRateUnitStr, "W") != NULL)
  9112. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9113. else
  9114. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9115. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9116. {
  9117. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9118. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9119. }
  9120. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9121. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9122. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9123. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9124. {
  9125. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9126. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9127. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9128. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9129. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9130. {
  9131. confirmPeriods = idx;
  9132. break;
  9133. }
  9134. }
  9135. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9136. {
  9137. confirmPeriods += 1;
  9138. }
  9139. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9140. }
  9141. else
  9142. {
  9143. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9144. }
  9145. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9146. return result;
  9147. }
  9148. int handleGetConfigurationRequest(char *uuid, char *payload)
  9149. {
  9150. mtrace();
  9151. int result = FAIL;
  9152. int MaxKeySupported = 0;
  9153. int n_keys = 0;
  9154. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9155. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9156. json_object *GetConfiguration;
  9157. GetConfiguration = json_tokener_parse(payload);
  9158. if(!is_error(GetConfiguration))
  9159. {
  9160. // Optional data
  9161. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9162. {
  9163. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9164. {
  9165. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9166. n_keys = idx + 1;
  9167. }
  9168. }
  9169. }
  9170. json_object_put(GetConfiguration);
  9171. UnknownKeynum = 0;
  9172. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9173. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9174. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9175. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9176. if(n_keys != 0)
  9177. {
  9178. for(int i=0;i<n_keys;i++)
  9179. {
  9180. getKeyValue(requestKey[i]);
  9181. }
  9182. }
  9183. else
  9184. {
  9185. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9186. getKeyValue("");
  9187. }
  9188. processUnkownKey();
  9189. sendGetConfigurationConfirmation(uuid);
  9190. return result;
  9191. }
  9192. static char fnamePlusPath[100]={0};
  9193. static char fnamePWithNoPath[60]={0};
  9194. void checkUploadLog(void)
  9195. {
  9196. FILE *fp;
  9197. /* Open the command for reading. */
  9198. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9199. if (fp == NULL) {
  9200. DEBUG_WARN("Failed to run command\n" );
  9201. exit(1);
  9202. }
  9203. int ftppathlen = 0;
  9204. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9205. int i = 0;
  9206. /* Read the output a line at a time - output it. */
  9207. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9208. if(i==0)
  9209. {
  9210. ftppathlen = strlen(fnamePlusPath);
  9211. DEBUG_INFO("%s\n", fnamePlusPath);
  9212. fnamePlusPath[ftppathlen]='\0';
  9213. break;
  9214. }
  9215. i= i+1;
  9216. }
  9217. /* close */
  9218. pclose(fp);
  9219. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9220. {
  9221. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9222. {
  9223. fnamePlusPath[k]='\0';
  9224. }
  9225. }
  9226. i=1;
  9227. //char fname[60]={0};
  9228. while(i < ftppathlen)
  9229. {
  9230. int len=ftppathlen-i;
  9231. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9232. {
  9233. DEBUG_INFO("compare '/' all right\n");
  9234. break;
  9235. }
  9236. i=i+1;
  9237. }
  9238. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9239. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9240. fnamePWithNoPath[i+1] = '\0';
  9241. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9242. {
  9243. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9244. {
  9245. fnamePWithNoPath[j]='\0';
  9246. }
  9247. }
  9248. FILE* fp1 = fopen(fnamePlusPath, "r");
  9249. if (fp1)
  9250. {
  9251. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9252. // file exists
  9253. fclose(fp1);
  9254. }
  9255. else
  9256. {
  9257. // file doesn't exist
  9258. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9259. }
  9260. }
  9261. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9262. {
  9263. mtrace();
  9264. int result = FAIL;
  9265. time_t CurrentTime;
  9266. struct tm *tm;
  9267. pthread_t th_Status;
  9268. CurrentTime = time(NULL);
  9269. tm = localtime(&CurrentTime);
  9270. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9271. 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);
  9272. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9273. if(!interLock.isGetDiagnosticGoing)
  9274. {
  9275. interLock.isGetDiagnosticGoing = 1;
  9276. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9277. sleep(1);
  9278. }
  9279. else
  9280. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9281. return result;
  9282. }
  9283. void* GetDiagnosticsProcess(void* data)
  9284. {
  9285. pthread_detach(pthread_self());
  9286. mtrace();
  9287. int retriesInt=0, retryIntervalInt=0;
  9288. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9289. 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};
  9290. int port=0;
  9291. int isSuccess = FALSE;
  9292. char ftpbuf[200]={0};
  9293. char cmdBuf[2048];
  9294. struct tm *tmNow;
  9295. time_t CurrentTime;
  9296. struct tm tmStart;
  9297. struct tm tmStop;
  9298. CurrentTime = time(NULL);
  9299. tmNow=localtime(&CurrentTime);
  9300. uint16_t targetYear, targetMonth;
  9301. json_object *GetDiagnostics;
  9302. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9303. GetDiagnostics = json_tokener_parse(data);
  9304. if(!is_error(GetDiagnostics))
  9305. {
  9306. // Required data
  9307. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9308. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9309. // Optional data
  9310. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9311. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9312. else
  9313. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9314. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9315. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9316. else
  9317. retryIntervalInt = 30;
  9318. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9319. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9320. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9321. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9322. }
  9323. json_object_put(GetDiagnostics);
  9324. // Pack log to compress file
  9325. 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) &&
  9326. (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))
  9327. {
  9328. // Pack system log
  9329. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9330. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9331. targetYear = tmStart.tm_year;
  9332. targetMonth = tmStart.tm_mon;
  9333. do
  9334. {
  9335. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9336. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9337. if(targetMonth+1>=13)
  9338. {
  9339. targetYear += 1;
  9340. targetMonth = 1;
  9341. }
  9342. else
  9343. {
  9344. targetMonth += 1;
  9345. }
  9346. }while((targetYear < (tmNow->tm_year+1900)) ||
  9347. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9348. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9349. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9350. system(cmdBuf);
  9351. // Pack charging & event log
  9352. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9353. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9354. targetYear = tmStart.tm_year;
  9355. targetMonth = tmStart.tm_mon;
  9356. do
  9357. {
  9358. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9359. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9360. if(targetMonth+1>=13)
  9361. {
  9362. targetYear += 1;
  9363. targetMonth = 1;
  9364. }
  9365. else
  9366. {
  9367. targetMonth += 1;
  9368. }
  9369. }while((targetYear < (tmNow->tm_year+1900)) ||
  9370. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9371. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9372. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9373. system(cmdBuf);
  9374. // Combine log file
  9375. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9376. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9377. }
  9378. else
  9379. {
  9380. system("exec /root/logPackTools 'log' 6");
  9381. }
  9382. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9383. system(cmdBuf);
  9384. checkUploadLog();
  9385. //****************location*******************/
  9386. if(strcmp(locationstr,"")==0)
  9387. {
  9388. DEBUG_INFO("location is <Empty>!\n");
  9389. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9390. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9391. goto end;
  9392. }
  9393. memset(protocol, 0, ARRAY_SIZE(protocol));
  9394. memset(user, 0, ARRAY_SIZE(user) );
  9395. memset(password, 0, ARRAY_SIZE(password));
  9396. memset(host, 0, ARRAY_SIZE(host));
  9397. memset(path, 0, ARRAY_SIZE(path));
  9398. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9399. memset(host1, 0, ARRAY_SIZE(host1));
  9400. memset(path1, 0, ARRAY_SIZE(path1));
  9401. /*location: ftp://user:password@host:port/path*/
  9402. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9403. if((access(fnamePlusPath,F_OK))!=-1)
  9404. {
  9405. DEBUG_INFO("fnamePlusPath exist.\n");
  9406. }
  9407. else
  9408. {
  9409. DEBUG_INFO("fnamePlusPath not exist!\n");
  9410. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9411. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9412. goto end;
  9413. }
  9414. if(strchr(locationstr,'@')==NULL)
  9415. {
  9416. sscanf(locationstr,
  9417. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9418. protocol, host, &port, path);
  9419. strcpy(user,"anonymous");
  9420. strcpy(password,"");
  9421. }
  9422. else
  9423. {
  9424. //DEBUG_INFO("pch=%s\n", pch);
  9425. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9426. protocol, user, password, host, &port, path);
  9427. }
  9428. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9429. {
  9430. DEBUG_INFO("protocol is not ftp/http ! \n");
  9431. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9432. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9433. goto end;
  9434. }
  9435. if(strncmp(locationstr,"http", 4) == 0)
  9436. {
  9437. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9438. sprintf(ftppath,"/%s", path);
  9439. do
  9440. {
  9441. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9442. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9443. sleep(3);
  9444. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9445. if(!isSuccess)
  9446. {
  9447. DEBUG_INFO("Diagnostics fail.\n");
  9448. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9449. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9450. sleep(retryIntervalInt);
  9451. }
  9452. else
  9453. {
  9454. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9455. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9456. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9457. }
  9458. retriesInt--;
  9459. }while((isSuccess == 0)&&(retriesInt >= 0));
  9460. }
  9461. else
  9462. {
  9463. sscanf(host,"%[^/]%s",host1, path1);
  9464. if(strlen(path) > 0)
  9465. sprintf(ftppath,"/%s", path);
  9466. else
  9467. sprintf(ftppath,"/%s", path1);
  9468. int ftppathlen=strlen(ftppath);
  9469. int i=1;
  9470. char filenametemp[50];
  9471. while(i < ftppathlen)
  9472. {
  9473. int len=ftppathlen-i;
  9474. if(ftppath[len]== 47) // '/' ascll code: 47
  9475. {
  9476. DEBUG_INFO("find '/' all right\n");
  9477. break;
  9478. }
  9479. i=i+1;
  9480. }
  9481. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9482. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9483. filenametemp[i+1] = 0;
  9484. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9485. if(port == 0)
  9486. port = 21;
  9487. do
  9488. {
  9489. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9490. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9491. sleep(3);
  9492. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9493. if(!isSuccess)
  9494. {
  9495. DEBUG_INFO("Diagnostics fail.\n");
  9496. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9497. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9498. sleep(retryIntervalInt);
  9499. }
  9500. else
  9501. {
  9502. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9503. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9504. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9505. }
  9506. retriesInt--;
  9507. }while((!isSuccess)&&(retriesInt >= 0));
  9508. }
  9509. end:
  9510. system("rm -f /mnt/*");
  9511. sleep(5);
  9512. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9513. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9514. interLock.isGetDiagnosticGoing = 0;
  9515. pthread_exit(NULL);
  9516. }
  9517. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9518. {
  9519. mtrace();
  9520. int result = FAIL;
  9521. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9522. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9523. {
  9524. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9525. locallistVersion = -1;
  9526. }
  9527. else
  9528. {
  9529. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9530. OCPP_getListVerion();
  9531. }
  9532. //from db.OCPP_getListVerion
  9533. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9534. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9535. sendGetLocalListVersionConfirmation(uuid,"");
  9536. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9537. return result;
  9538. }
  9539. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9540. {
  9541. mtrace();
  9542. int result = FAIL;
  9543. int connectorIdInt=-1;
  9544. int tempIndex = 0;
  9545. int connectorIdIsNULL, chargingProfileIsNULL;
  9546. char comfirmstr[20]={0};
  9547. char cmdBuf[512];
  9548. json_object *RemoteStartTransaction;
  9549. FILE *fp;
  9550. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9551. if(server_pending == TRUE)
  9552. {
  9553. return 0;
  9554. }
  9555. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9556. RemoteStartTransaction = json_tokener_parse(payload);
  9557. if(!is_error(RemoteStartTransaction))
  9558. {
  9559. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9560. {
  9561. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9562. }
  9563. else
  9564. {
  9565. connectorIdIsNULL = TRUE;
  9566. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9567. {
  9568. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9569. {
  9570. connectorIdIsNULL = FALSE;
  9571. connectorIdInt = (gun_index+1);
  9572. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9573. break;
  9574. }
  9575. }
  9576. }
  9577. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9578. {
  9579. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9580. // Required data
  9581. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9582. // Optional data
  9583. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9584. {
  9585. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9586. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9587. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9588. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9589. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9590. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9591. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9592. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9593. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9594. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9595. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9596. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9597. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9598. {
  9599. 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")));
  9600. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9601. 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"));
  9602. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9603. 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"));
  9604. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9605. 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")));
  9606. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9607. {
  9608. 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++)
  9609. {
  9610. 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"));
  9611. 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"));
  9612. 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)
  9613. 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"));
  9614. }
  9615. }
  9616. }
  9617. }
  9618. else
  9619. {
  9620. chargingProfileIsNULL = TRUE;
  9621. }
  9622. }
  9623. }
  9624. else
  9625. {
  9626. connectorIdIsNULL = TRUE;
  9627. }
  9628. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9629. {
  9630. DEBUG_WARN("Connector id is NULL\n.");
  9631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9632. goto end;
  9633. }
  9634. /*
  9635. enum _SYSTEM_STATUS
  9636. {
  9637. S_BOOTING = 0,
  9638. S_IDLE, = 1
  9639. S_AUTHORIZING, = 2
  9640. S_REASSIGN_CHECK, = 3
  9641. S_REASSIGN, = 4
  9642. S_PRECHARGE, = 5
  9643. S_PREPARING_FOR_EV, = 6
  9644. S_PREPARING_FOR_EVSE, = 7
  9645. S_CHARGING, = 8
  9646. S_TERMINATING, = 9
  9647. S_COMPLETE, = 10
  9648. S_ALARM, = 11
  9649. S_FAULT = 12
  9650. }
  9651. */
  9652. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9653. {
  9654. //check Transaction active
  9655. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9656. {
  9657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9658. {
  9659. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9660. }
  9661. else
  9662. {
  9663. tempIndex = connectorIdInt -1;
  9664. }
  9665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9666. {
  9667. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9668. {
  9669. 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))
  9670. {
  9671. //Reserved
  9672. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9673. }
  9674. 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))
  9675. {
  9676. //Reserved
  9677. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9678. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9679. goto end;
  9680. }
  9681. else
  9682. {
  9683. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9684. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9685. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9686. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9687. {
  9688. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9689. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9690. goto end;
  9691. }
  9692. }//END FOR ELSE
  9693. }
  9694. }// END FOR CHAdeMO_QUANTITY
  9695. }
  9696. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9697. {
  9698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9699. {
  9700. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9701. }
  9702. else
  9703. {
  9704. tempIndex = connectorIdInt -1;
  9705. }
  9706. for (int index = 0; index < CCS_QUANTITY; index++)
  9707. {
  9708. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9709. {
  9710. 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))
  9711. {
  9712. //Reserved
  9713. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9714. }
  9715. 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))
  9716. {
  9717. //Reserved
  9718. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9719. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9720. goto end;
  9721. }
  9722. else
  9723. {
  9724. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9725. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9726. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9727. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9728. {
  9729. DEBUG_WARN("CCS connector not allow start\n.");
  9730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9731. goto end;
  9732. }
  9733. }// END FOR ELSE
  9734. }
  9735. }// END FOR CCS_QUANTITY
  9736. }
  9737. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9738. {
  9739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9740. {
  9741. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9742. }
  9743. else
  9744. {
  9745. tempIndex = connectorIdInt -1;
  9746. }
  9747. for (int index = 0; index < GB_QUANTITY; index++)
  9748. {
  9749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9750. {
  9751. 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))
  9752. {
  9753. //Reserved
  9754. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9755. }
  9756. 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))
  9757. {
  9758. //Reserved
  9759. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9760. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9761. goto end;
  9762. }
  9763. else
  9764. {
  9765. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9766. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9767. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9768. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9769. {
  9770. DEBUG_WARN("GB connector not allow start\n.");
  9771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9772. goto end;
  9773. }
  9774. }// END FOR ELSE
  9775. }
  9776. } // END FOR GB_QUANTITY
  9777. }
  9778. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9779. {
  9780. tempIndex = connectorIdInt -1;
  9781. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9782. {
  9783. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9784. {
  9785. 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))
  9786. {
  9787. //Reserved
  9788. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9789. }
  9790. 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))
  9791. {
  9792. //Reserved
  9793. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9794. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9795. goto end;
  9796. }
  9797. else
  9798. {
  9799. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9800. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9801. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9802. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9803. {
  9804. DEBUG_WARN("GB connector not allow start\n.");
  9805. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9806. goto end;
  9807. }
  9808. }// END FOR ELSE
  9809. }
  9810. } // END FOR GB_QUANTITY
  9811. }
  9812. else
  9813. {
  9814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9815. {
  9816. tempIndex = 2;
  9817. }
  9818. else
  9819. {
  9820. tempIndex = connectorIdInt -1;
  9821. }
  9822. for (int index = 0; index < AC_QUANTITY; index++)
  9823. {
  9824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9825. {
  9826. 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))
  9827. {
  9828. //Reserved
  9829. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9830. }
  9831. 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))
  9832. {
  9833. //Reserved
  9834. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9835. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9836. goto end;
  9837. }
  9838. else
  9839. {
  9840. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9841. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9842. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9843. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9844. {
  9845. DEBUG_WARN("AC connector not allow start\n.");
  9846. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9847. goto end;
  9848. }
  9849. }//END FOR ELSE
  9850. }
  9851. }// END FOR AC_QUANTITY
  9852. }
  9853. if(chargingProfileIsNULL == FALSE)
  9854. {
  9855. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9856. {
  9857. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9858. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9859. //memset idTag
  9860. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9861. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9862. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9864. // Save profile to file
  9865. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9866. system(cmdBuf);
  9867. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9868. fp = fopen(cmdBuf, "w");
  9869. 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));
  9870. fclose(fp);
  9871. }
  9872. else
  9873. {
  9874. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9875. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9876. }
  9877. }
  9878. else
  9879. {
  9880. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9881. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9882. //memset idTag
  9883. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9884. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9885. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9886. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9887. }
  9888. }
  9889. else
  9890. {
  9891. DEBUG_WARN("Connector id over\n.");
  9892. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9893. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9894. }
  9895. end:
  9896. json_object_put(RemoteStartTransaction);
  9897. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9898. {
  9899. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9900. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9901. }
  9902. //OCPP send RemoteStartConfirmation by first.
  9903. sendRemoteStartConfirmation(uuid, comfirmstr);
  9904. return result;
  9905. }
  9906. int handleRemoteStartRequest(char *uuid, char *payload)
  9907. {
  9908. mtrace();
  9909. int result = PASS;
  9910. int connectorIdInt=-1;
  9911. int tempIndex = 0;
  9912. char comfirmstr[20]={0};
  9913. char cmdBuf[512];
  9914. json_object *RemoteStartTransaction;
  9915. FILE *fp;
  9916. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9917. if(server_pending == TRUE)
  9918. {
  9919. result = FAIL;
  9920. }
  9921. RemoteStartTransaction = json_tokener_parse(payload);
  9922. if(!is_error(RemoteStartTransaction))
  9923. {
  9924. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9925. {
  9926. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9927. }
  9928. else
  9929. {
  9930. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9931. {
  9932. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9933. {
  9934. connectorIdInt = (gun_index+1);
  9935. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9936. break;
  9937. }
  9938. }
  9939. }
  9940. if(connectorIdInt == 0)
  9941. {
  9942. DEBUG_WARN("Connector id shall not equal 0.\n");
  9943. result = FAIL;
  9944. }
  9945. else if(connectorIdInt == -1)
  9946. {
  9947. DEBUG_INFO("Connector id does not specific.\n");
  9948. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9949. {
  9950. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  9951. // Required data
  9952. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9953. // Optional data
  9954. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9955. {
  9956. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9957. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9958. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9959. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9960. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9961. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9962. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9963. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9964. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9965. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9966. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9967. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9968. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9969. {
  9970. 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")));
  9971. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9972. 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"));
  9973. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9974. 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"));
  9975. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9976. 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")));
  9977. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9978. {
  9979. 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++)
  9980. {
  9981. 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"));
  9982. 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"));
  9983. 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)
  9984. 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"));
  9985. }
  9986. }
  9987. }
  9988. }
  9989. else
  9990. {
  9991. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  9992. }
  9993. }
  9994. }
  9995. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  9996. {
  9997. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  9998. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9999. // Required data
  10000. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10001. // Optional data
  10002. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10003. {
  10004. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10005. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10006. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10007. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10008. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10009. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10010. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10011. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10012. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10013. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10014. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10015. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10016. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10017. {
  10018. 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")));
  10019. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10020. 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"));
  10021. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10022. 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"));
  10023. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10024. 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")));
  10025. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10026. {
  10027. 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++)
  10028. {
  10029. 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"));
  10030. 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"));
  10031. 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)
  10032. 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"));
  10033. }
  10034. }
  10035. }
  10036. }
  10037. else
  10038. {
  10039. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10040. }
  10041. }
  10042. else
  10043. {
  10044. DEBUG_WARN("Connector id is over maximun value.\n");
  10045. result = FAIL;
  10046. }
  10047. }
  10048. if(result == PASS)
  10049. {
  10050. if(connectorIdInt > 0)
  10051. {
  10052. //check Transaction active
  10053. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10054. {
  10055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10056. {
  10057. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10058. }
  10059. else
  10060. {
  10061. tempIndex = connectorIdInt -1;
  10062. }
  10063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10064. {
  10065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10066. {
  10067. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10068. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10069. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10070. {
  10071. //Reserved
  10072. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10073. }
  10074. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10075. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10076. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10077. {
  10078. //Reserved
  10079. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10081. goto end;
  10082. }
  10083. else
  10084. {
  10085. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10086. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10087. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10088. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10089. {
  10090. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10091. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10092. goto end;
  10093. }
  10094. }//END FOR ELSE
  10095. }
  10096. }// END FOR CHAdeMO_QUANTITY
  10097. }
  10098. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10099. {
  10100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10101. {
  10102. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10103. }
  10104. else
  10105. {
  10106. tempIndex = connectorIdInt -1;
  10107. }
  10108. for (int index = 0; index < CCS_QUANTITY; index++)
  10109. {
  10110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10111. {
  10112. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10113. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10114. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10115. {
  10116. //Reserved
  10117. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10118. }
  10119. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10120. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10121. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10122. {
  10123. //Reserved
  10124. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10125. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10126. goto end;
  10127. }
  10128. else
  10129. {
  10130. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10131. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10132. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10133. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10134. {
  10135. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10136. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10137. goto end;
  10138. }
  10139. }// END FOR ELSE
  10140. }
  10141. }// END FOR CCS_QUANTITY
  10142. }
  10143. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10144. {
  10145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10146. {
  10147. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10148. }
  10149. else
  10150. {
  10151. tempIndex = connectorIdInt -1;
  10152. }
  10153. for (int index = 0; index < GB_QUANTITY; index++)
  10154. {
  10155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10156. {
  10157. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10158. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10159. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10160. {
  10161. //Reserved
  10162. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10163. }
  10164. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10165. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10166. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10167. {
  10168. //Reserved
  10169. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10171. goto end;
  10172. }
  10173. else
  10174. {
  10175. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10176. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10177. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10178. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10179. {
  10180. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10181. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10182. goto end;
  10183. }
  10184. }// END FOR ELSE
  10185. }
  10186. } // END FOR GB_QUANTITY
  10187. }
  10188. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10189. {
  10190. tempIndex = connectorIdInt -1;
  10191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10192. {
  10193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10194. {
  10195. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10196. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10197. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10198. {
  10199. //Reserved
  10200. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10201. }
  10202. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10203. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10204. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10205. {
  10206. //Reserved
  10207. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10208. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10209. goto end;
  10210. }
  10211. else
  10212. {
  10213. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10214. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10215. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10216. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10217. {
  10218. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10219. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10220. goto end;
  10221. }
  10222. }// END FOR ELSE
  10223. }
  10224. } // END FOR GB_QUANTITY
  10225. }
  10226. else
  10227. {
  10228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10229. {
  10230. tempIndex = 2;
  10231. }
  10232. else
  10233. {
  10234. tempIndex = connectorIdInt -1;
  10235. }
  10236. for (int index = 0; index < AC_QUANTITY; index++)
  10237. {
  10238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10239. {
  10240. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10241. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10242. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10243. {
  10244. //Reserved
  10245. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10246. }
  10247. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10248. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10249. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10250. {
  10251. //Reserved
  10252. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10253. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10254. goto end;
  10255. }
  10256. else
  10257. {
  10258. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10259. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10260. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10261. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10262. {
  10263. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10265. goto end;
  10266. }
  10267. }//END FOR ELSE
  10268. }
  10269. }// END FOR AC_QUANTITY
  10270. }
  10271. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10272. {
  10273. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10274. {
  10275. // Save profile to file
  10276. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10277. system(cmdBuf);
  10278. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10279. fp = fopen(cmdBuf, "w");
  10280. 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));
  10281. fclose(fp);
  10282. }
  10283. else
  10284. {
  10285. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10286. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10287. goto end;
  10288. }
  10289. }
  10290. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10292. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10293. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10294. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10295. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10296. }
  10297. else
  10298. {
  10299. uint8_t isHasIdleConnector = FALSE;
  10300. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10301. {
  10302. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10303. {
  10304. isHasIdleConnector = TRUE;
  10305. break;
  10306. }
  10307. }
  10308. if(isHasIdleConnector == TRUE)
  10309. {
  10310. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10311. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10312. {
  10313. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10314. {
  10315. // Save profile to file
  10316. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10317. system(cmdBuf);
  10318. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10319. fp = fopen(cmdBuf, "w");
  10320. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10321. fclose(fp);
  10322. refreshStartTimer(&clientTime.RemoteStartWait);
  10323. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10324. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10325. }
  10326. else
  10327. {
  10328. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10329. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10330. }
  10331. }
  10332. }
  10333. else
  10334. {
  10335. DEBUG_INFO("There is not any connector is idle.\n");
  10336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10337. }
  10338. }
  10339. }
  10340. else
  10341. {
  10342. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10343. }
  10344. end:
  10345. json_object_put(RemoteStartTransaction);
  10346. sendRemoteStartConfirmation(uuid, comfirmstr);
  10347. return result;
  10348. }
  10349. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10350. {
  10351. mtrace();
  10352. int result = FAIL;
  10353. int match = FALSE;
  10354. int GunNO = 0;
  10355. int tempIndex = 0;
  10356. int transactionIdInt=0;
  10357. int transactionIdIsNULL= TRUE;
  10358. char comfirmstr[20];
  10359. json_object *RemoteStopTransaction;
  10360. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10361. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10362. if(server_pending == TRUE)
  10363. {
  10364. return 0;
  10365. }
  10366. RemoteStopTransaction = json_tokener_parse(payload);
  10367. if(!is_error(RemoteStopTransaction))
  10368. {
  10369. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10370. {
  10371. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10372. transactionIdIsNULL = FALSE;
  10373. }
  10374. }
  10375. json_object_put(RemoteStopTransaction);
  10376. if(transactionIdIsNULL == FALSE)
  10377. {
  10378. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10379. {
  10380. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10381. {
  10382. //check Transaction active
  10383. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10384. {
  10385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10386. {
  10387. tempIndex = ((gun_index==2) ? 1: 0);
  10388. }
  10389. else
  10390. {
  10391. tempIndex = gun_index;
  10392. }
  10393. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10394. {
  10395. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10396. {
  10397. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10398. {
  10399. match = TRUE;
  10400. GunNO = gun_index;
  10401. }
  10402. }
  10403. }// END FOR CHAdeMO_QUANTITY
  10404. }
  10405. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10406. {
  10407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10408. {
  10409. tempIndex = ((gun_index==2) ? 1: 0);
  10410. }
  10411. else
  10412. {
  10413. tempIndex = gun_index;
  10414. }
  10415. for (int index = 0; index < CCS_QUANTITY; index++)
  10416. {
  10417. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10418. {
  10419. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10420. {
  10421. match = TRUE;
  10422. GunNO = gun_index;
  10423. }
  10424. }
  10425. }// END FOR CCS_QUANTITY
  10426. }
  10427. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10428. {
  10429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10430. {
  10431. tempIndex = ((gun_index==2) ? 1: 0);
  10432. }
  10433. else
  10434. {
  10435. tempIndex = gun_index;
  10436. }
  10437. for (int index = 0; index < GB_QUANTITY; index++)
  10438. {
  10439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10440. {
  10441. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10442. {
  10443. match = TRUE;
  10444. GunNO = gun_index;
  10445. }
  10446. }
  10447. }// END FOR GB_QUANTITY
  10448. }
  10449. else if(gunType[gun_index] == GUN_TYPE_DO)
  10450. {
  10451. tempIndex = gun_index;
  10452. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10453. {
  10454. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10455. {
  10456. 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
  10457. {
  10458. match = TRUE;
  10459. GunNO = gun_index;
  10460. }
  10461. }
  10462. }// END FOR GB_QUANTITY
  10463. }
  10464. else
  10465. {
  10466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10467. {
  10468. tempIndex = 2;
  10469. }
  10470. else
  10471. {
  10472. tempIndex = gun_index;
  10473. }
  10474. for (int index = 0; index < AC_QUANTITY; index++)
  10475. {
  10476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10477. {
  10478. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10479. {
  10480. match = TRUE;
  10481. GunNO = gun_index;
  10482. }
  10483. }
  10484. }// END FOR CHAdeMO_QUANTITY
  10485. } // END FOR AC ELSE
  10486. }// CHECK IF ResponseTransactionId == transactionIdInt
  10487. }//END FOR
  10488. if( match == TRUE)
  10489. {
  10490. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10491. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10492. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10493. }
  10494. else
  10495. {
  10496. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10497. }
  10498. }
  10499. else
  10500. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10501. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10502. return result;
  10503. }
  10504. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10505. {
  10506. mtrace();
  10507. int result = FAIL;
  10508. int connectorIdInt=0, reservationIdInt=0;
  10509. int tempIndex = 0;
  10510. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10511. char comfirmstr[20]={0};
  10512. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10513. int c = 0;
  10514. char *loc;
  10515. //char *ptr;
  10516. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10517. strcpy(sstrtemp, stringtrimspace(payload));
  10518. //***(1)connectorId ****/
  10519. c=0;
  10520. loc = strstr(sstrtemp, "connectorId");
  10521. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10522. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10523. {
  10524. sstr[c] = loc[strlen("connectorId")+2+c];
  10525. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10526. c++;
  10527. }
  10528. sstr[c] = '\0';
  10529. connectorIdInt = atoi(sstr);
  10530. //***(2)expiryDate ****/
  10531. loc = strstr(sstrtemp, "expiryDate");
  10532. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10533. c = 0;
  10534. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10535. {
  10536. sstr[c] = loc[3+strlen("expiryDate")+c];
  10537. c++;
  10538. }
  10539. sstr[c] = '\0';
  10540. strcpy(expiryDatestr, sstr);
  10541. //***(3)idTag ****/
  10542. loc = strstr(sstrtemp, "idTag");
  10543. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10544. c = 0;
  10545. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10546. {
  10547. sstr[c] = loc[3+strlen("idTag")+c];
  10548. c++;
  10549. }
  10550. sstr[c] = '\0';
  10551. strcpy(idTagstr, sstr);
  10552. //***(4)parentIdTag ****/
  10553. loc = strstr(sstrtemp, "parentIdTag");
  10554. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10555. c = 0;
  10556. if(loc == NULL)
  10557. {
  10558. strcpy(parentIdTagstr, "");
  10559. }
  10560. else
  10561. {
  10562. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10563. {
  10564. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10565. c++;
  10566. }
  10567. sstr[c] = '\0';
  10568. strcpy(parentIdTagstr, sstr);
  10569. }
  10570. //***(5)reservationId ****/
  10571. c=0;
  10572. loc = strstr(sstrtemp, "reservationId");
  10573. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10574. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10575. {
  10576. sstr[c] = loc[strlen("reservationId")+2+c];
  10577. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10578. c++;
  10579. }
  10580. sstr[c] = '\0';
  10581. reservationIdInt = atoi(sstr);
  10582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10583. /*
  10584. enum SYSTEM_STATUS
  10585. {
  10586. SYS_MODE_BOOTING = 0,
  10587. SYS_MODE_IDLE = 1,
  10588. SYS_MODE_AUTHORIZING = 2,
  10589. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10590. SYS_MODE_REASSIGN = 4,
  10591. SYS_MODE_PREPARING = 5,
  10592. SYS_MODE_PREPARE_FOR_EV = 6,
  10593. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10594. SYS_MODE_CHARGING = 8,
  10595. SYS_MODE_TERMINATING = 9,
  10596. SYS_MODE_COMPLETE = 10,
  10597. SYS_MODE_ALARM = 11,
  10598. SYS_MODE_FAULT = 12,
  10599. SYS_MODE_RESERVATION = 13,
  10600. SYS_MODE_BOOKING = 14,
  10601. SYS_MODE_MAINTAIN = 15,
  10602. SYS_MODE_DEBUG = 16,
  10603. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10604. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10605. SYS_MODE_UPDATE = 19
  10606. };
  10607. */
  10608. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10609. {
  10610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10611. goto end;
  10612. }
  10613. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10614. {
  10615. //check Transaction active
  10616. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10617. {
  10618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10619. {
  10620. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10621. }
  10622. else
  10623. {
  10624. tempIndex = connectorIdInt -1;
  10625. }
  10626. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10627. {
  10628. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10629. {
  10630. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10631. {
  10632. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10633. {
  10634. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10635. {
  10636. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10638. }
  10639. 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'))
  10640. {
  10641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10642. }
  10643. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10644. {
  10645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10646. }
  10647. else
  10648. {
  10649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10650. }
  10651. }
  10652. 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
  10653. {
  10654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10655. }
  10656. }
  10657. else
  10658. {
  10659. //replace reservation
  10660. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10662. }
  10663. }
  10664. } // END FOR CHAdeMO_QUANTITY
  10665. }
  10666. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10667. {
  10668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10669. {
  10670. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10671. }
  10672. else
  10673. {
  10674. tempIndex = connectorIdInt -1;
  10675. }
  10676. for (int index = 0; index < CCS_QUANTITY; index++)
  10677. {
  10678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10679. {
  10680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10681. {
  10682. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10683. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10684. {
  10685. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10686. {
  10687. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10689. }
  10690. 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'))
  10691. {
  10692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10693. }
  10694. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10695. {
  10696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10697. }
  10698. else
  10699. {
  10700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10701. }
  10702. }
  10703. 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
  10704. {
  10705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10706. }
  10707. }
  10708. else
  10709. {
  10710. //replace reservation
  10711. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10713. }
  10714. }
  10715. } // END FOR CCS_QUANTITY
  10716. }
  10717. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10718. {
  10719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10720. {
  10721. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10722. }
  10723. else
  10724. {
  10725. tempIndex = connectorIdInt -1;
  10726. }
  10727. for (int index = 0; index < GB_QUANTITY; index++)
  10728. {
  10729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10730. {
  10731. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10732. {
  10733. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10734. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10735. {
  10736. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10737. {
  10738. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10740. }
  10741. 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'))
  10742. {
  10743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10744. }
  10745. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10746. {
  10747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10748. }
  10749. else
  10750. {
  10751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10752. }
  10753. }
  10754. 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
  10755. {
  10756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10757. }
  10758. }
  10759. else
  10760. {
  10761. //replace reservation
  10762. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10764. }
  10765. }
  10766. }// END FOR GB_QUANTITY
  10767. }
  10768. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10769. {
  10770. tempIndex = connectorIdInt -1;
  10771. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10772. {
  10773. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10774. {
  10775. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10776. {
  10777. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10778. 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
  10779. {
  10780. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10781. {
  10782. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10784. }
  10785. 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'))
  10786. {
  10787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10788. }
  10789. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10790. {
  10791. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10792. }
  10793. else
  10794. {
  10795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10796. }
  10797. }
  10798. 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
  10799. {
  10800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10801. }
  10802. }
  10803. else
  10804. {
  10805. //replace reservation
  10806. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10807. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10808. }
  10809. }
  10810. }// END FOR GB_QUANTITY
  10811. }
  10812. else
  10813. {
  10814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10815. {
  10816. tempIndex = 2;
  10817. }
  10818. else
  10819. {
  10820. tempIndex = (connectorIdInt -1);
  10821. }
  10822. for (int index = 0; index < AC_QUANTITY; index++)
  10823. {
  10824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10825. {
  10826. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10827. {
  10828. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10829. {
  10830. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10831. {
  10832. 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))
  10833. {
  10834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10835. }
  10836. else
  10837. {
  10838. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10840. }
  10841. }
  10842. 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'))
  10843. {
  10844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10845. }
  10846. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10847. {
  10848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10849. }
  10850. else
  10851. {
  10852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10853. }
  10854. }
  10855. 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
  10856. {
  10857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10858. }
  10859. }
  10860. else
  10861. {
  10862. //replace reservation
  10863. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10865. }
  10866. }
  10867. } // END FOR AC_QUANTITY
  10868. }
  10869. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10870. }
  10871. else if(connectorIdInt == 0)
  10872. {
  10873. //check Transaction active
  10874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10875. {
  10876. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10877. {
  10878. 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'))
  10879. {
  10880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10881. goto end;
  10882. }
  10883. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10884. {
  10885. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10886. goto end;
  10887. }
  10888. 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
  10889. {
  10890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10891. goto end;
  10892. }
  10893. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10894. {
  10895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10896. goto end;
  10897. }
  10898. }
  10899. }// END FOR CHAdeMO_QUANTITY
  10900. for (int index = 0; index < CCS_QUANTITY; index++)
  10901. {
  10902. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10903. {
  10904. 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'))
  10905. {
  10906. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10907. goto end;
  10908. }
  10909. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10910. {
  10911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10912. goto end;
  10913. }
  10914. 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
  10915. {
  10916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10917. goto end;
  10918. }
  10919. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10920. {
  10921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10922. goto end;
  10923. }
  10924. }
  10925. } // END FOR CCS_QUANTITY
  10926. for (int index = 0; index < GB_QUANTITY; index++)
  10927. {
  10928. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10929. {
  10930. 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'))
  10931. {
  10932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10933. goto end;
  10934. }
  10935. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10936. {
  10937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10938. goto end;
  10939. }
  10940. 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
  10941. {
  10942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10943. goto end;
  10944. }
  10945. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10946. {
  10947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10948. goto end;
  10949. }
  10950. }
  10951. } // END FOR GB_QUANTITY
  10952. for (int index = 0; index < AC_QUANTITY; index++)
  10953. {
  10954. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10955. {
  10956. 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'))
  10957. {
  10958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10959. goto end;
  10960. }
  10961. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10962. {
  10963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10964. goto end;
  10965. }
  10966. 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
  10967. {
  10968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10969. goto end;
  10970. }
  10971. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10972. {
  10973. 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))
  10974. {
  10975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10976. goto end;
  10977. }
  10978. }
  10979. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10980. {
  10981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10982. goto end;
  10983. }
  10984. }
  10985. }// END FOR AC_QUANTITY
  10986. //The connectorId is 0
  10987. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10989. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10990. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10991. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10992. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10993. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10994. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10995. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10996. result = TRUE;
  10997. return result;
  10998. }
  10999. else
  11000. {
  11001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11002. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11003. }
  11004. if(strcmp(comfirmstr,"Accepted") == 0)
  11005. {
  11006. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11007. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11008. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11009. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11010. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11011. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11012. result = TRUE;
  11013. return result;
  11014. }
  11015. end:
  11016. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11017. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11018. return result;
  11019. }
  11020. int handleResetRequest(char *uuid, char *payload)
  11021. {
  11022. mtrace();
  11023. int result = FAIL;
  11024. char sstr[10]={0},sstrtemp[30]={ 0 };
  11025. char typestr[10]={0};
  11026. char comfirmstr[20]={0};
  11027. int c = 0;
  11028. char *loc;
  11029. DEBUG_INFO("handleResetRequest...\n");
  11030. strcpy(sstrtemp, stringtrimspace(payload));
  11031. loc = strstr(sstrtemp, "type");
  11032. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11033. c = 0;
  11034. while (loc[3+strlen("type")+c] != '\"')
  11035. {
  11036. sstr[c] = loc[3+strlen("type")+c];
  11037. c++;
  11038. }
  11039. sstr[c] = '\0';
  11040. strcpy(typestr,sstr);
  11041. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  11042. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11043. {
  11044. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  11045. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11046. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11047. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11048. }
  11049. else
  11050. {
  11051. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11052. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11053. result = PASS;
  11054. }
  11055. sendResetConfirmation(uuid, comfirmstr);
  11056. return result;
  11057. }
  11058. int handleSendLocalListRequest(char *uuid, char *payload)
  11059. {
  11060. mtrace();
  11061. int result = FAIL;
  11062. char comfirmstr[20];
  11063. int checkState_Faulted = FALSE;
  11064. json_object *SendLocalList;
  11065. DEBUG_INFO("handleSendLocalListRequest...\n");
  11066. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11067. {
  11068. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11069. goto end;
  11070. }
  11071. //check Charge Point state
  11072. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11073. {
  11074. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11075. {
  11076. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11077. }
  11078. }
  11079. for (int index = 0; index < CCS_QUANTITY; index++)
  11080. {
  11081. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11082. {
  11083. checkState_Faulted = TRUE; //OCPP Status
  11084. }
  11085. }
  11086. for (int index = 0; index < GB_QUANTITY; index++)
  11087. {
  11088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11089. {
  11090. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11091. }
  11092. }
  11093. //check Charge Point state
  11094. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11095. {
  11096. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11097. {
  11098. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11099. }
  11100. }
  11101. //check Charge Point state
  11102. for (int index = 0; index < AC_QUANTITY; index++)
  11103. {
  11104. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11105. {
  11106. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11107. }
  11108. }
  11109. if(checkState_Faulted == TRUE)
  11110. {
  11111. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11112. goto end;
  11113. }
  11114. // Parsing payload
  11115. SendLocalList = json_tokener_parse(payload);
  11116. if(!is_error(SendLocalList))
  11117. {
  11118. // Required data
  11119. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11120. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11121. // Optional data
  11122. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11123. {
  11124. //Check UpdateType
  11125. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11126. {
  11127. //Local list full update
  11128. DEBUG_INFO("Local list full update.\n");
  11129. OCPP_getListVerion();
  11130. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11131. {
  11132. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11133. goto end;
  11134. }
  11135. OCPP_cleanLocalList();
  11136. }
  11137. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11138. {
  11139. //Local list different update
  11140. DEBUG_INFO("Local list different update.\n");
  11141. OCPP_getListVerion();
  11142. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11143. {
  11144. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11145. goto end;
  11146. }
  11147. }
  11148. else
  11149. {
  11150. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11151. goto end;
  11152. }
  11153. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11154. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11155. {
  11156. 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")));
  11157. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11158. {
  11159. 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")));
  11160. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11161. 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")));
  11162. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11163. 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")));
  11164. }
  11165. // Add to db
  11166. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11167. {
  11168. //Local list full update
  11169. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11170. idx,
  11171. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11172. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11173. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11174. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11175. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11176. // update list
  11177. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11178. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11179. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11180. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11181. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11182. }
  11183. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11184. {
  11185. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11186. idx,
  11187. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11188. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11189. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11190. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11191. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11192. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11193. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11194. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11195. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11196. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11197. }
  11198. }
  11199. }
  11200. else
  11201. {
  11202. //Check UpdateType
  11203. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11204. {
  11205. //Local list full update
  11206. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11207. OCPP_cleanLocalList();
  11208. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11209. goto end;
  11210. }
  11211. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11212. {
  11213. //Local list different update
  11214. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11215. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11216. goto end;
  11217. }
  11218. }
  11219. result = PASS;
  11220. }
  11221. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11222. end:
  11223. json_object_put(SendLocalList);
  11224. sendSendLocalListConfirmation(uuid, comfirmstr);
  11225. return result;
  11226. }
  11227. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11228. {
  11229. mtrace();
  11230. int result = FAIL;
  11231. struct StructSetChargingProfile SetProfileReq = {0};
  11232. int tempchargingProfileIdInt;
  11233. int chargingSchedulePeriodCount = 0;
  11234. char comfirmstr[20]={0};
  11235. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11236. char rmFileCmd[128]={0};
  11237. int profileQuantity = 0;
  11238. json_object *SetChargingProfile;
  11239. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11240. SetChargingProfile = json_tokener_parse(payload);
  11241. if(!is_error(SetChargingProfile))
  11242. {
  11243. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11244. {
  11245. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11246. }
  11247. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11248. {
  11249. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11250. {
  11251. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11252. }
  11253. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11254. {
  11255. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11256. }
  11257. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11258. {
  11259. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11260. }
  11261. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11262. {
  11263. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11264. }
  11265. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11266. {
  11267. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11268. }
  11269. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11270. {
  11271. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11272. }
  11273. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11274. {
  11275. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11276. }
  11277. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11278. {
  11279. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11280. }
  11281. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11282. {
  11283. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11284. {
  11285. 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")));
  11286. }
  11287. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11288. {
  11289. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11290. }
  11291. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11292. {
  11293. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11294. }
  11295. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11296. {
  11297. 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")));
  11298. }
  11299. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11300. {
  11301. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11302. if(chargingSchedulePeriodCount <= 10)
  11303. {
  11304. 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++)
  11305. {
  11306. 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)
  11307. {
  11308. 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"));
  11309. }
  11310. 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)
  11311. {
  11312. 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"));
  11313. }
  11314. 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)
  11315. {
  11316. 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"));
  11317. }
  11318. }
  11319. }
  11320. }
  11321. }
  11322. }
  11323. }
  11324. // Profile periods quantity check
  11325. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11326. {
  11327. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11328. goto end;
  11329. }
  11330. // Check invalid limit
  11331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11332. {
  11333. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11334. {
  11335. 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)))) ||
  11336. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11337. {
  11338. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11339. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11340. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11341. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11342. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11343. goto end;
  11344. }
  11345. }
  11346. }
  11347. else
  11348. {
  11349. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11350. {
  11351. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:modelnameInfo.ParsingInfo[0].Current)))
  11352. {
  11353. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11354. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11355. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11356. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11357. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11358. goto end;
  11359. }
  11360. }
  11361. }
  11362. // Profile purpose info check
  11363. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11364. {
  11365. FILE *fp;
  11366. char dataLine[4096]={0};
  11367. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11368. if(SetProfileReq.ConnectorId != 0)
  11369. {
  11370. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11371. goto end;
  11372. }
  11373. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11374. if (!fp)
  11375. {
  11376. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11377. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11378. }
  11379. else
  11380. {
  11381. while(fscanf(fp, "%s", dataLine) != EOF)
  11382. {
  11383. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11384. {
  11385. profileQuantity += 1;
  11386. }
  11387. }
  11388. }
  11389. fclose(fp);
  11390. }
  11391. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11392. {
  11393. FILE *fp;
  11394. char dataLine[4096]={0};
  11395. char filename[128]={0};
  11396. int tmpProfileQuantity;
  11397. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11398. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11399. {
  11400. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11401. goto end;
  11402. }
  11403. if(SetProfileReq.ConnectorId == 0)
  11404. {
  11405. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11406. {
  11407. tmpProfileQuantity = 0;
  11408. memset(filename, 0, ARRAY_SIZE(filename));
  11409. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11410. fp = fopen(filename, "r");
  11411. if (!fp)
  11412. {
  11413. DEBUG_INFO("%s does not create.\n", filename);
  11414. fp = fopen(filename, "w+");
  11415. }
  11416. else
  11417. {
  11418. while(fscanf(fp, "%s", dataLine) != EOF)
  11419. {
  11420. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11421. {
  11422. tmpProfileQuantity += 1;
  11423. }
  11424. }
  11425. }
  11426. fclose(fp);
  11427. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11428. }
  11429. }
  11430. else
  11431. {
  11432. memset(filename, 0, ARRAY_SIZE(filename));
  11433. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11434. fp = fopen(filename, "r");
  11435. if (!fp)
  11436. {
  11437. DEBUG_INFO("%s does not create.\n", filename);
  11438. fp = fopen(filename, "w+");
  11439. }
  11440. else
  11441. {
  11442. while(fscanf(fp, "%s", dataLine) != EOF)
  11443. {
  11444. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11445. {
  11446. profileQuantity += 1;
  11447. }
  11448. }
  11449. }
  11450. fclose(fp);
  11451. }
  11452. }
  11453. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11454. {
  11455. int isMatchTransactiodId= FALSE;
  11456. FILE *fp;
  11457. char dataLine[4096]={0};
  11458. char filename[128]={0};
  11459. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11460. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11461. if(SetProfileReq.ConnectorId == 0)
  11462. {
  11463. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11464. goto end;
  11465. }
  11466. int tempIndex = 0;
  11467. //check Transaction active
  11468. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11469. {
  11470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11471. {
  11472. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11473. }
  11474. else
  11475. {
  11476. tempIndex = SetProfileReq.ConnectorId -1;
  11477. }
  11478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11479. {
  11480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11481. {
  11482. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11483. {
  11484. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11485. {
  11486. isMatchTransactiodId = TRUE;
  11487. break;
  11488. }
  11489. }
  11490. }
  11491. }
  11492. }
  11493. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11494. {
  11495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11496. {
  11497. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11498. }
  11499. else
  11500. {
  11501. tempIndex = SetProfileReq.ConnectorId -1;
  11502. }
  11503. for (int index = 0; index < CCS_QUANTITY; index++)
  11504. {
  11505. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11506. {
  11507. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11508. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11509. {
  11510. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11511. {
  11512. isMatchTransactiodId = TRUE;
  11513. break;
  11514. }
  11515. }
  11516. }
  11517. }
  11518. }
  11519. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11520. {
  11521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11522. {
  11523. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11524. }
  11525. else
  11526. {
  11527. tempIndex = SetProfileReq.ConnectorId -1;
  11528. }
  11529. for (int index = 0; index < GB_QUANTITY; index++)
  11530. {
  11531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11532. {
  11533. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11534. {
  11535. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11536. {
  11537. isMatchTransactiodId = TRUE;
  11538. break;
  11539. }
  11540. }
  11541. }
  11542. }
  11543. }
  11544. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11545. {
  11546. tempIndex = SetProfileReq.ConnectorId -1;
  11547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11548. {
  11549. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11550. {
  11551. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11552. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11553. {
  11554. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11555. {
  11556. isMatchTransactiodId = TRUE;
  11557. break;
  11558. }
  11559. }
  11560. }
  11561. }
  11562. }
  11563. else
  11564. {
  11565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11566. {
  11567. tempIndex = 2;
  11568. }
  11569. else
  11570. {
  11571. tempIndex = (SetProfileReq.ConnectorId -1);
  11572. }
  11573. for (int index = 0; index < AC_QUANTITY; index++)
  11574. {
  11575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11576. {
  11577. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11578. {
  11579. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11580. {
  11581. isMatchTransactiodId = TRUE;
  11582. break;
  11583. }
  11584. }
  11585. }
  11586. }
  11587. }
  11588. //check Transaction active
  11589. if(isMatchTransactiodId == FALSE)
  11590. {
  11591. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11592. goto end;
  11593. }
  11594. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11595. {
  11596. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11597. goto end;
  11598. }
  11599. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11600. fp = fopen(filename, "r");
  11601. if (!fp)
  11602. {
  11603. DEBUG_INFO("%s does not create.\n", filename);
  11604. fp = fopen(filename, "w+");
  11605. }
  11606. else
  11607. {
  11608. //Check Charging Profile Count
  11609. while(fscanf(fp, "%s", dataLine) != EOF)
  11610. {
  11611. //DEBUG_INFO("word=%s\n",word);
  11612. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11613. {
  11614. profileQuantity += 1;
  11615. }
  11616. }
  11617. }
  11618. fclose(fp);
  11619. }
  11620. // Check ChargeProfileMaxStackLevel
  11621. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11622. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11623. {
  11624. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11625. goto end;
  11626. }
  11627. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11628. {
  11629. FILE *fp;
  11630. char dataLine[4096]={0};
  11631. char fnametemp[128]={0};
  11632. int tmpProfileQuantity;
  11633. //Check ChargePointMaxProfile.json exit
  11634. profileQuantity = 0;
  11635. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11636. {
  11637. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11638. //Check Charging Profile Count
  11639. tmpProfileQuantity = 0;
  11640. while(fscanf(fp, "%s", dataLine) != EOF)
  11641. {
  11642. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11643. {
  11644. profileQuantity += 1;
  11645. tmpProfileQuantity += 1;
  11646. }
  11647. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11648. }
  11649. fclose(fp);
  11650. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11651. }
  11652. //Check TxDefaultProfile_%d.json
  11653. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11654. {
  11655. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11656. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11657. if((access(fnametemp,F_OK))!=-1)
  11658. {
  11659. fp = fopen(fnametemp, "r");
  11660. //Check Charging Profile Count
  11661. tmpProfileQuantity = 0;
  11662. while(fscanf(fp, "%s", dataLine) != EOF)
  11663. {
  11664. //DEBUG_INFO("word=%s\n",word);
  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("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11674. }
  11675. }
  11676. //Check TxProfile_%d.json
  11677. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11678. {
  11679. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11680. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11681. if((access(fnametemp,F_OK))!=-1)
  11682. {
  11683. fp = fopen(fnametemp, "r");
  11684. //Check Charging Profile Count
  11685. tmpProfileQuantity = 0;
  11686. while(fscanf(fp, "%s", dataLine) != EOF)
  11687. {
  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. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11700. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11701. {
  11702. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11703. goto end;
  11704. }
  11705. }
  11706. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11707. //**********************************Write to File********************************************************/
  11708. {
  11709. FILE *infile;
  11710. FILE *outfile;
  11711. char dataLine[4096]={0};
  11712. char filename[128]={0};
  11713. int chkChar=0;
  11714. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11715. {
  11716. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11717. {
  11718. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11719. }
  11720. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11721. {
  11722. if(SetProfileReq.ConnectorId==0)
  11723. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11724. else
  11725. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11726. }
  11727. else
  11728. {
  11729. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11730. }
  11731. infile = fopen (filename, "r");
  11732. outfile = fopen (tempfile, "w");
  11733. chkChar = fgetc(infile);
  11734. rewind(infile);
  11735. if(chkChar == EOF)
  11736. {
  11737. // Profile is empty
  11738. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11739. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11740. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11741. fclose(infile);
  11742. fclose(outfile);
  11743. sprintf(rmFileCmd,"rm -f %s",filename);
  11744. system(rmFileCmd);
  11745. rename(tempfile, filename);
  11746. }
  11747. else
  11748. {
  11749. // Profile is not empty
  11750. int ChargingProfileAdded = FALSE;
  11751. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11752. {
  11753. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11754. json_object *tmpChargingProfile;
  11755. tmpChargingProfile = json_tokener_parse(dataLine);
  11756. if(!is_error(SetChargingProfile))
  11757. {
  11758. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11759. {
  11760. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11761. {
  11762. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11763. }
  11764. }
  11765. }
  11766. json_object_put(tmpChargingProfile);
  11767. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11768. {
  11769. if(ChargingProfileAdded == FALSE)
  11770. {
  11771. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11772. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11773. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11774. ChargingProfileAdded = TRUE;
  11775. }
  11776. }
  11777. else
  11778. {
  11779. fprintf(outfile,"%s\n",dataLine);
  11780. if(ChargingProfileAdded == FALSE)
  11781. {
  11782. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11783. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11784. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11785. ChargingProfileAdded = TRUE;
  11786. }
  11787. }
  11788. } // end of while loop
  11789. fclose(infile);
  11790. fclose(outfile);
  11791. sprintf(rmFileCmd,"rm -f %s",filename);
  11792. system(rmFileCmd);
  11793. rename(tempfile, filename);
  11794. }
  11795. }
  11796. sleep(1);
  11797. result = TRUE;
  11798. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11799. }
  11800. end:
  11801. json_object_put(SetChargingProfile);
  11802. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11803. {
  11804. if(SetProfileReq.ConnectorId == 0)
  11805. {
  11806. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11807. {
  11808. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11809. }
  11810. }
  11811. else
  11812. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11813. }
  11814. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11815. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11816. return result;
  11817. }
  11818. int handleTriggerMessageRequest(char *uuid, char *payload)
  11819. {
  11820. mtrace();
  11821. int result = FAIL;
  11822. int connectorIdIsNULL = FALSE;
  11823. int connectorIdInt =0;
  11824. char sstr[40]={0},sstrtemp[100]={ 0 };
  11825. char requestedMessagestr[40]={0};
  11826. char comfirmstr[20]={0};
  11827. int c = 0;
  11828. char *loc;
  11829. DEBUG_INFO("handleTriggerMessageRequest\n");
  11830. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11831. strcpy(sstrtemp, stringtrimspace(payload));
  11832. c = 0;
  11833. loc = strstr(sstrtemp, "requestedMessage");
  11834. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11835. {
  11836. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11837. c++;
  11838. }
  11839. sstr[c] = '\0';
  11840. strcpy(requestedMessagestr, sstr);
  11841. c = 0;
  11842. loc = strstr(sstrtemp, "connectorId");
  11843. if(loc == NULL)
  11844. {
  11845. connectorIdIsNULL = TRUE;
  11846. }
  11847. else
  11848. {
  11849. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11850. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11851. {
  11852. sstr[c] = loc[strlen("connectorId")+2+c];
  11853. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11854. c++;
  11855. }
  11856. sstr[c] = '\0';
  11857. connectorIdInt = atoi(sstr);
  11858. }
  11859. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11860. {
  11861. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11862. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11863. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11864. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11865. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11866. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11867. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11868. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11869. {
  11870. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11871. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11872. return TRUE;
  11873. }
  11874. else
  11875. {
  11876. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11877. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11878. }
  11879. }
  11880. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11881. {
  11882. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11883. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11884. return TRUE;
  11885. }
  11886. //==========================
  11887. // Trigger message
  11888. //==========================
  11889. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11890. {
  11891. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11892. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11893. {
  11894. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11895. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11896. }
  11897. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11898. }
  11899. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11900. {
  11901. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11902. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11903. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11904. }
  11905. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11906. {
  11907. //sendBootNotificationRequest();
  11908. server_sign = FALSE;
  11909. }
  11910. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11911. {
  11912. refreshStartTimer(&clientTime.Heartbeat);
  11913. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  11914. }
  11915. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11916. {
  11917. if(connectorIdIsNULL == FALSE)
  11918. {
  11919. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11920. {
  11921. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11922. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11923. }
  11924. }
  11925. else
  11926. {
  11927. for(int idx=0;idx< gunTotalNumber;idx++)
  11928. {
  11929. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11930. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11931. }
  11932. }
  11933. }
  11934. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11935. {
  11936. if(connectorIdIsNULL == FALSE)
  11937. {
  11938. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11939. {
  11940. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11941. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11942. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11943. }
  11944. }
  11945. else
  11946. {
  11947. for(int idx=0;idx< gunTotalNumber;idx++)
  11948. {
  11949. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11950. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11951. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11952. }
  11953. }
  11954. }
  11955. return result;
  11956. }
  11957. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11958. {
  11959. mtrace();
  11960. int result = FAIL;
  11961. int connectorIdInt =0;
  11962. char comfirmstr[20]={0};
  11963. int tempIndex = 0;
  11964. json_object *UnlockConnector;
  11965. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11966. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11967. UnlockConnector = json_tokener_parse(payload);
  11968. if(!is_error(UnlockConnector))
  11969. {
  11970. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11971. {
  11972. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11973. }
  11974. }
  11975. json_object_put(UnlockConnector);
  11976. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11977. if(gunTotalNumber == 0)
  11978. {
  11979. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11980. goto end;
  11981. }
  11982. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11983. {
  11984. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11985. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11986. goto end;
  11987. }
  11988. else
  11989. {
  11990. //check Transaction active
  11991. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11992. {
  11993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11994. {
  11995. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11996. }
  11997. else
  11998. {
  11999. tempIndex = connectorIdInt -1;
  12000. }
  12001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12002. {
  12003. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12004. {
  12005. //stop Transaction
  12006. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12007. }
  12008. }
  12009. }
  12010. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12011. {
  12012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12013. {
  12014. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12015. }
  12016. else
  12017. {
  12018. tempIndex = connectorIdInt -1;
  12019. }
  12020. for (int index = 0; index < CCS_QUANTITY; index++)
  12021. {
  12022. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12023. {
  12024. //stop Transaction
  12025. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12026. }
  12027. }
  12028. }
  12029. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12030. {
  12031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12032. {
  12033. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12034. }
  12035. else
  12036. {
  12037. tempIndex = connectorIdInt -1;
  12038. }
  12039. for (int index = 0; index < GB_QUANTITY; index++)
  12040. {
  12041. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12042. {
  12043. //stop Transaction
  12044. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12045. }
  12046. }
  12047. }
  12048. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12049. {
  12050. tempIndex = connectorIdInt -1;
  12051. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12052. {
  12053. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12054. {
  12055. //stop Transaction
  12056. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12057. }
  12058. }
  12059. }
  12060. else
  12061. {
  12062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12063. {
  12064. tempIndex = 2;
  12065. }
  12066. else
  12067. {
  12068. tempIndex = connectorIdInt-1;
  12069. }
  12070. for (int index = 0; index < AC_QUANTITY; index++)
  12071. {
  12072. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12073. {
  12074. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12075. }
  12076. }
  12077. }
  12078. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12079. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12080. result = TRUE;
  12081. return result;
  12082. }
  12083. end:
  12084. //json_object_put(obj); --- remove temporally
  12085. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12086. return result;
  12087. }
  12088. static char UpdateFirmwarepayloadData[300]={0};
  12089. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12090. {
  12091. mtrace();
  12092. int result = FAIL;
  12093. pthread_t t;
  12094. sendUpdateFirmwareConfirmation(uuid);
  12095. memset(UpdateFirmwarepayloadData, 0, 300);
  12096. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12097. if(!interLock.isUpdateFirmwareGoing)
  12098. {
  12099. interLock.isUpdateFirmwareGoing = 1;
  12100. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12101. sleep(1);
  12102. }
  12103. else
  12104. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12105. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12106. return result;
  12107. }
  12108. void *UpdateFirmwareProcess(void *data)
  12109. {
  12110. pthread_detach(pthread_self());
  12111. mtrace();
  12112. int retriesInt =0, retryIntervalInt=0;
  12113. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12114. int port=0;
  12115. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12116. int isSuccess = 0;
  12117. char ftpbuf[512];
  12118. char temp[100];
  12119. char * pch;
  12120. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12121. json_object *UpdateFirmware;
  12122. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12123. if(!is_error(UpdateFirmware))
  12124. {
  12125. // Required data
  12126. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12127. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12128. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12129. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12130. // Optional data
  12131. if(json_object_object_get(UpdateFirmware, "retries"))
  12132. {
  12133. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12134. }
  12135. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12136. {
  12137. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12138. }
  12139. }
  12140. json_object_put(UpdateFirmware);
  12141. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12142. memset(path, 0, ARRAY_SIZE(path));
  12143. // Wait retrieveData
  12144. if(strlen(retrieveDatestr) > 10)
  12145. {
  12146. do
  12147. {
  12148. sleep(1);
  12149. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12150. }
  12151. // Ready to download
  12152. system("rm -f /mnt/*");
  12153. if(strncmp(locationstr,"http", 4) == 0)
  12154. {
  12155. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12156. sprintf(ftppath,"/%s", path);
  12157. DEBUG_INFO("locationstr: %s\n", locationstr);
  12158. DEBUG_INFO("protocol: %s\n",protocol);
  12159. DEBUG_INFO("host: %s\n",host);
  12160. DEBUG_INFO("path: %s\n",path);
  12161. DEBUG_INFO("ftppath: %s\n",ftppath);
  12162. int ftppathlen=strlen(ftppath);
  12163. int i=1;
  12164. char filenametemp[50];
  12165. while(i < ftppathlen)
  12166. {
  12167. int len=ftppathlen-i;
  12168. if(ftppath[len]== 47) // '/' ascll code: 47
  12169. {
  12170. DEBUG_INFO("compare '/' all right\n");
  12171. break;
  12172. }
  12173. i=i+1;
  12174. }
  12175. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12176. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12177. filenametemp[i+1] = 0;
  12178. do
  12179. {
  12180. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12181. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12182. sleep(1);
  12183. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12184. if(!isSuccess)
  12185. {
  12186. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12187. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12188. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12189. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12190. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12191. }
  12192. else
  12193. {
  12194. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12195. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12196. }
  12197. retriesInt--;
  12198. }while((isSuccess == 0)&&(retriesInt >= 0));
  12199. }
  12200. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12201. {
  12202. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12203. memset(temp, 0, ARRAY_SIZE(temp));
  12204. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12205. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12206. int ftppathlen=strlen(ftpbuf);
  12207. int i=1;
  12208. char filenametemp[50];
  12209. while(i < ftppathlen)
  12210. {
  12211. int len=ftppathlen-i;
  12212. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12213. {
  12214. DEBUG_INFO(" compare '/' all right\n");
  12215. break;
  12216. }
  12217. i=i+1;
  12218. }
  12219. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12220. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12221. filenametemp[i+1] = 0;
  12222. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12223. pch=strchr(temp,'@');
  12224. if(pch==NULL)
  12225. {
  12226. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12227. protocol, host, &port, path);
  12228. strcpy(user,"anonymous");
  12229. strcpy(password,"");
  12230. }
  12231. else
  12232. {
  12233. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12234. protocol, user, password, host, &port, path);
  12235. }
  12236. sscanf(host,"%[^/]%s",host1, path1);
  12237. sprintf(ftppath,"%s", path1);
  12238. //DEBUG_INFO("protocol =%s\n",protocol);
  12239. //DEBUG_INFO("user =%s\n",user);
  12240. //DEBUG_INFO("password =%s\n",password);
  12241. //DEBUG_INFO("host1 =%s\n",host1);
  12242. //DEBUG_INFO("port =%d\n",port);
  12243. //DEBUG_INFO("path1 =%s\n",path1);
  12244. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12245. //ftpFile(host, user, password, port, ftppath, fname);
  12246. //download firmware pthred
  12247. if(port == 0)
  12248. {
  12249. port = 21;
  12250. }
  12251. do
  12252. {
  12253. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12254. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12255. sleep(1);
  12256. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12257. if(!isSuccess)
  12258. {
  12259. //BulldogUtil.sleepMs(interval*1000);
  12260. DEBUG_INFO("Update firmware request and download file fail.\n");
  12261. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12262. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12263. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12264. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12265. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12266. }
  12267. else
  12268. {
  12269. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12270. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12271. }
  12272. retriesInt--;
  12273. }while((!isSuccess)&&(retriesInt >= 0));
  12274. }
  12275. else
  12276. {
  12277. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12278. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12279. sleep(1);
  12280. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12281. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12282. }
  12283. // OCPPPH only, must announce CSU upgrade firmware
  12284. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  12285. interLock.isUpdateFirmwareGoing = 0;
  12286. pthread_exit(NULL);
  12287. }
  12288. int handleCertificateSignedRequest(char *uuid, char *payload)
  12289. {
  12290. mtrace();
  12291. int result = PASS;
  12292. json_object *CertificateSigned;
  12293. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12294. CertificateSigned = json_tokener_parse(payload);
  12295. if(!is_error(CertificateSigned))
  12296. {
  12297. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12298. }
  12299. json_object_put(CertificateSigned);
  12300. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12301. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12302. fclose(fp);
  12303. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12304. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12305. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12306. sendCertificateSignedConfirmation(uuid);
  12307. return result;
  12308. }
  12309. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12310. {
  12311. mtrace();
  12312. int result = PASS;
  12313. json_object *DeleteCertificate;
  12314. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12315. DeleteCertificate = json_tokener_parse(payload);
  12316. if(!is_error(DeleteCertificate))
  12317. {
  12318. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12319. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12320. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12321. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12322. }
  12323. json_object_put(DeleteCertificate);
  12324. /*
  12325. * TODO: Delete certificateSigned process
  12326. */
  12327. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12328. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12329. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12330. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12331. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12332. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12333. sendDeleteCertificateConfirmation(uuid);
  12334. return result;
  12335. }
  12336. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12337. {
  12338. mtrace();
  12339. int result = PASS;
  12340. json_object *ExtendedTriggerMessage;
  12341. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12342. ExtendedTriggerMessage = json_tokener_parse(payload);
  12343. if(!is_error(ExtendedTriggerMessage))
  12344. {
  12345. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12346. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12347. {
  12348. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12349. }
  12350. else
  12351. {
  12352. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12353. }
  12354. }
  12355. json_object_put(ExtendedTriggerMessage);
  12356. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12357. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12358. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12359. {
  12360. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12361. }
  12362. else
  12363. {
  12364. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12365. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12366. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12367. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12368. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12369. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12370. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12371. {
  12372. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12373. }
  12374. else
  12375. {
  12376. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12377. }
  12378. }
  12379. sendExtendedTriggerMessageConfirmation(uuid);
  12380. //==========================
  12381. // Trigger message
  12382. //==========================
  12383. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12384. {
  12385. //sendBootNotificationRequest();
  12386. server_sign = FALSE;
  12387. }
  12388. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12389. {
  12390. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12391. }
  12392. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12393. {
  12394. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12395. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12396. {
  12397. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12398. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12399. }
  12400. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12401. }
  12402. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12403. {
  12404. refreshStartTimer(&clientTime.Heartbeat);
  12405. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12406. }
  12407. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12408. {
  12409. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12410. {
  12411. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12412. }
  12413. else
  12414. {
  12415. for(int idx=0;idx< gunTotalNumber;idx++)
  12416. {
  12417. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12418. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12419. }
  12420. }
  12421. }
  12422. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12423. {
  12424. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12425. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12426. {
  12427. 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\" &");
  12428. }
  12429. }
  12430. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12431. {
  12432. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12433. {
  12434. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12435. }
  12436. else
  12437. {
  12438. for(int idx=0;idx< gunTotalNumber;idx++)
  12439. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12440. }
  12441. }
  12442. return result;
  12443. }
  12444. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12445. {
  12446. mtrace();
  12447. int result = PASS;
  12448. json_object *GetInstalledCertificateIds;
  12449. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12450. GetInstalledCertificateIds = json_tokener_parse(payload);
  12451. if(!is_error(GetInstalledCertificateIds))
  12452. {
  12453. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12454. }
  12455. json_object_put(GetInstalledCertificateIds);
  12456. /*
  12457. * TODO: Return installed certificate process
  12458. */
  12459. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12460. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12461. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12462. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12463. sendGetInstalledCertificateIdsConfirmation(uuid);
  12464. return result;
  12465. }
  12466. int handleGetLogRequest(char *uuid, char *payload)
  12467. {
  12468. mtrace();
  12469. int result = PASS;
  12470. json_object *GetLog;
  12471. DEBUG_INFO("handleGetLogRequest...\n");
  12472. GetLog = json_tokener_parse(payload);
  12473. if(!is_error(GetLog))
  12474. {
  12475. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12476. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12477. if(json_object_object_get(GetLog, "retries") != NULL)
  12478. {
  12479. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12480. }
  12481. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12482. {
  12483. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12484. }
  12485. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12486. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12487. {
  12488. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12489. }
  12490. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12491. {
  12492. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12493. }
  12494. }
  12495. json_object_put(GetLog);
  12496. /*
  12497. * TODO: Upload log process
  12498. */
  12499. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12500. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12501. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12502. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12503. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12504. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12505. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12506. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12507. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12508. sendGetLogConfirmation(uuid);
  12509. return result;
  12510. }
  12511. int handleInstallCertificateRequest(char *uuid, char *payload)
  12512. {
  12513. mtrace();
  12514. int result = PASS;
  12515. json_object *InstallCertificate;
  12516. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12517. InstallCertificate = json_tokener_parse(payload);
  12518. if(!is_error(InstallCertificate))
  12519. {
  12520. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12521. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12522. /*
  12523. * TODO: Install certificate process
  12524. */
  12525. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12526. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12527. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12528. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12529. sendInstallCertificateConfirmation(uuid);
  12530. }
  12531. json_object_put(InstallCertificate);
  12532. return result;
  12533. }
  12534. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12535. {
  12536. mtrace();
  12537. int result = PASS;
  12538. json_object *SignedUpdateFirmware;
  12539. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12540. SignedUpdateFirmware = json_tokener_parse(payload);
  12541. if(!is_error(SignedUpdateFirmware))
  12542. {
  12543. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12544. {
  12545. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12546. }
  12547. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12548. {
  12549. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12550. }
  12551. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12552. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12553. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12554. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12555. {
  12556. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12557. }
  12558. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12559. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12560. }
  12561. json_object_put(SignedUpdateFirmware);
  12562. /*
  12563. * TODO: Upgrade firmware process
  12564. */
  12565. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12566. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12567. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12568. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12569. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12570. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12571. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12572. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12573. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12574. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12575. sendInstallCertificateConfirmation(uuid);
  12576. return result;
  12577. }
  12578. int handleUnknownRequest(char *uuid, char *payload)
  12579. {
  12580. mtrace();
  12581. int result = PASS;
  12582. DEBUG_INFO("handleUnknownRequest...\n");
  12583. sendUnknownConfirmation(uuid);
  12584. result = PASS;
  12585. return result;
  12586. }
  12587. //==========================================
  12588. // Handle server response routine
  12589. //==========================================
  12590. void handleAuthorizeResponse(char *payload, int gun_index)
  12591. {
  12592. mtrace();
  12593. char expiryDatestr[30]={0};
  12594. char parentIdTagstr[20]={0};
  12595. char statusstr[20]={0};
  12596. int expiryDateISNULL=FALSE;
  12597. int parentIdTagISNULL=FALSE;
  12598. DEBUG_INFO("handleAuthorizeResponse...\n");
  12599. json_object *Authorize;
  12600. Authorize = json_tokener_parse(payload);
  12601. if(!is_error(Authorize))
  12602. {
  12603. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12604. {
  12605. // Required data
  12606. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12607. // Optional data
  12608. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12609. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12610. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12611. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12612. }
  12613. }
  12614. json_object_put(Authorize);
  12615. if(expiryDateISNULL == FALSE)
  12616. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12617. if(parentIdTagISNULL == FALSE)
  12618. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12619. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12620. //Update idTag information to authorization cache if supproted
  12621. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12622. {
  12623. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12624. }
  12625. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12626. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12627. authorizeRetryTimes = 0;
  12628. }
  12629. void handleBootNotificationResponse(char *payload, int gun_index)
  12630. {
  12631. mtrace();
  12632. char statusStr[12]={0};
  12633. char currentTimeStr[30]={0};
  12634. int intervalInt = 0;
  12635. DEBUG_INFO("handleBootNotificationResponse...\n");
  12636. json_object *BootNotification;
  12637. BootNotification = json_tokener_parse(payload);
  12638. if(!is_error(BootNotification))
  12639. {
  12640. // Required data
  12641. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12642. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12643. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12644. }
  12645. json_object_put(BootNotification);
  12646. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12647. BootNotificationInterval = intervalInt;
  12648. HeartBeatWaitTime = intervalInt;
  12649. //write back to ShmOCPP16DataPH->BootNotification
  12650. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12651. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12652. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12653. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12654. {
  12655. server_sign = TRUE;
  12656. server_pending =FALSE;
  12657. }
  12658. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12659. {
  12660. server_pending = TRUE;
  12661. }
  12662. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12663. srand(time(NULL));
  12664. refreshStartTimer(&clientTime.Heartbeat);
  12665. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12666. SetOcppConnStatus(TRUE);
  12667. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12668. }
  12669. void handleDataTransferResponse(char *payload, int gun_index)
  12670. {
  12671. char sstr[160]={0};//sstr[200]={ 0 };
  12672. int c = 0;
  12673. char *loc;
  12674. DEBUG_INFO("handleDataTransferResponse ...\n");
  12675. loc = strstr(payload, "status");
  12676. c = 0;
  12677. while (loc[3+strlen("status")+c] != '\"')
  12678. {
  12679. sstr[c] = loc[3+strlen("status")+c];
  12680. c++;
  12681. }
  12682. sstr[c] = '\0';
  12683. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12684. }
  12685. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12686. {
  12687. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12688. //struct json_object *obj;
  12689. // obj = json_tokener_parse(payload);
  12690. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12691. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12692. //No fields are defined.
  12693. }
  12694. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12695. {
  12696. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12697. //struct json_object *obj;
  12698. // obj = json_tokener_parse(payload);
  12699. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12700. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12701. //No fields are defined.
  12702. }
  12703. void handleHeartbeatResponse(char *payload, int gun_index)
  12704. {
  12705. mtrace();
  12706. DEBUG_INFO("handleHeartbeatResponse...\n");
  12707. json_object *Heartbeat;
  12708. Heartbeat = json_tokener_parse(payload);
  12709. if(!is_error(Heartbeat))
  12710. {
  12711. // Required data
  12712. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12713. }
  12714. json_object_put(Heartbeat);
  12715. if(FirstHeartBeat == 0)
  12716. {
  12717. FirstHeartBeat = 1;
  12718. DEBUG_INFO("FirstHeartBeat \n");
  12719. }
  12720. HeartBeatWithNOResponse = 0;
  12721. refreshStartTimer(&clientTime.Heartbeat);
  12722. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12723. }
  12724. void handleMeterValuesResponse(char *payload, int gun_index)
  12725. {
  12726. mtrace();
  12727. DEBUG_INFO("handleMeterValuesResponse...\n");
  12728. isQueueSendable = 1;
  12729. }
  12730. void handleStartTransactionResponse(char *payload, int gun_index)
  12731. {
  12732. mtrace();
  12733. //int transactionIdInt = 0;
  12734. FILE *outfile;
  12735. char data[100]={0};
  12736. DEBUG_INFO("handleStartTransactionResponse...\n");
  12737. json_object *StartTransaction;
  12738. StartTransaction = json_tokener_parse(payload);
  12739. if(!is_error(StartTransaction))
  12740. {
  12741. // Required data
  12742. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12743. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12744. // Optional data
  12745. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12746. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12747. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12748. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12749. }
  12750. json_object_put(StartTransaction);
  12751. isQueueSendable = 1;
  12752. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12753. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12754. //-----------Start : write to the Queue TransactionId file -----------------//
  12755. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12756. {}
  12757. else
  12758. {
  12759. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12760. if(log == NULL)
  12761. {
  12762. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12763. return ;
  12764. }
  12765. else
  12766. {
  12767. fclose(log);
  12768. }
  12769. }
  12770. // open file for writing
  12771. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12772. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12773. {
  12774. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12775. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12776. fputs(data, outfile);
  12777. fclose (outfile);
  12778. }
  12779. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12780. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12781. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12782. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12783. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12784. }
  12785. void handleStatusNotificationResponse(char *payload, int gun_index)
  12786. {
  12787. mtrace();
  12788. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12789. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12790. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12791. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12792. }
  12793. void handleStopTransactionnResponse(char *payload, int gun_index)
  12794. {
  12795. mtrace();
  12796. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12797. json_object *StopTransaction;
  12798. StopTransaction = json_tokener_parse(payload);
  12799. if(!is_error(StopTransaction))
  12800. {
  12801. // Optional data
  12802. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12803. {
  12804. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12805. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12806. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12807. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12808. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12809. }
  12810. }
  12811. json_object_put(StopTransaction);
  12812. isQueueSendable = 1;
  12813. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12814. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12815. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12816. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12817. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12818. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  12819. }
  12820. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12821. {
  12822. mtrace();
  12823. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12824. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12825. }
  12826. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12827. {
  12828. mtrace();
  12829. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12830. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12831. }
  12832. void handleSignCertificateResponse(char *payload, int gun_index)
  12833. {
  12834. mtrace();
  12835. DEBUG_INFO("handleSignCertificateResponse...\n");
  12836. json_object *SignCertificate;
  12837. SignCertificate = json_tokener_parse(payload);
  12838. if(!is_error(SignCertificate))
  12839. {
  12840. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12841. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12842. }
  12843. json_object_put(SignCertificate);
  12844. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12845. }
  12846. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12847. {
  12848. mtrace();
  12849. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12850. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12851. }
  12852. //==========================================
  12853. // Handle Error routine
  12854. //==========================================
  12855. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12856. {
  12857. mtrace();
  12858. #ifdef SystemLogMessage
  12859. DEBUG_INFO("errorCode: %s\n", errorCode);
  12860. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12861. DEBUG_INFO("errorDetails: %s\n", payload);
  12862. #endif
  12863. }
  12864. //===============================================
  12865. // Common routine
  12866. //===============================================
  12867. int initialConfigurationTable(void)
  12868. {
  12869. //clock_t start_t, end_t, total_t;
  12870. FILE *fp;
  12871. FILE *outfile;
  12872. char str[512]={0};
  12873. char sstr[256]={0};
  12874. int c = 0;
  12875. char *loc;
  12876. int confVersion = 10;
  12877. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12878. //start_t = clock();
  12879. //printf("Starting of the program, start_t = %ld\n", start_t);
  12880. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12881. // Check configuration file size is correct
  12882. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12883. {
  12884. struct stat st;
  12885. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12886. if(st.st_size < 3100)
  12887. {
  12888. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12889. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12890. }
  12891. }
  12892. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12893. {
  12894. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12895. if(outfile == NULL)
  12896. {
  12897. DEBUG_INFO("Error opening file\n");
  12898. return FALSE;
  12899. }
  12900. /*Core Profile*/
  12901. //AllowOfflineTxForUnknownId
  12902. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12906. //AuthorizationCacheEnabled
  12907. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12911. //AuthorizeRemoteTxRequests
  12912. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12916. //BlinkRepeat
  12917. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12921. //ClockAlignedDataInterval
  12922. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12926. //ConnectionTimeOut
  12927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12931. //GetConfigurationMaxKeys
  12932. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12934. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12936. // HeartbeatInterval
  12937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12941. // LightIntensity
  12942. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12946. // LocalAuthorizeOffline
  12947. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12948. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12951. // LocalPreAuthorize
  12952. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12956. // MaxEnergyOnInvalidId
  12957. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12961. // MeterValuesAlignedData
  12962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12965. 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" );
  12966. else
  12967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12969. // MeterValuesAlignedDataMaxLength
  12970. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12972. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12974. else
  12975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12977. // MeterValuesSampledData
  12978. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12981. 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" );
  12982. else
  12983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12985. // MeterValuesSampledDataMaxLength
  12986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12988. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12990. else
  12991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12993. // MeterValueSampleInterval
  12994. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12998. // MinimumStatusDuration
  12999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13002. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13004. // NumberOfConnectors
  13005. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13008. {
  13009. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13010. }
  13011. else
  13012. {
  13013. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13014. }
  13015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13016. // ResetRetries
  13017. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13018. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13021. // ConnectorPhaseRotation
  13022. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13026. // ConnectorPhaseRotationMaxLength
  13027. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13031. // StopTransactionOnEVSideDisconnect
  13032. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13036. // StopTransactionOnInvalidId
  13037. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13041. // StopTxnAlignedData
  13042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13046. // StopTxnAlignedDataMaxLength
  13047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13051. // StopTxnSampledData
  13052. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13056. else
  13057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13059. // StopTxnSampledDataMaxLength
  13060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13063. {
  13064. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13065. }
  13066. else
  13067. {
  13068. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13069. }
  13070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13071. // SupportedFeatureProfiles
  13072. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13074. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13076. // SupportedFeatureProfilesMaxLength
  13077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13081. // TransactionMessageAttempts
  13082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13085. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13087. // TransactionMessageRetryInterval
  13088. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13091. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13093. // UnlockConnectorOnEVSideDisconnect
  13094. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13098. // WebSocketPingInterval
  13099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13103. // QueueOffLineMeterValues
  13104. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13108. // AuthorizationKey
  13109. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  13112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13113. // SecurityProfile
  13114. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  13117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13118. // DefaultPrice
  13119. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13123. // CustomDisplayCostAndPrice
  13124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13128. // CustomIdleFeeAfterStop
  13129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13133. // SystemUptimeSec
  13134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13138. // FreeVend
  13139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13143. // Configuration Version
  13144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13146. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13148. //* Local Auth List Management Profile*/
  13149. #if 0
  13150. //For OCTT Test Case
  13151. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13154. #endif
  13155. #if 1
  13156. //LocalAuthListEnabled
  13157. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13161. #endif
  13162. //LocalAuthListMaxLength
  13163. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13167. //SendLocalListMaxLength
  13168. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13172. //ReserveConnectorZeroSupported
  13173. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13177. //* Smart Charging Profile */
  13178. //ChargeProfileMaxStackLevel
  13179. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13183. // ChargingScheduleAllowedChargingRateUnit
  13184. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13188. // ChargingScheduleMaxPeriods
  13189. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13193. // ConnectorSwitch3to1PhaseSupported
  13194. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13198. // MaxChargingProfilesInstalled
  13199. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13203. fclose(outfile);
  13204. }
  13205. else
  13206. {
  13207. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13208. char keystr[60]={0};
  13209. char readonlystr[10]={0};
  13210. char valuestr[256]={0};
  13211. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13212. if(fp == NULL) {
  13213. DEBUG_INFO("Error opening file");
  13214. return FALSE;
  13215. }
  13216. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13217. {
  13218. //DEBUG_INFO("Get Configuration \n");
  13219. if(strlen(str) > 0)
  13220. {
  13221. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13222. //*************************key*********************************/
  13223. if(strstr(str, "key") != NULL)
  13224. {
  13225. loc = strstr(str, "key");
  13226. c = 0;
  13227. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13228. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13229. {
  13230. sstr[c] = loc[strlen("key")+3+c];
  13231. c++;
  13232. }
  13233. sstr[c] = '\0';
  13234. strcpy(keystr,sstr);
  13235. }
  13236. //*************************readonly*********************************/
  13237. if(strstr(str, "readonly") != NULL)
  13238. {
  13239. loc = strstr(str, "readonly");
  13240. c = 0;
  13241. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13242. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13243. {
  13244. sstr[c] = loc[strlen("readonly")+2+c];
  13245. c++;
  13246. }
  13247. sstr[c] = '\0';
  13248. strcpy(readonlystr,sstr);
  13249. }
  13250. //*************************value*********************************/
  13251. if(strstr(str, "value") != NULL)
  13252. {
  13253. loc = strstr(str, "value");
  13254. c = 0;
  13255. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13256. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13257. {
  13258. sstr[c] = loc[strlen("value")+3+c];
  13259. c++;
  13260. }
  13261. sstr[c] = '\0';
  13262. strcpy(valuestr,sstr);
  13263. }
  13264. // DEBUG_INFO("keystr=%s\n",keystr);
  13265. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13266. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13267. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13268. {
  13269. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13270. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13271. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13272. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13273. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13274. }
  13275. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13276. {
  13277. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13278. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13279. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13280. }
  13281. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13282. {
  13283. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13284. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13285. }
  13286. if(strcmp(keystr, "BlinkRepeat") == 0)
  13287. {
  13288. //Charger.BlinkRepeat = Integer.parseInt(value);
  13289. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13291. }
  13292. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13293. {
  13294. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13295. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13296. }
  13297. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13298. {
  13299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13300. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13301. }
  13302. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13303. {
  13304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13305. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13306. }
  13307. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13308. {
  13309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13310. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13311. HeartBeatWaitTime = atoi(valuestr);
  13312. }
  13313. if(strcmp(keystr, "LightIntensity") == 0)
  13314. {
  13315. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13316. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13317. }
  13318. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13319. {
  13320. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13321. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13322. }
  13323. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13324. {
  13325. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13326. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13327. }
  13328. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13329. {
  13330. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13331. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13332. }
  13333. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13334. {
  13335. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13336. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13337. }
  13338. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13339. {
  13340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13341. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13342. }
  13343. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13344. {
  13345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13347. }
  13348. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13349. {
  13350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13351. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13352. }
  13353. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13354. {
  13355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13356. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13357. }
  13358. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13359. {
  13360. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13362. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13363. }
  13364. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13365. {
  13366. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13367. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13368. }
  13369. if(strcmp(keystr, "ResetRetries") == 0)
  13370. {
  13371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13372. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13373. }
  13374. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13375. {
  13376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13377. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13378. }
  13379. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13380. {
  13381. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13383. }
  13384. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13385. {
  13386. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13388. }
  13389. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13390. {
  13391. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13393. }
  13394. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13395. {
  13396. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13397. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13398. }
  13399. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13400. {
  13401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13403. }
  13404. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13405. {
  13406. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13408. }
  13409. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13410. {
  13411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13413. }
  13414. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13415. {
  13416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13417. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13418. }
  13419. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13420. {
  13421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13422. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13423. }
  13424. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13425. {
  13426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13427. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13428. TransactionMessageAttemptsValue = atoi(valuestr);
  13429. }
  13430. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13431. {
  13432. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13433. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13434. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13435. }
  13436. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13437. {
  13438. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13439. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13440. }
  13441. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13442. {
  13443. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13444. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13445. }
  13446. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13447. {
  13448. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13450. }
  13451. if(strcmp(keystr, "AuthorizationKey") == 0)
  13452. {
  13453. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13454. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13455. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13456. }
  13457. if(strcmp(keystr, "SecurityProfile") == 0)
  13458. {
  13459. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13460. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  13462. }
  13463. if(strcmp(keystr, "DefaultPrice") == 0)
  13464. {
  13465. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13466. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13467. }
  13468. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13469. {
  13470. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13471. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13472. }
  13473. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13474. {
  13475. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13476. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13477. }
  13478. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13479. {
  13480. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13481. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13482. }
  13483. if(strcmp(keystr, "FreeVend") == 0)
  13484. {
  13485. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13486. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13487. }
  13488. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13489. {
  13490. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13491. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13492. }
  13493. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13494. {
  13495. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13496. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13497. }
  13498. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13499. {
  13500. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13501. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13502. }
  13503. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13504. {
  13505. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13506. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13507. }
  13508. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13509. {
  13510. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13511. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13512. }
  13513. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13514. {
  13515. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13516. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13517. }
  13518. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13519. {
  13520. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13521. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13522. }
  13523. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13524. {
  13525. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13527. }
  13528. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13529. {
  13530. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13532. }
  13533. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13534. {
  13535. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13537. }
  13538. }
  13539. }
  13540. fclose(fp);
  13541. }
  13542. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13543. {
  13544. return PASS;
  13545. }
  13546. else
  13547. {
  13548. return FAIL;
  13549. }
  13550. }
  13551. void StoreConfigurationTable(void)
  13552. {
  13553. FILE *outfile;
  13554. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13555. if(outfile == NULL)
  13556. {
  13557. DEBUG_INFO("Error opening file");
  13558. return ;
  13559. }
  13560. /*Core Profile*/
  13561. //AllowOfflineTxForUnknownId
  13562. /*
  13563. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13564. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13566. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13567. */
  13568. //DEBUG_INFO("data=%s\n",data);
  13569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13570. //AuthorizationCacheEnabled
  13571. /*
  13572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13575. */
  13576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13577. //AuthorizeRemoteTxRequests
  13578. /*
  13579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13582. */
  13583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13584. //BlinkRepeat
  13585. /*
  13586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13589. */
  13590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13591. //ClockAlignedDataInterval
  13592. /*
  13593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13594. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13596. */
  13597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13598. //ConnectionTimeOut
  13599. /*
  13600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13603. */
  13604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13605. //GetConfigurationMaxKeys
  13606. /*
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13610. */
  13611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13612. // HeartbeatInterval
  13613. /*
  13614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13616. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13617. */
  13618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13619. // LightIntensity
  13620. /*
  13621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13624. */
  13625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13626. // LocalAuthorizeOffline
  13627. /*
  13628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13631. */
  13632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13633. // LocalPreAuthorize
  13634. /*
  13635. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13638. */
  13639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13640. // MaxEnergyOnInvalidId
  13641. /*
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13645. */
  13646. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13648. // MeterValuesAlignedData
  13649. /*
  13650. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13652. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13653. */
  13654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13655. // MeterValuesAlignedDataMaxLength
  13656. /*
  13657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13660. */
  13661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13662. // MeterValuesSampledData
  13663. /*
  13664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13667. */
  13668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13669. // MeterValuesSampledDataMaxLength
  13670. /*
  13671. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13673. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13674. */
  13675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13676. // MeterValueSampleInterval
  13677. /*
  13678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13681. */
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13683. // MinimumStatusDuration
  13684. /*
  13685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13688. */
  13689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13690. // NumberOfConnectors
  13691. /*
  13692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13694. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13695. {
  13696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13697. }
  13698. else
  13699. {
  13700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13701. }
  13702. */
  13703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13704. // ResetRetries
  13705. /*
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13707. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13709. */
  13710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13711. // ConnectorPhaseRotation
  13712. /*
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13716. */
  13717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13718. // ConnectorPhaseRotationMaxLength
  13719. /*
  13720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13723. */
  13724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13725. // StopTransactionOnEVSideDisconnect
  13726. /*
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13730. */
  13731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13732. // StopTransactionOnInvalidId
  13733. /*
  13734. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13736. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13737. */
  13738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13739. // StopTxnAlignedData
  13740. /*
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13744. */
  13745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13746. // StopTxnAlignedDataMaxLength
  13747. /*
  13748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13749. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13751. */
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13753. // StopTxnSampledData
  13754. /*
  13755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13756. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13758. */
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13760. // StopTxnSampledDataMaxLength
  13761. /*
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13765. */
  13766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13767. // SupportedFeatureProfiles
  13768. /*
  13769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13772. */
  13773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13774. // SupportedFeatureProfilesMaxLength
  13775. /*
  13776. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13779. */
  13780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13781. // TransactionMessageAttempts
  13782. /*
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13786. */
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13788. // TransactionMessageRetryInterval
  13789. /*
  13790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13793. */
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13795. // UnlockConnectorOnEVSideDisconnect
  13796. /*
  13797. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13800. */
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13802. // WebSocketPingInterval
  13803. /*
  13804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13807. */
  13808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13809. // QueueOffLineMeterValues
  13810. /*
  13811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13814. */
  13815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13816. // AuthorizationKey
  13817. /*
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13821. */
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13823. // SecurityProfile
  13824. /*
  13825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13828. */
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13830. // DefaultPrice
  13831. /*
  13832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13835. */
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13837. // CustomDisplayCostAndPrice
  13838. /*
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13842. */
  13843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13844. // CustomIdleFeeAfterStop
  13845. /*
  13846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13849. */
  13850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13851. // SystemUptimeSec
  13852. /*
  13853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13856. */
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13858. // FreeVend
  13859. /*
  13860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13863. */
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13865. // ConfigurationVersion
  13866. /*
  13867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13870. */
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13872. //* Local Auth List Management Profile*/
  13873. //LocalAuthListEnabled
  13874. /*
  13875. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13878. */
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13880. //LocalAuthListMaxLength
  13881. /*
  13882. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13885. */
  13886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13887. //SendLocalListMaxLength
  13888. /*
  13889. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13892. */
  13893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13894. //ReserveConnectorZeroSupported
  13895. /*
  13896. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13899. */
  13900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13901. //* Smart Charging Profile */
  13902. //ChargeProfileMaxStackLevel
  13903. /*
  13904. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13907. */
  13908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13909. // ChargingScheduleAllowedChargingRateUnit
  13910. /*
  13911. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13914. */
  13915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13916. // ChargingScheduleMaxPeriods
  13917. /*
  13918. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13921. */
  13922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13923. // ConnectorSwitch3to1PhaseSupported
  13924. /*
  13925. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13928. */
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13930. // MaxChargingProfilesInstalled
  13931. /*
  13932. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13934. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13935. */
  13936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13937. fclose(outfile);
  13938. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13939. }
  13940. void getKeyValue(char *keyReq)
  13941. {
  13942. int isEmpty = FALSE;
  13943. int isKnowKey = FALSE;
  13944. DEBUG_INFO("keyReq = %s\n", keyReq);
  13945. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13946. isEmpty = TRUE;
  13947. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13948. {
  13949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13951. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13952. {
  13953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13954. }
  13955. else
  13956. {
  13957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13958. }
  13959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13960. isKnowKey = TRUE;
  13961. }
  13962. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13963. {
  13964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13966. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13967. {
  13968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13969. }
  13970. else
  13971. {
  13972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13973. }
  13974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13975. isKnowKey = TRUE;
  13976. }
  13977. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13978. {
  13979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13981. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13982. {
  13983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13984. }
  13985. else
  13986. {
  13987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13988. }
  13989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13990. isKnowKey = TRUE;
  13991. }
  13992. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13993. {
  13994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13996. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13997. {
  13998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13999. }
  14000. else
  14001. {
  14002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14003. }
  14004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14005. isKnowKey = TRUE;
  14006. }
  14007. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14008. {
  14009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14011. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14012. {
  14013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14014. }
  14015. else
  14016. {
  14017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14018. }
  14019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14020. isKnowKey = TRUE;
  14021. }
  14022. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14023. {
  14024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14026. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14027. {
  14028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14029. }
  14030. else
  14031. {
  14032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14033. }
  14034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14035. isKnowKey = TRUE;
  14036. }
  14037. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14038. {
  14039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14041. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14042. {
  14043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14044. }
  14045. else
  14046. {
  14047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14048. }
  14049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14050. isKnowKey = TRUE;
  14051. }
  14052. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14053. {
  14054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14056. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14057. {
  14058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14059. }
  14060. else
  14061. {
  14062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14063. }
  14064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14065. isKnowKey = TRUE;
  14066. }
  14067. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14068. {
  14069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14071. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14072. {
  14073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14074. }
  14075. else
  14076. {
  14077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14078. }
  14079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14080. isKnowKey = TRUE;
  14081. }
  14082. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14083. {
  14084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14086. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14087. {
  14088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14089. }
  14090. else
  14091. {
  14092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14093. }
  14094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14095. isKnowKey = TRUE;
  14096. }
  14097. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14098. {
  14099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14100. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14101. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14102. {
  14103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14104. }
  14105. else
  14106. {
  14107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14108. }
  14109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14110. isKnowKey = TRUE;
  14111. }
  14112. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14113. {
  14114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14116. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14117. {
  14118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14119. }
  14120. else
  14121. {
  14122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14123. }
  14124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14125. isKnowKey = TRUE;
  14126. }
  14127. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14128. {
  14129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14130. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14131. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14132. {
  14133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14134. }
  14135. else
  14136. {
  14137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14138. }
  14139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14140. isKnowKey = TRUE;
  14141. }
  14142. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14143. {
  14144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14145. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14146. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14147. {
  14148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14149. }
  14150. else
  14151. {
  14152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14153. }
  14154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14155. isKnowKey = TRUE;
  14156. }
  14157. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14158. {
  14159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14161. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14162. {
  14163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14164. }
  14165. else
  14166. {
  14167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14168. }
  14169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14170. isKnowKey = TRUE;
  14171. }
  14172. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14173. {
  14174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14176. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14177. {
  14178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14179. }
  14180. else
  14181. {
  14182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14183. }
  14184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14185. isKnowKey = TRUE;
  14186. }
  14187. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14188. {
  14189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14191. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14192. {
  14193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14194. }
  14195. else
  14196. {
  14197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14198. }
  14199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14200. isKnowKey = TRUE;
  14201. }
  14202. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14203. {
  14204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14206. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14207. {
  14208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14209. }
  14210. else
  14211. {
  14212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14213. }
  14214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14215. isKnowKey = TRUE;
  14216. }
  14217. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14218. {
  14219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14221. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14222. {
  14223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14224. }
  14225. else
  14226. {
  14227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14228. }
  14229. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14231. isKnowKey = TRUE;
  14232. }
  14233. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14234. {
  14235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14237. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14238. {
  14239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14240. }
  14241. else
  14242. {
  14243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14244. }
  14245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14246. isKnowKey = TRUE;
  14247. }
  14248. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14249. {
  14250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14252. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14253. {
  14254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14255. }
  14256. else
  14257. {
  14258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14259. }
  14260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14261. isKnowKey = TRUE;
  14262. }
  14263. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14264. {
  14265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14267. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14268. {
  14269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14270. }
  14271. else
  14272. {
  14273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14274. }
  14275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14276. isKnowKey = TRUE;
  14277. }
  14278. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14279. {
  14280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14282. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14283. {
  14284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14285. }
  14286. else
  14287. {
  14288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14289. }
  14290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14291. isKnowKey = TRUE;
  14292. }
  14293. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14294. {
  14295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14297. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14298. {
  14299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14300. }
  14301. else
  14302. {
  14303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14304. }
  14305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14306. isKnowKey = TRUE;
  14307. }
  14308. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14309. {
  14310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14312. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14313. {
  14314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14315. }
  14316. else
  14317. {
  14318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14319. }
  14320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14321. isKnowKey = TRUE;
  14322. }
  14323. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14324. {
  14325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14327. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14328. {
  14329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14330. }
  14331. else
  14332. {
  14333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14334. }
  14335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14336. isKnowKey = TRUE;
  14337. }
  14338. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14339. {
  14340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14342. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14343. {
  14344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14345. }
  14346. else
  14347. {
  14348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14349. }
  14350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14351. isKnowKey = TRUE;
  14352. }
  14353. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14354. {
  14355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14357. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14358. {
  14359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14360. }
  14361. else
  14362. {
  14363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14364. }
  14365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14366. isKnowKey = TRUE;
  14367. }
  14368. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14369. {
  14370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14372. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14373. {
  14374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14375. }
  14376. else
  14377. {
  14378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14379. }
  14380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14381. isKnowKey = TRUE;
  14382. }
  14383. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14384. {
  14385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14387. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14388. {
  14389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14390. }
  14391. else
  14392. {
  14393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14394. }
  14395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14396. isKnowKey = TRUE;
  14397. }
  14398. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14399. {
  14400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14402. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14403. {
  14404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14405. }
  14406. else
  14407. {
  14408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14409. }
  14410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14411. isKnowKey = TRUE;
  14412. }
  14413. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14414. {
  14415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14418. {
  14419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14420. }
  14421. else
  14422. {
  14423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14424. }
  14425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14426. isKnowKey = TRUE;
  14427. }
  14428. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14429. {
  14430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14432. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14433. {
  14434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14435. }
  14436. else
  14437. {
  14438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14439. }
  14440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14441. isKnowKey = TRUE;
  14442. }
  14443. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14444. {
  14445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14447. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14448. {
  14449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14450. }
  14451. else
  14452. {
  14453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14454. }
  14455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14456. isKnowKey = TRUE;
  14457. }
  14458. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14459. {
  14460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14462. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14463. {
  14464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14465. }
  14466. else
  14467. {
  14468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14469. }
  14470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14471. isKnowKey = TRUE;
  14472. }
  14473. /*
  14474. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14475. {
  14476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14479. {
  14480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14481. }
  14482. else
  14483. {
  14484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14485. }
  14486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14487. isKnowKey = TRUE;
  14488. }*/
  14489. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14490. {
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14494. {
  14495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14496. }
  14497. else
  14498. {
  14499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14500. }
  14501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14502. isKnowKey = TRUE;
  14503. }
  14504. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14505. {
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14508. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14509. {
  14510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14511. }
  14512. else
  14513. {
  14514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14515. }
  14516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14517. isKnowKey = TRUE;
  14518. }
  14519. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14520. {
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14523. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14524. {
  14525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14526. }
  14527. else
  14528. {
  14529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14530. }
  14531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14532. isKnowKey = TRUE;
  14533. }
  14534. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14535. {
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14538. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14539. {
  14540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14541. }
  14542. else
  14543. {
  14544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14545. }
  14546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14547. isKnowKey = TRUE;
  14548. }
  14549. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14550. {
  14551. struct sysinfo s_info;
  14552. int error = sysinfo(&s_info);
  14553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14555. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14556. {
  14557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14558. }
  14559. else
  14560. {
  14561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14562. }
  14563. if(error != 0)
  14564. {
  14565. DEBUG_WARN("System uptime get error: %d\n", error);
  14566. }
  14567. else
  14568. {
  14569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14570. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14571. }
  14572. isKnowKey = TRUE;
  14573. }
  14574. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14575. {
  14576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14578. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14579. {
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14581. }
  14582. else
  14583. {
  14584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14585. }
  14586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14587. isKnowKey = TRUE;
  14588. }
  14589. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14590. {
  14591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14593. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14594. {
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14596. }
  14597. else
  14598. {
  14599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14600. }
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14602. isKnowKey = TRUE;
  14603. }
  14604. #if 1
  14605. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14606. {
  14607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14609. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14610. {
  14611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14612. }
  14613. else
  14614. {
  14615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14616. }
  14617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14618. isKnowKey = TRUE;
  14619. }
  14620. #endif
  14621. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14622. {
  14623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14625. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14626. {
  14627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14628. }
  14629. else
  14630. {
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14632. }
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14634. isKnowKey = TRUE;
  14635. }
  14636. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14637. {
  14638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14640. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14641. {
  14642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14643. }
  14644. else
  14645. {
  14646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14647. }
  14648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14649. isKnowKey = TRUE;
  14650. }
  14651. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14652. {
  14653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14655. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14656. {
  14657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14658. }
  14659. else
  14660. {
  14661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14662. }
  14663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14664. isKnowKey = TRUE;
  14665. }
  14666. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14667. {
  14668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14670. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14671. {
  14672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14673. }
  14674. else
  14675. {
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14677. }
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14679. isKnowKey = TRUE;
  14680. }
  14681. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14682. {
  14683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14685. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14686. {
  14687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14688. }
  14689. else
  14690. {
  14691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14692. }
  14693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14694. isKnowKey = TRUE;
  14695. }
  14696. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14697. {
  14698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14700. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14701. {
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14703. }
  14704. else
  14705. {
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14707. }
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14709. isKnowKey = TRUE;
  14710. }
  14711. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14712. {
  14713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14715. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14716. {
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14718. }
  14719. else
  14720. {
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14722. }
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14724. isKnowKey = TRUE;
  14725. }
  14726. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14727. {
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14730. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14731. {
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14733. }
  14734. else
  14735. {
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14737. }
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14739. isKnowKey = TRUE;
  14740. }
  14741. //=========================================================
  14742. if(!isEmpty && !isKnowKey)
  14743. {
  14744. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14745. strcpy(unknownkey[UnknownKeynum], keyReq);
  14746. UnknownKeynum = UnknownKeynum + 1;
  14747. }
  14748. }
  14749. void processUnkownKey(void)
  14750. {
  14751. DEBUG_INFO("processUnkownKey...\n");
  14752. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14753. for(int index=0; index < UnknownKeynum; index++)
  14754. {
  14755. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14756. {
  14757. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14758. }
  14759. }
  14760. }
  14761. int setKeyValue(char *key, char *value)
  14762. {
  14763. int isSuccess = NotSupported;
  14764. int check_ascii=0;
  14765. char str[256]={0};
  14766. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14767. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14768. {
  14769. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14770. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14771. {
  14772. strcpy(str, (const char*)value);
  14773. for(int i = 0; str[i]; i++){
  14774. str[i] = tolower(str[i]);
  14775. }
  14776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14777. isSuccess = ConfigurationStatus_Accepted;
  14778. }
  14779. else
  14780. {
  14781. isSuccess = ConfigurationStatus_Rejected;
  14782. }
  14783. }
  14784. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14785. {
  14786. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14787. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14788. {
  14789. strcpy(str, (const char*)value);
  14790. for(int i = 0; str[i]; i++){
  14791. str[i] = tolower(str[i]);
  14792. }
  14793. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14794. isSuccess = ConfigurationStatus_Accepted;
  14795. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  14796. }
  14797. else
  14798. {
  14799. isSuccess = ConfigurationStatus_Rejected;
  14800. }
  14801. }
  14802. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14803. {
  14804. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14805. {
  14806. strcpy(str, (const char*)value);
  14807. for(int i = 0; str[i]; i++)
  14808. {
  14809. str[i] = tolower(str[i]);
  14810. }
  14811. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14812. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14813. isSuccess = ConfigurationStatus_Accepted;
  14814. }
  14815. else
  14816. {
  14817. isSuccess = ConfigurationStatus_Rejected;
  14818. }
  14819. }
  14820. if(strcmp(key, "BlinkRepeat") == 0)
  14821. {
  14822. //Charger.BlinkRepeat = Integer.parseInt(value);
  14823. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14824. {
  14825. check_ascii = value[0];
  14826. if( (check_ascii < 48) || (check_ascii > 57) )
  14827. {
  14828. isSuccess = ConfigurationStatus_Rejected;
  14829. }
  14830. else
  14831. {
  14832. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14833. isSuccess = ConfigurationStatus_Accepted;
  14834. }
  14835. }
  14836. else
  14837. {
  14838. isSuccess = ConfigurationStatus_Rejected;
  14839. }
  14840. }
  14841. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14842. {
  14843. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14844. {
  14845. check_ascii = value[0];
  14846. if( (check_ascii < 48) || (check_ascii > 57) )
  14847. {
  14848. isSuccess = ConfigurationStatus_Rejected;
  14849. }
  14850. else
  14851. {
  14852. if((atoi(value) == 0) || (atoi(value) >= 5))
  14853. {
  14854. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14855. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14856. isSuccess = ConfigurationStatus_Accepted;
  14857. }
  14858. else
  14859. isSuccess = ConfigurationStatus_Rejected;
  14860. }
  14861. }
  14862. else
  14863. {
  14864. isSuccess = ConfigurationStatus_Rejected;
  14865. }
  14866. }
  14867. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14868. {
  14869. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14870. {
  14871. check_ascii = value[0];
  14872. if( (check_ascii < 48) || (check_ascii > 57) )
  14873. {
  14874. isSuccess = ConfigurationStatus_Rejected;
  14875. }
  14876. else
  14877. {
  14878. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14879. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14880. isSuccess = ConfigurationStatus_Accepted;
  14881. }
  14882. }
  14883. else
  14884. {
  14885. isSuccess = ConfigurationStatus_Rejected;
  14886. }
  14887. }
  14888. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14889. {
  14890. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14891. {
  14892. check_ascii = value[0];
  14893. if( (check_ascii < 48) || (check_ascii > 57) )
  14894. {
  14895. isSuccess = ConfigurationStatus_Rejected;
  14896. }
  14897. else
  14898. {
  14899. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14900. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14901. isSuccess = ConfigurationStatus_Accepted;
  14902. }
  14903. }
  14904. else
  14905. {
  14906. isSuccess = ConfigurationStatus_Rejected;
  14907. }
  14908. }
  14909. if(strcmp(key, "HeartbeatInterval") == 0)
  14910. {
  14911. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14912. {
  14913. check_ascii = value[0];
  14914. if( (check_ascii < 48) || (check_ascii > 57) )
  14915. {
  14916. isSuccess = ConfigurationStatus_Rejected;
  14917. }
  14918. else
  14919. {
  14920. if((atoi(value) == 0) || (atoi(value) >= 10))
  14921. {
  14922. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14923. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14924. HeartBeatWaitTime = atoi(value);
  14925. isSuccess = ConfigurationStatus_Accepted;
  14926. }
  14927. else
  14928. {
  14929. isSuccess = ConfigurationStatus_Rejected;
  14930. }
  14931. }
  14932. }
  14933. else
  14934. {
  14935. isSuccess = ConfigurationStatus_Rejected;
  14936. }
  14937. }
  14938. if(strcmp(key, "LightIntensity") == 0)
  14939. {
  14940. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14941. {
  14942. check_ascii = value[0];
  14943. if( (check_ascii < 48) || (check_ascii > 57) )
  14944. {
  14945. isSuccess = ConfigurationStatus_Rejected;
  14946. }
  14947. else
  14948. {
  14949. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14950. isSuccess = ConfigurationStatus_Accepted;
  14951. }
  14952. }
  14953. else
  14954. {
  14955. isSuccess = ConfigurationStatus_Rejected;
  14956. }
  14957. }
  14958. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14959. {
  14960. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14961. {
  14962. strcpy(str, (const char*)value);
  14963. for(int i = 0; str[i]; i++)
  14964. {
  14965. str[i] = tolower(str[i]);
  14966. }
  14967. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14968. isSuccess = ConfigurationStatus_Accepted;
  14969. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14970. }
  14971. else
  14972. {
  14973. isSuccess = ConfigurationStatus_Rejected;
  14974. }
  14975. }
  14976. if(strcmp(key, "LocalPreAuthorize") == 0)
  14977. {
  14978. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14979. {
  14980. strcpy(str, (const char*)value);
  14981. for(int i = 0; str[i]; i++)
  14982. {
  14983. str[i] = tolower(str[i]);
  14984. }
  14985. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14986. isSuccess = ConfigurationStatus_Accepted;
  14987. }
  14988. else
  14989. {
  14990. isSuccess = ConfigurationStatus_Rejected;
  14991. }
  14992. }
  14993. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14994. {
  14995. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14996. {
  14997. check_ascii = value[0];
  14998. if( (check_ascii < 48) || (check_ascii > 57) )
  14999. {
  15000. isSuccess = ConfigurationStatus_Rejected;
  15001. }
  15002. else
  15003. {
  15004. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15005. isSuccess = ConfigurationStatus_Accepted;
  15006. }
  15007. }
  15008. else
  15009. {
  15010. isSuccess = ConfigurationStatus_Rejected;
  15011. }
  15012. }
  15013. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15014. {
  15015. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15016. {
  15017. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15018. isSuccess = ConfigurationStatus_Accepted;
  15019. }
  15020. else
  15021. {
  15022. isSuccess = ConfigurationStatus_Rejected;
  15023. }
  15024. }
  15025. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15026. {
  15027. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15028. {
  15029. check_ascii = value[0];
  15030. if( (check_ascii < 48) || (check_ascii > 57) )
  15031. {
  15032. isSuccess = ConfigurationStatus_Rejected;
  15033. }
  15034. else
  15035. {
  15036. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15037. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15038. isSuccess = ConfigurationStatus_Accepted;
  15039. }
  15040. }
  15041. else
  15042. {
  15043. isSuccess = ConfigurationStatus_Rejected;
  15044. }
  15045. }
  15046. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15047. {
  15048. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15049. {
  15050. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15051. isSuccess = ConfigurationStatus_Accepted;
  15052. }
  15053. else
  15054. {
  15055. isSuccess = ConfigurationStatus_Rejected;
  15056. }
  15057. }
  15058. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15059. {
  15060. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15061. {
  15062. check_ascii = value[0];
  15063. if( (check_ascii < 48) || (check_ascii > 57) )
  15064. {
  15065. isSuccess = ConfigurationStatus_Rejected;
  15066. }
  15067. else
  15068. {
  15069. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15070. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15071. isSuccess = ConfigurationStatus_Accepted;
  15072. }
  15073. }
  15074. else
  15075. {
  15076. isSuccess = ConfigurationStatus_Rejected;
  15077. }
  15078. }
  15079. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15080. {
  15081. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15082. {
  15083. check_ascii = value[0];
  15084. if( (check_ascii < 48) || (check_ascii > 57) )
  15085. {
  15086. isSuccess = ConfigurationStatus_Rejected;
  15087. }
  15088. else
  15089. {
  15090. if((atoi(value) == 0) || (atoi(value) >= 5))
  15091. {
  15092. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15093. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15094. isSuccess = ConfigurationStatus_Accepted;
  15095. }
  15096. else
  15097. {
  15098. isSuccess = ConfigurationStatus_Rejected;
  15099. }
  15100. }
  15101. }
  15102. else
  15103. {
  15104. isSuccess = ConfigurationStatus_Rejected;
  15105. }
  15106. }
  15107. if(strcmp(key, "MinimumStatusDuration") == 0)
  15108. {
  15109. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15110. {
  15111. check_ascii = value[0];
  15112. if( (check_ascii < 48) || (check_ascii > 57) )
  15113. {
  15114. isSuccess = ConfigurationStatus_Rejected;
  15115. }
  15116. else
  15117. {
  15118. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15119. {
  15120. isSuccess = ConfigurationStatus_Rejected;
  15121. }
  15122. else
  15123. {
  15124. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15125. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15126. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15127. isSuccess = ConfigurationStatus_Accepted;
  15128. }
  15129. }
  15130. }
  15131. else
  15132. {
  15133. isSuccess = ConfigurationStatus_Rejected;
  15134. }
  15135. }
  15136. if(strcmp(key, "NumberOfConnectors") == 0)
  15137. {
  15138. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15139. {
  15140. check_ascii = value[0];
  15141. if( (check_ascii < 48) || (check_ascii > 57) )
  15142. {
  15143. isSuccess = ConfigurationStatus_Rejected;
  15144. }
  15145. else
  15146. {
  15147. //Charger.ResetRetries = Integer.parseInt(value);
  15148. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15149. isSuccess = ConfigurationStatus_Accepted;
  15150. }
  15151. }
  15152. else
  15153. {
  15154. isSuccess = ConfigurationStatus_Rejected;
  15155. }
  15156. }
  15157. if(strcmp(key, "ResetRetries") == 0)
  15158. {
  15159. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15160. {
  15161. check_ascii = value[0];
  15162. if( (check_ascii < 48) || (check_ascii > 57) )
  15163. {
  15164. isSuccess = ConfigurationStatus_Rejected;
  15165. }
  15166. else
  15167. {
  15168. //Charger.ResetRetries = Integer.parseInt(value);
  15169. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15170. isSuccess = ConfigurationStatus_Accepted;
  15171. }
  15172. }
  15173. else
  15174. {
  15175. isSuccess = ConfigurationStatus_Rejected;
  15176. }
  15177. }
  15178. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15179. {
  15180. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15181. {
  15182. strcpy(str, (const char*)value);
  15183. for(int i = 0; str[i]; i++)
  15184. {
  15185. str[i] = tolower(str[i]);
  15186. }
  15187. if(strcmp(str, "notapplicable")== 0)
  15188. {
  15189. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15190. isSuccess = ConfigurationStatus_Accepted;
  15191. }
  15192. else if(strcmp(str, "unknown")== 0)
  15193. {
  15194. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15195. isSuccess = ConfigurationStatus_Accepted;
  15196. }
  15197. else if(strcmp(str, "rst")== 0)
  15198. {
  15199. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15200. isSuccess = ConfigurationStatus_Accepted;
  15201. }
  15202. else if(strcmp(str, "rts")== 0)
  15203. {
  15204. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15205. isSuccess = ConfigurationStatus_Accepted;
  15206. }
  15207. else if(strcmp(str, "srt")== 0)
  15208. {
  15209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15210. isSuccess = ConfigurationStatus_Accepted;
  15211. }
  15212. else if(strcmp(str, "str")== 0)
  15213. {
  15214. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15215. isSuccess = ConfigurationStatus_Accepted;
  15216. }
  15217. else if(strcmp(str, "trs")== 0)
  15218. {
  15219. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15220. isSuccess = ConfigurationStatus_Accepted;
  15221. }
  15222. else if(strcmp(str, "tsr")== 0)
  15223. {
  15224. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15225. isSuccess = ConfigurationStatus_Accepted;
  15226. }
  15227. else
  15228. {
  15229. isSuccess = ConfigurationStatus_Rejected;
  15230. }
  15231. }
  15232. else
  15233. {
  15234. isSuccess = ConfigurationStatus_Rejected;
  15235. }
  15236. }
  15237. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15238. {
  15239. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15240. {
  15241. check_ascii = value[0];
  15242. if( (check_ascii < 48) || (check_ascii > 57) )
  15243. {
  15244. isSuccess = ConfigurationStatus_Rejected;
  15245. }
  15246. else
  15247. {
  15248. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15249. isSuccess = ConfigurationStatus_Accepted;
  15250. }
  15251. }
  15252. else
  15253. {
  15254. isSuccess = ConfigurationStatus_Rejected;
  15255. }
  15256. }
  15257. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15258. {
  15259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15260. {
  15261. strcpy(str, (const char*)value);
  15262. for(int i = 0; str[i]; i++)
  15263. {
  15264. str[i] = tolower(str[i]);
  15265. }
  15266. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15268. isSuccess = ConfigurationStatus_Accepted;
  15269. }
  15270. else
  15271. {
  15272. isSuccess = ConfigurationStatus_Rejected;
  15273. }
  15274. }
  15275. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15276. {
  15277. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15278. {
  15279. strcpy(str, (const char*)value);
  15280. for(int i = 0; str[i]; i++)
  15281. {
  15282. str[i] = tolower(str[i]);
  15283. }
  15284. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15285. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15286. isSuccess = ConfigurationStatus_Accepted;
  15287. }
  15288. else
  15289. {
  15290. isSuccess = ConfigurationStatus_Rejected;
  15291. }
  15292. }
  15293. if(strcmp(key, "StopTxnAlignedData") == 0)
  15294. {
  15295. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15296. {
  15297. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15298. isSuccess = ConfigurationStatus_Accepted;
  15299. }
  15300. else
  15301. {
  15302. isSuccess = ConfigurationStatus_Rejected;
  15303. }
  15304. }
  15305. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15306. {
  15307. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15308. {
  15309. check_ascii = value[0];
  15310. if( (check_ascii < 48) || (check_ascii > 57) )
  15311. {
  15312. isSuccess = ConfigurationStatus_Rejected;
  15313. }
  15314. else
  15315. {
  15316. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15317. isSuccess = ConfigurationStatus_Accepted;
  15318. }
  15319. }
  15320. else
  15321. {
  15322. isSuccess = ConfigurationStatus_Rejected;
  15323. }
  15324. }
  15325. if(strcmp(key, "StopTxnSampledData") == 0)
  15326. {
  15327. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15328. {
  15329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15330. isSuccess = ConfigurationStatus_Accepted;
  15331. }
  15332. else
  15333. {
  15334. isSuccess = ConfigurationStatus_Rejected;
  15335. }
  15336. }
  15337. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15338. {
  15339. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15340. {
  15341. check_ascii = value[0];
  15342. if( (check_ascii < 48) || (check_ascii > 57) )
  15343. {
  15344. isSuccess = ConfigurationStatus_Rejected;
  15345. }
  15346. else
  15347. {
  15348. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15349. isSuccess = ConfigurationStatus_Accepted;
  15350. }
  15351. }
  15352. else
  15353. {
  15354. isSuccess = ConfigurationStatus_Rejected;
  15355. }
  15356. }
  15357. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15358. {
  15359. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15360. {
  15361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15362. isSuccess = ConfigurationStatus_Accepted;
  15363. }
  15364. else
  15365. {
  15366. isSuccess = ConfigurationStatus_Rejected;
  15367. }
  15368. }
  15369. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15370. {
  15371. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15372. {
  15373. check_ascii = value[0];
  15374. if( (check_ascii < 48) || (check_ascii > 57) )
  15375. {
  15376. isSuccess = ConfigurationStatus_Rejected;
  15377. }
  15378. else
  15379. {
  15380. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15381. isSuccess = ConfigurationStatus_Accepted;
  15382. }
  15383. }
  15384. else
  15385. {
  15386. isSuccess = ConfigurationStatus_Rejected;
  15387. }
  15388. }
  15389. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15390. {
  15391. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15392. {
  15393. check_ascii = value[0];
  15394. if( (check_ascii < 48) || (check_ascii > 57) )
  15395. {
  15396. isSuccess = ConfigurationStatus_Rejected;
  15397. }
  15398. else
  15399. {
  15400. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15401. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15402. TransactionMessageAttemptsValue = atoi(value);
  15403. isSuccess = ConfigurationStatus_Accepted;
  15404. }
  15405. }
  15406. else
  15407. {
  15408. isSuccess = ConfigurationStatus_Rejected;
  15409. }
  15410. }
  15411. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15412. {
  15413. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15414. {
  15415. check_ascii = value[0];
  15416. if( (check_ascii < 48) || (check_ascii > 57) )
  15417. {
  15418. isSuccess = ConfigurationStatus_Rejected;
  15419. }
  15420. else
  15421. {
  15422. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15423. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15424. TransactionMessageRetryIntervalValue = atoi(value);
  15425. isSuccess = ConfigurationStatus_Accepted;
  15426. }
  15427. }
  15428. else
  15429. {
  15430. isSuccess = ConfigurationStatus_Rejected;
  15431. }
  15432. }
  15433. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15434. {
  15435. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15436. {
  15437. strcpy(str, (const char*)value);
  15438. for(int i = 0; str[i]; i++)
  15439. {
  15440. str[i] = tolower(str[i]);
  15441. }
  15442. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15443. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15444. isSuccess = ConfigurationStatus_Accepted;
  15445. }
  15446. else
  15447. {
  15448. isSuccess = ConfigurationStatus_Rejected;
  15449. }
  15450. }
  15451. if(strcmp(key, "WebSocketPingInterval") == 0)
  15452. {
  15453. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15454. {
  15455. check_ascii = value[0];
  15456. if( (check_ascii < 48) || (check_ascii > 57) )
  15457. {
  15458. isSuccess = ConfigurationStatus_Rejected;
  15459. }
  15460. else
  15461. {
  15462. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15463. isSuccess = ConfigurationStatus_Accepted;
  15464. if((atoi(value) == 0) || (atoi(value) >= 10))
  15465. {
  15466. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15467. isSuccess = ConfigurationStatus_Accepted;
  15468. }
  15469. else
  15470. isSuccess = ConfigurationStatus_Rejected;
  15471. }
  15472. }
  15473. else
  15474. {
  15475. isSuccess = ConfigurationStatus_Rejected;
  15476. }
  15477. }
  15478. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15479. {
  15480. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15481. {
  15482. strcpy(str, (const char*)value);
  15483. for(int i = 0; str[i]; i++)
  15484. {
  15485. str[i] = tolower(str[i]);
  15486. }
  15487. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15488. isSuccess = ConfigurationStatus_Accepted;
  15489. }
  15490. else
  15491. {
  15492. isSuccess = ConfigurationStatus_Rejected;
  15493. }
  15494. }
  15495. if(strcmp(key, "AuthorizationKey") == 0)
  15496. {
  15497. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15498. {
  15499. strcpy(str, (const char*)value);
  15500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15501. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15502. isSuccess = ConfigurationStatus_Accepted;
  15503. }
  15504. else
  15505. {
  15506. isSuccess = ConfigurationStatus_Rejected;
  15507. }
  15508. }
  15509. if(strcmp(key, "SecurityProfile") == 0)
  15510. {
  15511. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15512. {
  15513. check_ascii = value[0];
  15514. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15515. {
  15516. isSuccess = ConfigurationStatus_Rejected;
  15517. }
  15518. else if(check_ascii == 0x33)
  15519. {
  15520. isSuccess = NotSupported;
  15521. }
  15522. else
  15523. {
  15524. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15525. {
  15526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15527. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15528. isSuccess = ConfigurationStatus_Accepted;
  15529. }
  15530. else
  15531. isSuccess = ConfigurationStatus_Rejected;
  15532. }
  15533. }
  15534. else
  15535. {
  15536. isSuccess = ConfigurationStatus_Rejected;
  15537. }
  15538. }
  15539. if(strcmp(key, "DefaultPrice") == 0)
  15540. {
  15541. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15542. {
  15543. strcpy(str, (const char*)value);
  15544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15545. isSuccess = ConfigurationStatus_Accepted;
  15546. }
  15547. else
  15548. {
  15549. isSuccess = ConfigurationStatus_Rejected;
  15550. }
  15551. }
  15552. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15553. {
  15554. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15555. {
  15556. strcpy(str, (const char*)value);
  15557. for(int i = 0; str[i]; i++)
  15558. {
  15559. str[i] = tolower(str[i]);
  15560. }
  15561. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15562. isSuccess = ConfigurationStatus_Accepted;
  15563. }
  15564. else
  15565. {
  15566. isSuccess = ConfigurationStatus_Rejected;
  15567. }
  15568. }
  15569. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15570. {
  15571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15572. {
  15573. strcpy(str, (const char*)value);
  15574. for(int i = 0; str[i]; i++)
  15575. {
  15576. str[i] = tolower(str[i]);
  15577. }
  15578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15579. isSuccess = ConfigurationStatus_Accepted;
  15580. }
  15581. else
  15582. {
  15583. isSuccess = ConfigurationStatus_Rejected;
  15584. }
  15585. }
  15586. if(strcmp(key, "SystemUptimeSec") == 0)
  15587. {
  15588. isSuccess = NotSupported;
  15589. }
  15590. if(strcmp(key, "FreeVend") == 0)
  15591. {
  15592. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15593. {
  15594. strcpy(str, (const char*)value);
  15595. for(int i = 0; str[i]; i++)
  15596. {
  15597. str[i] = tolower(str[i]);
  15598. }
  15599. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15601. isSuccess = ConfigurationStatus_Accepted;
  15602. }
  15603. else
  15604. {
  15605. isSuccess = ConfigurationStatus_Rejected;
  15606. }
  15607. }
  15608. #if 0
  15609. //For OCPP Test Case
  15610. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15611. {
  15612. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15613. {
  15614. strcpy(str, (const char*)value);
  15615. for(int i = 0; str[i]; i++)
  15616. {
  15617. str[i] = tolower(str[i]);
  15618. }
  15619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15620. isSuccess = ConfigurationStatus_Accepted;
  15621. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15622. }
  15623. else
  15624. {
  15625. isSuccess = ConfigurationStatus_Rejected;
  15626. }
  15627. }
  15628. #endif
  15629. #if 1
  15630. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15631. {
  15632. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15633. {
  15634. strcpy(str, (const char*)value);
  15635. for(int i = 0; str[i]; i++)
  15636. {
  15637. str[i] = tolower(str[i]);
  15638. }
  15639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15640. isSuccess = ConfigurationStatus_Accepted;
  15641. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15642. }
  15643. else
  15644. {
  15645. isSuccess = ConfigurationStatus_Rejected;
  15646. }
  15647. }
  15648. #endif
  15649. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15650. {
  15651. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15652. {
  15653. check_ascii = value[0];
  15654. if( (check_ascii < 48) || (check_ascii > 57) )
  15655. {
  15656. isSuccess = ConfigurationStatus_Rejected;
  15657. }
  15658. else
  15659. {
  15660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15661. isSuccess = ConfigurationStatus_Accepted;
  15662. }
  15663. }
  15664. else
  15665. {
  15666. isSuccess = ConfigurationStatus_Rejected;
  15667. }
  15668. }
  15669. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15670. {
  15671. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15672. {
  15673. check_ascii = value[0];
  15674. if( (check_ascii < 48) || (check_ascii > 57) )
  15675. {
  15676. isSuccess = ConfigurationStatus_Rejected;
  15677. }
  15678. else
  15679. {
  15680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15681. isSuccess = ConfigurationStatus_Accepted;
  15682. }
  15683. }
  15684. else
  15685. {
  15686. isSuccess = ConfigurationStatus_Rejected;
  15687. }
  15688. }
  15689. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15690. {
  15691. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15692. {
  15693. strcpy(str, (const char*)value);
  15694. for(int i = 0; str[i]; i++)
  15695. {
  15696. str[i] = tolower(str[i]);
  15697. }
  15698. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15699. isSuccess = ConfigurationStatus_Accepted;
  15700. }
  15701. else
  15702. {
  15703. isSuccess = ConfigurationStatus_Rejected;
  15704. }
  15705. }
  15706. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15707. {
  15708. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15709. {
  15710. check_ascii = value[0];
  15711. if( (check_ascii < 48) || (check_ascii > 57) )
  15712. {
  15713. isSuccess = ConfigurationStatus_Rejected;
  15714. }
  15715. else
  15716. {
  15717. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15718. isSuccess = ConfigurationStatus_Accepted;
  15719. }
  15720. }
  15721. else
  15722. {
  15723. isSuccess = ConfigurationStatus_Rejected;
  15724. }
  15725. }
  15726. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15727. {
  15728. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15729. {
  15730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15731. isSuccess = ConfigurationStatus_Accepted;
  15732. }
  15733. else
  15734. {
  15735. isSuccess = ConfigurationStatus_Rejected;
  15736. }
  15737. }
  15738. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15739. {
  15740. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15741. {
  15742. check_ascii = value[0];
  15743. if( (check_ascii < 48) || (check_ascii > 57) )
  15744. {
  15745. isSuccess = ConfigurationStatus_Rejected;
  15746. }
  15747. else
  15748. {
  15749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15750. isSuccess = ConfigurationStatus_Accepted;
  15751. }
  15752. }
  15753. else
  15754. {
  15755. isSuccess = ConfigurationStatus_Rejected;
  15756. }
  15757. }
  15758. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15759. {
  15760. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15761. {
  15762. strcpy(str, (const char*)value);
  15763. for(int i = 0; str[i]; i++)
  15764. {
  15765. str[i] = tolower(str[i]);
  15766. }
  15767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15768. isSuccess = ConfigurationStatus_Accepted;
  15769. }
  15770. else
  15771. {
  15772. isSuccess = ConfigurationStatus_Rejected;
  15773. }
  15774. }
  15775. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15776. {
  15777. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15778. {
  15779. check_ascii = value[0];
  15780. if( (check_ascii < 48) || (check_ascii > 57) )
  15781. {
  15782. isSuccess = ConfigurationStatus_Rejected;
  15783. }
  15784. else
  15785. {
  15786. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15787. isSuccess = ConfigurationStatus_Accepted;
  15788. }
  15789. }
  15790. else
  15791. {
  15792. isSuccess = ConfigurationStatus_Rejected;
  15793. }
  15794. }
  15795. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15796. return isSuccess;
  15797. }
  15798. int TransactionMessageAttemptsGet(void)
  15799. {
  15800. return TransactionMessageAttemptsValue;
  15801. }
  15802. int FirstHeartBeatResponse(void)
  15803. {
  15804. return FirstHeartBeat;
  15805. }
  15806. int TransactionMessageRetryIntervalGet(void)
  15807. {
  15808. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15809. }
  15810. int ReadHttpStatus(int sock)
  15811. {
  15812. //char c;
  15813. char buff[1024]="",*ptr=buff+1;
  15814. int bytes_received, status;
  15815. DEBUG_INFO("Begin Response ..\n");
  15816. while((bytes_received = recv(sock, ptr, 1, 0))){
  15817. if(bytes_received==-1){
  15818. perror("ReadHttpStatus");
  15819. exit(1);
  15820. }
  15821. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15822. ptr++;
  15823. }
  15824. *ptr=0;
  15825. ptr=buff+1;
  15826. sscanf(ptr,"%*s %d ", &status);
  15827. DEBUG_INFO("%s\n",ptr);
  15828. DEBUG_INFO("status=%d\n",status);
  15829. DEBUG_INFO("End Response ..\n");
  15830. return (bytes_received>0)?status:0;
  15831. }
  15832. //the only filed that it parsed is 'Content-Length'
  15833. int ParseHeader(int sock)
  15834. {
  15835. //char c;
  15836. char buff[1024]="",*ptr=buff+4;
  15837. int bytes_received;
  15838. DEBUG_INFO("Begin HEADER ..\n");
  15839. while((bytes_received = recv(sock, ptr, 1, 0))){
  15840. if(bytes_received==-1){
  15841. perror("Parse Header");
  15842. exit(1);
  15843. }
  15844. if(
  15845. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15846. (ptr[-1]=='\r') && (*ptr=='\n' )
  15847. ) break;
  15848. ptr++;
  15849. }
  15850. *ptr=0;
  15851. ptr=buff+4;
  15852. //printf("%s",ptr);
  15853. if(bytes_received){
  15854. ptr=strstr(ptr,"Content-Length:");
  15855. if(ptr){
  15856. sscanf(ptr,"%*s %d",&bytes_received);
  15857. }else
  15858. bytes_received=-1; //unknown size
  15859. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15860. }
  15861. DEBUG_INFO("End HEADER ..\n");
  15862. return bytes_received ;
  15863. }
  15864. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15865. {
  15866. int result = TRUE;
  15867. char rmFileCmd[100]={0};
  15868. char FilePath[100]={0};
  15869. char ftpbuf[200];
  15870. int systemresult;
  15871. sprintf(FilePath,"/mnt/%s",filename);
  15872. system("ping 8.8.8.8 &");
  15873. if((access(FilePath,F_OK))!=-1)
  15874. {
  15875. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15876. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15877. system(rmFileCmd);
  15878. }
  15879. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15880. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15881. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15882. systemresult = system(ftpbuf);
  15883. if(systemresult != 0)
  15884. {
  15885. DEBUG_INFO("http DownLoad error!\n");
  15886. result = FALSE;
  15887. }
  15888. system("pkill ping");
  15889. return result;
  15890. }
  15891. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15892. {
  15893. int result = TRUE;
  15894. char rmFileCmd[100]={0};
  15895. char FilePath[100]={0};
  15896. char ftpbuf[200];
  15897. int systemresult;
  15898. sprintf(FilePath,"/mnt/%s",filename);
  15899. system("ping 8.8.8.8 &");
  15900. if((access(FilePath,F_OK))!=-1)
  15901. {
  15902. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15903. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15904. system(rmFileCmd);
  15905. }
  15906. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15907. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15908. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15909. systemresult = system(ftpbuf);
  15910. if(systemresult != 0)
  15911. {
  15912. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15913. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15914. systemresult = system(ftpbuf);
  15915. if(systemresult != 0)
  15916. {
  15917. DEBUG_WARN("wget error!\n");
  15918. result = FALSE;
  15919. }
  15920. }
  15921. system("pkill ping");
  15922. return result;
  15923. }
  15924. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15925. {
  15926. char rmFileCmd[100]={0};
  15927. char FilePath[100]={0};
  15928. char buf[512];
  15929. int systemresult = 0;
  15930. //DEBUG_INFO("filename=%s\n",filename);
  15931. //DEBUG_INFO("url=%s\n",url);
  15932. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15933. if((access(FilePath,F_OK))!=-1)
  15934. {
  15935. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15936. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15937. system(rmFileCmd);
  15938. }
  15939. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15940. if(fp == NULL)
  15941. {
  15942. DEBUG_INFO("log is NULL\n");
  15943. return FALSE;
  15944. }
  15945. else
  15946. {
  15947. fprintf(fp, "%s\n", url);
  15948. fprintf(fp, "%s\n", filename);
  15949. fclose(fp);
  15950. }
  15951. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15952. if(phpFP == NULL)
  15953. {
  15954. DEBUG_INFO("PHP upload fail.\n");
  15955. return FALSE;
  15956. }
  15957. else
  15958. {
  15959. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15960. {
  15961. if(strstr(buf, "result") != NULL)
  15962. {
  15963. sscanf(buf, "result: %d", &systemresult);
  15964. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15965. }
  15966. }
  15967. pclose(phpFP);
  15968. }
  15969. if(systemresult != 1)
  15970. {
  15971. DEBUG_INFO("HTTP upload error!\n");
  15972. return FALSE;
  15973. }
  15974. return TRUE;
  15975. }
  15976. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15977. {
  15978. int result = FALSE;
  15979. char ftpbuf[200];
  15980. int systemresult;
  15981. /*
  15982. // Domaind name transfer to IP address
  15983. struct hostent* server;
  15984. char *IPbuffer;
  15985. server = gethostbyname(location);
  15986. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  15987. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15988. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  15989. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  15990. systemresult = system(ftpbuf);
  15991. if(systemresult != 0)
  15992. {
  15993. DEBUG_INFO("ftpput error!\n");
  15994. }
  15995. else
  15996. {
  15997. result = TRUE;
  15998. DEBUG_INFO("ftpput OK!\n");
  15999. }
  16000. return result;
  16001. }
  16002. int GetOcppServerURL()
  16003. {
  16004. int result = FALSE;
  16005. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16006. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16007. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16008. struct yuarel url;
  16009. char urlStr[512];
  16010. // OCPPPH only
  16011. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16012. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16013. {
  16014. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16015. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16016. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16017. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16018. if(yuarel_parse(&url, urlStr) != -1)
  16019. {
  16020. sprintf(OcppProtocol, "%s", url.scheme);
  16021. sprintf(OcppHost, "%s", url.host);
  16022. if(url.path == NULL)
  16023. OcppTempPath[0] = '\0';
  16024. else
  16025. sprintf(OcppTempPath, "%s", url.path);
  16026. if(url.port == 0)
  16027. {
  16028. if(strcmp(OcppProtocol, "wss") == 0)
  16029. OcppPort = 443;
  16030. else
  16031. OcppPort = 80;
  16032. }
  16033. else
  16034. OcppPort = url.port;
  16035. result = TRUE;
  16036. }
  16037. }
  16038. else
  16039. {
  16040. strcpy(OcppHost,"");
  16041. }
  16042. return result;
  16043. }
  16044. int GetOcppPath()
  16045. {
  16046. int result = FALSE;
  16047. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16048. {
  16049. if(OcppTempPath == NULL)
  16050. {
  16051. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16052. }
  16053. else
  16054. {
  16055. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16056. }
  16057. result = TRUE;
  16058. goto End;
  16059. }
  16060. else
  16061. {
  16062. strcpy(OcppPath,"");
  16063. }
  16064. End:
  16065. return result;
  16066. }
  16067. int GetOcppPort()
  16068. {
  16069. return OcppPort;
  16070. }
  16071. int GetOcppConnStatus(void)
  16072. {
  16073. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16074. }
  16075. void SetOcppConnStatus(uint8_t status)
  16076. {
  16077. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16078. }
  16079. int GetHeartBeatWithNOResponse(void)
  16080. {
  16081. return HeartBeatWithNOResponse;
  16082. }
  16083. void SetHeartBeatWithNOResponse(void)
  16084. {
  16085. HeartBeatWithNOResponse = 0;
  16086. }
  16087. void GetStartTransactionIdTag(int gun_index)
  16088. {
  16089. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16090. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16091. }
  16092. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16093. {
  16094. char ch;
  16095. FILE *fptr1;
  16096. int temptransactionId;
  16097. char str[100]={0};
  16098. temptransactionId = 0;
  16099. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16100. {
  16101. DEBUG_INFO("IdTag is empty.\n");
  16102. return temptransactionId;
  16103. }
  16104. /*------ Read the file ----------------*/
  16105. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16106. if (!fptr1)
  16107. {
  16108. DEBUG_INFO("QueueTransactionId file open error.\n");
  16109. //printf(" File not found or unable to open the input file!!\n");
  16110. return temptransactionId;
  16111. }
  16112. ch=fgetc(fptr1);
  16113. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16114. rewind(fptr1);
  16115. if(ch!=EOF)
  16116. {
  16117. // printf("%c",ch);
  16118. while (fgets(str, 100, fptr1) != NULL)
  16119. {
  16120. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16121. if(str[0]=='\0')
  16122. {
  16123. break;
  16124. }
  16125. char *revbuf[8] = {0}; // Variable store string split
  16126. int num = 0;// Quantity after string split
  16127. DEBUG_INFO("Transaction queue data= %s\n", str);
  16128. splitstring(str,",",revbuf,&num); // String split
  16129. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16130. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16131. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16132. DEBUG_INFO("------------------------------\n");
  16133. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16134. {
  16135. if(isStopTransaction)
  16136. {
  16137. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16138. {
  16139. temptransactionId = atoi(revbuf[2]);
  16140. //break;
  16141. }
  16142. }
  16143. else
  16144. {
  16145. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16146. {
  16147. temptransactionId = atoi(revbuf[2]);
  16148. //break;
  16149. }
  16150. }
  16151. }
  16152. }
  16153. }
  16154. else
  16155. DEBUG_INFO("EOF\n");
  16156. fclose(fptr1);
  16157. /*------- End of reading ---------------*/
  16158. return temptransactionId;
  16159. }
  16160. void SetTransactionIdZero(int transactionId)
  16161. {
  16162. char ch;
  16163. FILE *fptr1, *fptr2;
  16164. int temptransactionId = 0;
  16165. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16166. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16167. if (!fptr1)
  16168. {
  16169. //printf(" File not found or unable to open the input file!!\n");
  16170. return ;
  16171. }
  16172. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16173. if (!fptr2)
  16174. {
  16175. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16176. fclose(fptr1);
  16177. return ;
  16178. }
  16179. ch=fgetc(fptr1);
  16180. rewind(fptr1);
  16181. if(ch!=EOF)
  16182. {
  16183. // copy all contents to the temporary file except the specific line
  16184. while (fgets(str, 100, fptr1) != NULL)
  16185. {
  16186. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16187. if(str[0]=='\0')
  16188. {
  16189. break;
  16190. }
  16191. char *revbuf[8] = {0};
  16192. int num = 0;
  16193. strcpy(strtemp, str);
  16194. splitstring(str,",",revbuf,&num);
  16195. if(revbuf[2][0] != '\0')
  16196. {
  16197. temptransactionId = atoi(revbuf[2]);
  16198. if(transactionId != temptransactionId)
  16199. {
  16200. fprintf(fptr2, "%s\n", strtemp);
  16201. }
  16202. }
  16203. }
  16204. }
  16205. fclose(fptr1);
  16206. fclose(fptr2);
  16207. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16208. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16209. /*------ Read the file ----------------*/
  16210. }
  16211. int InternetDisconnect(void)
  16212. {
  16213. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16214. }
  16215. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16216. void storeTempStopTransaction(int gun_index)
  16217. {
  16218. char guid[37]={0};
  16219. int tempIndex = 0;
  16220. char TempStopTransaction[256];
  16221. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16222. DEBUG_INFO("storeTempStopTransaction...\n");
  16223. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16224. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16225. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16226. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16227. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16228. {
  16229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16230. {
  16231. tempIndex = ((gun_index==2) ? 1: 0);
  16232. }
  16233. else
  16234. {
  16235. tempIndex = gun_index;
  16236. }
  16237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16238. {
  16239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16240. {
  16241. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16242. }
  16243. }// END OF CHAdeMO_QUANTITY
  16244. }
  16245. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16246. {
  16247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16248. {
  16249. tempIndex = ((gun_index==2) ? 1: 0);
  16250. }
  16251. else
  16252. {
  16253. tempIndex = gun_index;
  16254. }
  16255. for (int index = 0; index < CCS_QUANTITY; index++)
  16256. {
  16257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16258. {
  16259. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16260. }
  16261. }// END OF CCS_QUANTITY
  16262. }
  16263. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16264. {
  16265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16266. {
  16267. tempIndex = ((gun_index==2) ? 1: 0);
  16268. }
  16269. else
  16270. {
  16271. tempIndex = gun_index;
  16272. }
  16273. for (int index = 0; index < GB_QUANTITY; index++)
  16274. {
  16275. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16276. {
  16277. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16278. }
  16279. }// END OF GB_QUANTITY
  16280. }
  16281. else if(gunType[gun_index] == GUN_TYPE_DO)
  16282. {
  16283. tempIndex = gun_index;
  16284. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16285. {
  16286. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16287. {
  16288. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16289. }
  16290. }
  16291. }
  16292. else
  16293. {
  16294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16295. {
  16296. tempIndex = 2;
  16297. }
  16298. else
  16299. {
  16300. tempIndex = gun_index;
  16301. }
  16302. for (int index = 0; index < AC_QUANTITY; index++)
  16303. {
  16304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16305. {
  16306. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16307. }
  16308. }// END OF AC_QUANTITY
  16309. }
  16310. //Stop Transaction Time
  16311. struct timeval tmnow;
  16312. struct tm *tm;
  16313. char buf[28];//, usec_buf[6];
  16314. gettimeofday(&tmnow, NULL);
  16315. time_t t;
  16316. t = time(NULL);
  16317. /*UTC time and date*/
  16318. tm = gmtime(&t);
  16319. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16320. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16321. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16322. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16323. random_uuid(guid);
  16324. /***********************************transactionData******************************************************/
  16325. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16326. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16327. //=================================
  16328. //1. Transaction_Begin
  16329. //=================================
  16330. //============================== Energy.Active.Import.Interval ===========================================
  16331. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16332. {
  16333. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16336. 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*/]);
  16337. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16338. 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))
  16339. {
  16340. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16341. }
  16342. else
  16343. {
  16344. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16345. }
  16346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16347. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16348. }
  16349. //=================================
  16350. //2. Transaction_End
  16351. //=================================
  16352. //2.1====================================== Current.Import L1 ==============================================
  16353. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16354. {
  16355. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16356. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16357. {
  16358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16359. {
  16360. tempIndex = ((gun_index==2) ? 1: 0);
  16361. }
  16362. else
  16363. {
  16364. tempIndex = gun_index;
  16365. }
  16366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16367. {
  16368. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16369. {
  16370. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16371. }
  16372. }// End of for CHAdeMO_QUANTITY
  16373. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16374. }
  16375. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16376. {
  16377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16378. {
  16379. tempIndex = ((gun_index==2) ? 1: 0);
  16380. }
  16381. else
  16382. {
  16383. tempIndex = gun_index;
  16384. }
  16385. for (int index = 0; index < CCS_QUANTITY; index++)
  16386. {
  16387. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16388. {
  16389. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16390. }
  16391. }// End of for CCS_QUANTITY
  16392. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16393. }
  16394. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16395. {
  16396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16397. {
  16398. tempIndex = ((gun_index==2) ? 1: 0);
  16399. }
  16400. else
  16401. {
  16402. tempIndex = gun_index;
  16403. }
  16404. for (int index = 0; index < GB_QUANTITY; index++)
  16405. {
  16406. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16407. {
  16408. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16409. }
  16410. }// End of for GB_QUANTITY
  16411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16412. }
  16413. else if(gunType[gun_index] == GUN_TYPE_DO)
  16414. {
  16415. tempIndex = gun_index;
  16416. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16417. {
  16418. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16419. {
  16420. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16421. }
  16422. }
  16423. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16424. }
  16425. else
  16426. {
  16427. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16428. {
  16429. tempIndex = 2;
  16430. }
  16431. else
  16432. {
  16433. tempIndex = gun_index;
  16434. }
  16435. for (int index = 0; index < AC_QUANTITY; index++)
  16436. {
  16437. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16438. {
  16439. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16440. }
  16441. }// End of for AC_QUANTITY
  16442. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16443. }
  16444. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16445. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16447. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16449. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16450. }
  16451. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16452. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16453. {
  16454. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16455. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16456. {
  16457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16458. {
  16459. tempIndex = ((gun_index==2) ? 1: 0);
  16460. }
  16461. else
  16462. {
  16463. tempIndex = gun_index;
  16464. }
  16465. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16466. {
  16467. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16468. {
  16469. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16470. }
  16471. }// END OF CHAdeMO_QUANTITY
  16472. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16473. }
  16474. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16475. {
  16476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16477. {
  16478. tempIndex = ((gun_index==2) ? 1: 0);
  16479. }
  16480. else
  16481. {
  16482. tempIndex = gun_index;
  16483. }
  16484. for (int index = 0; index < CCS_QUANTITY; index++)
  16485. {
  16486. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16487. {
  16488. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16489. }
  16490. }// END OF CCS_QUANTITY
  16491. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16492. }
  16493. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16494. {
  16495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16496. {
  16497. tempIndex = ((gun_index==2) ? 1: 0);
  16498. }
  16499. else
  16500. {
  16501. tempIndex = gun_index;
  16502. }
  16503. for (int index = 0; index < GB_QUANTITY; index++)
  16504. {
  16505. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16506. {
  16507. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16508. }
  16509. }// END OF GB_QUANTITY
  16510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16511. }
  16512. else if(gunType[gun_index] == GUN_TYPE_DO)
  16513. {
  16514. tempIndex = gun_index;
  16515. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16516. {
  16517. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16518. {
  16519. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16520. }
  16521. }
  16522. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16523. }
  16524. else
  16525. {
  16526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16527. {
  16528. tempIndex = 2;
  16529. }
  16530. else
  16531. {
  16532. tempIndex = gun_index;
  16533. }
  16534. for (int index = 0; index < AC_QUANTITY; index++)
  16535. {
  16536. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16537. {
  16538. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16539. }
  16540. }// END OF AC_QUANTITY
  16541. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16542. }
  16543. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16546. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16548. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16549. }
  16550. //2.3====================================== Power.Active.Import =========================================
  16551. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16552. {
  16553. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16554. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16555. {
  16556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16557. {
  16558. tempIndex = ((gun_index==2) ? 1: 0);
  16559. }
  16560. else
  16561. {
  16562. tempIndex = gun_index;
  16563. }
  16564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16565. {
  16566. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16567. {
  16568. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16569. }
  16570. } // End for CHAdeMO_QUANTITY
  16571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16572. }
  16573. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16574. {
  16575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16576. {
  16577. tempIndex = ((gun_index==2) ? 1: 0);
  16578. }
  16579. else
  16580. {
  16581. tempIndex = gun_index;
  16582. }
  16583. for (int index = 0; index < CCS_QUANTITY; index++)
  16584. {
  16585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16586. {
  16587. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16588. }
  16589. } // END for CCS_QUANTITY
  16590. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16591. }
  16592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16593. {
  16594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16595. {
  16596. tempIndex = ((gun_index==2) ? 1: 0);
  16597. }
  16598. else
  16599. {
  16600. tempIndex = gun_index;
  16601. }
  16602. for (int index = 0; index < GB_QUANTITY; index++)
  16603. {
  16604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16605. {
  16606. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16607. }
  16608. }// END for GB_QUANTITY
  16609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16610. }
  16611. else if(gunType[gun_index] == GUN_TYPE_DO)
  16612. {
  16613. tempIndex = gun_index;
  16614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16615. {
  16616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16617. {
  16618. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16619. }
  16620. }
  16621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16622. }
  16623. else
  16624. {
  16625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16626. {
  16627. tempIndex = 2;
  16628. }
  16629. else
  16630. {
  16631. tempIndex = gun_index;
  16632. }
  16633. for (int index = 0; index < AC_QUANTITY; index++)
  16634. {
  16635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16636. {
  16637. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16638. }
  16639. } // END for AC_QUANTITY
  16640. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16641. }
  16642. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16643. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16644. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16645. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16647. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16648. }
  16649. //2.4====================================== Voltage L1 ====================================================
  16650. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16651. {
  16652. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16653. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16654. {
  16655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16656. {
  16657. tempIndex = ((gun_index==2) ? 1: 0);
  16658. }
  16659. else
  16660. {
  16661. tempIndex = gun_index;
  16662. }
  16663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16664. {
  16665. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16666. {
  16667. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16668. }
  16669. } // END OF FOR CHAdeMO_QUANTITY
  16670. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16671. }
  16672. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16673. {
  16674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16675. {
  16676. tempIndex = ((gun_index==2) ? 1: 0);
  16677. }
  16678. else
  16679. {
  16680. tempIndex = gun_index;
  16681. }
  16682. for (int index = 0; index < CCS_QUANTITY; index++)
  16683. {
  16684. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16685. {
  16686. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16687. }
  16688. } // END OF FOR CCS_QUANTITY
  16689. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16690. }
  16691. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16692. {
  16693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16694. {
  16695. tempIndex = ((gun_index==2) ? 1: 0);
  16696. }
  16697. else
  16698. {
  16699. tempIndex = gun_index;
  16700. }
  16701. for (int index = 0; index < GB_QUANTITY; index++)
  16702. {
  16703. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16704. {
  16705. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16706. }
  16707. } // END OF FOR GB_QUANTITY
  16708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16709. }
  16710. else if(gunType[gun_index] == GUN_TYPE_DO)
  16711. {
  16712. tempIndex = gun_index;
  16713. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16714. {
  16715. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16716. {
  16717. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16718. }
  16719. }
  16720. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16721. }
  16722. else
  16723. {
  16724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16725. {
  16726. tempIndex = 2;
  16727. }
  16728. else
  16729. {
  16730. tempIndex = gun_index;
  16731. }
  16732. for (int index = 0; index < AC_QUANTITY; index++)
  16733. {
  16734. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16735. {
  16736. 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
  16737. }
  16738. } // END OF FOR AC_QUANTITY
  16739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16740. }
  16741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16744. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16747. }
  16748. //2.5============================================== End SoC =========================================================
  16749. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16750. {
  16751. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16752. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  16753. {
  16754. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16755. {
  16756. tempIndex = ((gun_index==2) ? 1: 0);
  16757. }
  16758. else
  16759. {
  16760. tempIndex = gun_index;
  16761. }
  16762. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16763. {
  16764. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16765. {
  16766. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16767. {
  16768. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16769. }
  16770. }
  16771. }
  16772. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16773. {
  16774. for (int index = 0; index < CCS_QUANTITY; index++)
  16775. {
  16776. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16777. {
  16778. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16779. }
  16780. }
  16781. }
  16782. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16783. {
  16784. for (int index = 0; index < GB_QUANTITY; index++)
  16785. {
  16786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16787. {
  16788. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16789. }
  16790. }
  16791. }
  16792. else if(gunType[gun_index] == GUN_TYPE_DO)
  16793. {
  16794. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16795. {
  16796. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16797. {
  16798. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16799. }
  16800. }
  16801. }
  16802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16808. } // END FOR DC CASE
  16809. }
  16810. //2.6====================================== Current.Import L2 ==============================================
  16811. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16812. {
  16813. // AC 3 phase L2 current
  16814. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16815. {
  16816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16817. {
  16818. tempIndex = 2;
  16819. }
  16820. else
  16821. {
  16822. tempIndex = gun_index;
  16823. }
  16824. for (int index = 0; index < AC_QUANTITY; index++)
  16825. {
  16826. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16827. {
  16828. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16829. }
  16830. }// End of for AC_QUANTITY
  16831. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16832. }
  16833. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16834. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16835. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16836. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16837. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16838. }
  16839. //2.7====================================== Current.Import L3 ==============================================
  16840. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16841. {
  16842. // AC 3 phase L3 current
  16843. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16844. {
  16845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16846. {
  16847. tempIndex = 2;
  16848. }
  16849. else
  16850. {
  16851. tempIndex = gun_index;
  16852. }
  16853. for (int index = 0; index < AC_QUANTITY; index++)
  16854. {
  16855. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16856. {
  16857. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16858. }
  16859. }// End of for AC_QUANTITY
  16860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16861. }
  16862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16864. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16866. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16867. }
  16868. //2.9====================================== Voltage L2 ====================================================
  16869. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16870. {
  16871. // AC 3 phase L2 volatge
  16872. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16873. {
  16874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16875. {
  16876. tempIndex = 2;
  16877. }
  16878. else
  16879. {
  16880. tempIndex = gun_index;
  16881. }
  16882. for (int index = 0; index < AC_QUANTITY; index++)
  16883. {
  16884. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16885. {
  16886. 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
  16887. }
  16888. } // END OF FOR AC_QUANTITY
  16889. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16890. }
  16891. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16892. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16893. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16894. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16895. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16896. }
  16897. //2.10====================================== Voltage L3 ====================================================
  16898. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16899. {
  16900. // AC 3 phase L3 volatge
  16901. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16902. {
  16903. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16904. {
  16905. tempIndex = 2;
  16906. }
  16907. else
  16908. {
  16909. tempIndex = gun_index;
  16910. }
  16911. for (int index = 0; index < AC_QUANTITY; index++)
  16912. {
  16913. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16914. {
  16915. 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
  16916. }
  16917. } // END OF FOR AC_QUANTITY
  16918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16919. }
  16920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16922. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16923. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16925. }
  16926. //====================== Start SoC ================================
  16927. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16928. {
  16929. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16930. 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))
  16931. {
  16932. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16933. {
  16934. tempIndex = ((gun_index==2) ? 1: 0);
  16935. }
  16936. else
  16937. {
  16938. tempIndex = gun_index;
  16939. }
  16940. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16941. {
  16942. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16943. {
  16944. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16945. {
  16946. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16947. }
  16948. }
  16949. }
  16950. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16951. {
  16952. for (int index = 0; index < CCS_QUANTITY; index++)
  16953. {
  16954. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16955. {
  16956. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16957. }
  16958. }
  16959. }
  16960. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16961. {
  16962. for (int index = 0; index < GB_QUANTITY; index++)
  16963. {
  16964. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16965. {
  16966. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16967. }
  16968. }
  16969. }
  16970. else if(gunType[gun_index] == GUN_TYPE_DO)
  16971. {
  16972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16973. {
  16974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16975. {
  16976. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16977. }
  16978. }
  16979. }
  16980. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16981. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16983. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16985. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16986. } // END FOR DC CASE
  16987. }
  16988. //======================================== Message create ==============================================
  16989. json_object *StopTransaction = json_object_new_object();
  16990. json_object *transactionDatas = json_object_new_array();
  16991. json_object *sampledValues = json_object_new_array();
  16992. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  16993. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16994. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16995. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16996. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16997. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16998. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16999. {
  17000. json_object *transactionData = json_object_new_object();
  17001. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17002. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17003. {
  17004. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17005. {
  17006. json_object *sampledValue = json_object_new_object();
  17007. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17008. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17009. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17010. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17011. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17012. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17013. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17014. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17015. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17016. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17017. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17018. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17019. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17020. json_object_array_add(sampledValues, sampledValue);
  17021. }
  17022. }
  17023. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17024. json_object_array_add(transactionDatas, transactionData);
  17025. }
  17026. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17027. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17028. ,MESSAGE_TYPE_CALL
  17029. ,guid
  17030. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17031. json_object_put(StopTransaction);
  17032. // Check File "TempStopTransaction" Exist
  17033. if((access(TempStopTransaction,F_OK))!=-1)
  17034. {
  17035. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17036. fclose(fopen(TempStopTransaction, "w"));
  17037. }
  17038. else
  17039. {
  17040. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17041. FILE *log = fopen(TempStopTransaction, "w+");
  17042. if(log == NULL)
  17043. {
  17044. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17045. return ;
  17046. }
  17047. else
  17048. {
  17049. fclose(log);
  17050. }
  17051. }
  17052. //Add TempStopTransaction | Update TempStopTransaction
  17053. // open file for writing
  17054. FILE *outfile;
  17055. outfile = fopen (TempStopTransaction, "a");
  17056. //DEBUG_INFO("data = %s\n", queuedata);
  17057. fputs(queuedata, outfile);
  17058. fputs("\n", outfile);
  17059. fclose (outfile);
  17060. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17061. }
  17062. void checkTempStopTransaction(int gun_index)
  17063. {
  17064. FILE *fptr1;
  17065. char ch;
  17066. char str[QUEUE_MESSAGE_LENGTH]={0};
  17067. char guid[37]={0};
  17068. char tempdata[65]={0};
  17069. char connectorStr[2]={0};
  17070. char TempStopTransaction[256];
  17071. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17072. fptr1 = fopen(TempStopTransaction, "r");
  17073. //TempStopTransaction格式: 槍號,StopTransaction封包
  17074. if (!fptr1)
  17075. {
  17076. //printf(" File not found or unable to open the input file!!\n");
  17077. return ;
  17078. }
  17079. ch=fgetc(fptr1);
  17080. //printf(" Now the content of the file %s is : \n",fname);
  17081. rewind(fptr1);
  17082. if(ch!=EOF)
  17083. {
  17084. // copy all contents to the temporary file except the specific line
  17085. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17086. {
  17087. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17088. if(str[0]=='\0')
  17089. {
  17090. break;
  17091. }
  17092. //TempStopTransaction格式: 槍號,StopTransaction封包
  17093. strncpy(connectorStr, str, 1);
  17094. if(atoi(connectorStr) != (gun_index+1))
  17095. {
  17096. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17097. fclose(fptr1);
  17098. return ;
  17099. }
  17100. //random_uuid(guid);
  17101. strncpy(guid, str+6, 36); //copy guid
  17102. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17103. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17104. {
  17105. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17106. }
  17107. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17108. OCPP_insert_transaction_msg(NO, str);
  17109. memset(str,0,ARRAY_SIZE(str));
  17110. }
  17111. }
  17112. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17113. fclose(fptr1);
  17114. remove(TempStopTransaction); // remove the original file
  17115. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17116. }
  17117. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17118. {
  17119. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17120. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17121. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17122. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17123. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17124. }
  17125. int GetWebSocketPingInterval(void)
  17126. {
  17127. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17128. }
  17129. int GetServerSign(void)
  17130. {
  17131. return server_sign;
  17132. }
  17133. uint8_t GetOcppSecurityProfile()
  17134. {
  17135. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17136. }
  17137. void GetOcppChargerBoxId(uint8_t *data)
  17138. {
  17139. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17140. }
  17141. void GetOcppSecurityPassword(uint8_t *data)
  17142. {
  17143. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17144. }
  17145. void SetOcppVersion(uint8_t *version)
  17146. {
  17147. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17148. DEBUG_INFO("ocpp version: %s\n", version);
  17149. if(strstr((char*)version, "ocpp1.6") != NULL)
  17150. {
  17151. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17152. }
  17153. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17154. {
  17155. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17156. system("pkill OcppBackend");
  17157. }
  17158. }
  17159. void SetServerSign(int value)
  17160. {
  17161. server_sign = value;
  17162. }
  17163. int GetBootNotificationInterval(void)
  17164. {
  17165. return BootNotificationInterval;
  17166. }
  17167. int GetInternetConn(void)
  17168. {
  17169. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17170. }
  17171. int GetBackendConnectionTimeout(void)
  17172. {
  17173. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17174. }
  17175. int isConnectorInitMode(int gun_index)
  17176. {
  17177. int tempIndex = 0;
  17178. int result = TRUE;
  17179. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17180. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17181. {
  17182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17183. {
  17184. tempIndex = ((gun_index==2) ? 1: 0);
  17185. }
  17186. else
  17187. {
  17188. tempIndex = gun_index;
  17189. }
  17190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17191. {
  17192. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17193. {
  17194. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17195. } //end of the same index
  17196. }//end of for CHAdeMO_QUANTITY
  17197. }
  17198. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17199. {
  17200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17201. {
  17202. tempIndex = ((gun_index==2) ? 1: 0);
  17203. }
  17204. else
  17205. {
  17206. tempIndex = gun_index;
  17207. }
  17208. for (int index = 0; index < CCS_QUANTITY; index++)
  17209. {
  17210. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17211. {
  17212. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17213. } //end of the same index
  17214. } // end of for CCS_QUANTITY
  17215. }
  17216. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17217. {
  17218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17219. {
  17220. tempIndex = ((gun_index==2) ? 1: 0);
  17221. }
  17222. else
  17223. {
  17224. tempIndex = gun_index;
  17225. }
  17226. for (int index = 0; index < GB_QUANTITY; index++)
  17227. {
  17228. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17229. {
  17230. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17231. } //end of the same index
  17232. } // end of for GB_QUANTITY
  17233. }
  17234. else if(gunType[gun_index] == GUN_TYPE_DO)
  17235. {
  17236. tempIndex = gun_index;
  17237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17238. {
  17239. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17240. {
  17241. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17242. } //end of the same index
  17243. }
  17244. }
  17245. else
  17246. {
  17247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17248. {
  17249. tempIndex = 2;
  17250. }
  17251. else
  17252. {
  17253. tempIndex = gun_index;
  17254. }
  17255. for (int index = 0; index < AC_QUANTITY; index++)
  17256. {
  17257. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17258. {
  17259. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17260. }//end of the same index
  17261. }//end of for AC_QUANTITY
  17262. }
  17263. return result;
  17264. }
  17265. void refreshProcDogTimer()
  17266. {
  17267. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17268. }
  17269. void InitialSystemValue(void)
  17270. {
  17271. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17272. locallistVersion=0;
  17273. BootNotificationInterval = 0;
  17274. authorizeRetryTimes = 0;
  17275. GunStatusInterval = 10;
  17276. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17277. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17278. //Hear Beat
  17279. HeartBeatWithNOResponse = 0;
  17280. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17281. FirstHeartBeat = 0;
  17282. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17283. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17284. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17285. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17286. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17287. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17288. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17289. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17290. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17291. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17292. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17293. //Status && ConnectorPlugIn Setting
  17294. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17295. {
  17296. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17297. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17298. }
  17299. for (int index = 0; index < CCS_QUANTITY; index++)
  17300. {
  17301. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17302. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17303. }
  17304. for (int index = 0; index < GB_QUANTITY; index++)
  17305. {
  17306. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17307. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17308. }
  17309. for (int index = 0; index < AC_QUANTITY; index++)
  17310. {
  17311. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17312. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17313. }
  17314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17315. {
  17316. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17317. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17318. }
  17319. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17320. {
  17321. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17322. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17323. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17324. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17325. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17326. }
  17327. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17328. refreshStartTimer(&clientTime.Heartbeat);
  17329. sleep(1);
  17330. }
  17331. void LWS_Send(char *str)
  17332. {
  17333. //=====================================================
  17334. // Check InternetConn 0: disconnected, 1: connected
  17335. //====================================================
  17336. if(GetOcppConnStatus() == 0)
  17337. {
  17338. DEBUG_INFO("offline now !!!\n");
  17339. return;
  17340. }
  17341. // Only disable isWebsocketSendable operation initiated by charger
  17342. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17343. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17344. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17345. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17346. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17347. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17348. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17349. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17350. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17351. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17352. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17353. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17354. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17355. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17356. {
  17357. isWebsocketSendable = 0;
  17358. }
  17359. pthread_mutex_lock(&lock_send);
  17360. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17361. sprintf((char *)SendBuffer, "%s", str);
  17362. SendBufLen = strlen(str);
  17363. pthread_mutex_unlock(&lock_send);
  17364. lws_callback_on_writable(wsi_client);
  17365. //lws_service(context, 0);
  17366. //sleep(1);
  17367. }
  17368. void LWS_SendNow(char *str)
  17369. {
  17370. //=====================================================
  17371. // Check InternetConn 0: disconnected, 1: connected
  17372. //====================================================
  17373. if(GetOcppConnStatus() == 0)
  17374. {
  17375. DEBUG_INFO("offline now !!!\n");
  17376. return;
  17377. }
  17378. // Only disable isWebsocketSendable operation initiated by charger
  17379. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17380. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17381. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17382. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17383. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17384. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17385. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17386. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17387. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17388. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17389. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17390. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17391. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17392. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17393. {
  17394. isWebsocketSendable = 0;
  17395. }
  17396. pthread_mutex_lock(&lock_send);
  17397. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17398. sprintf((char *)SendBuffer, "%s", str);
  17399. SendBufLen = strlen(str);
  17400. pthread_mutex_unlock(&lock_send);
  17401. lws_callback_on_writable(wsi_client);
  17402. lws_service(context, 0);
  17403. //sleep(1);
  17404. }