MessageHandler.c 795 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // Save configuration
  356. //=========================================
  357. int runShellCmd(const char*cmd)
  358. {
  359. int result = FAIL;
  360. char buf[256];
  361. FILE *fp;
  362. fp = popen(cmd, "r");
  363. if(fp != NULL)
  364. {
  365. while(fgets(buf, sizeof(buf), fp) != NULL)
  366. {
  367. DEBUG_INFO("%s\n", buf);
  368. }
  369. result = PASS;
  370. }
  371. pclose(fp);
  372. return result;
  373. }
  374. int StoreUsrConfigData(struct SysConfigData *UsrData)
  375. {
  376. int result = PASS;
  377. int fd,wrd;
  378. unsigned int i,Chk;
  379. unsigned char *ptr, *BufTmp;
  380. int MtdBlockSize = 0x300000;
  381. Chk=0;
  382. ptr=(unsigned char *)UsrData;
  383. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  384. {
  385. memset(BufTmp,0,MtdBlockSize);
  386. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  387. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  388. Chk+=*(BufTmp+i);
  389. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  390. // Output configuration to file.
  391. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  392. if (fd < 0)
  393. {
  394. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  395. free(BufTmp);
  396. return 0;
  397. }
  398. wrd=write(fd, BufTmp, MtdBlockSize);
  399. close(fd);
  400. if(wrd<MtdBlockSize)
  401. {
  402. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  407. DEBUG_INFO("Erase /dev/mtd10.\n");
  408. runShellCmd("flash_erase /dev/mtd10 0 0");
  409. DEBUG_INFO("Write /dev/mtd10.\n");
  410. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  411. DEBUG_INFO("Erase /dev/mtd11.\n");
  412. runShellCmd("flash_erase /dev/mtd11 0 0");
  413. DEBUG_INFO("Write /dev/mtd11.\n");
  414. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  415. system("rm -f /mnt/EvseConfig.bin");
  416. DEBUG_INFO("EvseConfig write to flash OK\n");
  417. }
  418. else
  419. {
  420. DEBUG_ERROR("alloc BlockSize NG\r\n");
  421. result = FAIL;
  422. }
  423. if(BufTmp!=NULL)
  424. free(BufTmp);
  425. return result;
  426. }
  427. //=========================================
  428. // Sqlite3 related function
  429. //=========================================
  430. static int selectSqlCount = 0;
  431. static int callback(void *data, int argc, char **argv, char **azColName){
  432. int i;
  433. //printf("%s: ", (const char*)data);
  434. selectSqlCount = argc;
  435. for(i = 0; i<argc; i++){
  436. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  437. }
  438. //printf("\n");
  439. return 0;
  440. }
  441. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  442. //int i;
  443. //printf("%s:\n", (const char*)data);
  444. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  445. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  446. return 0;
  447. }
  448. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  449. //printf("%s:\n", (const char*)data);
  450. //idTag
  451. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. //parentIdTag
  454. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  455. //expir_date
  456. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  457. //status
  458. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  459. //version
  460. if(columenCount > 5)
  461. idTagQuery.listVersionInt = atoi(columnValue[5]);
  462. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  463. return 0;
  464. }
  465. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  466. {
  467. // localversion = argv[5] ? atoi(argv[5]) : 0;
  468. // printf("localversion=%d\n", localversion);
  469. return 0;
  470. }
  471. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  472. {
  473. for (int i = 0; i < n_columns; i++)
  474. {
  475. DEBUG_INFO("%s\t", col_values[i]);
  476. }
  477. DEBUG_INFO("\n");
  478. return 0;
  479. }
  480. int OCPP_cleanLocalCache()
  481. {
  482. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  483. char *errMsg = 0;
  484. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  485. if (SQLITE_OK != rc)
  486. {
  487. DEBUG_INFO("SQL error: %s\n",errMsg);
  488. return FALSE;
  489. }
  490. return TRUE;
  491. }
  492. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  493. {
  494. int isSuccess = TRUE;
  495. int ret = 0;
  496. //const char* data = "Callback function called";
  497. char sql[300];
  498. char zErrMsg[200];
  499. memset(sql, 0, 300);
  500. memset(zErrMsg, 0, 200);
  501. 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);
  502. //* Execute SQL statement */
  503. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  504. if( ret != SQLITE_OK )
  505. {
  506. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  507. isSuccess = FALSE;
  508. }
  509. return isSuccess;
  510. }
  511. void OCPP_getIdTagFromLocalCache(char idTag[])
  512. {
  513. int rc = 0;
  514. char sql[100];
  515. char zErrMsg[100];
  516. memset(sql, 0, 100);
  517. memset(zErrMsg, 0, 100);
  518. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  519. memset(&idTagQuery, 0, sizeof(idTagQuery));
  520. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  521. /* Execute SQL statement */
  522. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  523. if( rc != SQLITE_OK )
  524. {
  525. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  526. }
  527. }
  528. void OCPP_getListVerion()
  529. {
  530. int rc = 0;
  531. // const char* data = "Callback function called";
  532. char sql[100];
  533. char zErrMsg[100];
  534. memset(sql, 0, 100);
  535. memset(zErrMsg, 0, 100);
  536. strcpy(sql, "select * from ocpp_auth_local order by idx");
  537. /* Execute SQL statement */
  538. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  539. if( rc != SQLITE_OK )
  540. {
  541. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  542. }
  543. }
  544. void OCPP_get_TableAuthlocalAllData(void)
  545. {
  546. int rc = 0;
  547. char sql[100];
  548. char zErrMsg[100];
  549. memset(sql, 0, 100);
  550. memset(zErrMsg, 0, 100);
  551. sprintf(sql,"select * from ocpp_auth_local ");
  552. /* Execute SQL statement */
  553. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  554. if( rc != SQLITE_OK )
  555. {
  556. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  557. }
  558. //return ver;
  559. }
  560. int OCPP_cleanLocalList()
  561. {
  562. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  563. char *errMsg = 0;
  564. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  565. if (SQLITE_OK != rc)
  566. {
  567. DEBUG_INFO("%s\n",errMsg);
  568. return FALSE;
  569. }
  570. return TRUE;
  571. }
  572. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  573. {
  574. int isSuccess = FALSE;
  575. int ret = 0;
  576. //const char* data = "Callback function called";
  577. char sql[300];
  578. char zErrMsg[200];
  579. memset(sql, 0, 300);
  580. memset(zErrMsg, 0, 200);
  581. 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);
  582. //* Execute SQL statement */
  583. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  584. if( ret != SQLITE_OK )
  585. {
  586. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  587. return isSuccess;
  588. }
  589. memset(sql, 0, 300);
  590. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  591. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. isSuccess = TRUE;
  598. return isSuccess;
  599. }
  600. void OCPP_getIdTagFromLocalList(char idTag[])
  601. {
  602. int rc = 0;
  603. // const char* data = "Callback function called";
  604. char sql[100];
  605. char zErrMsg[100];
  606. memset(sql, 0, 100);
  607. memset(zErrMsg, 0, 100);
  608. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  609. memset(&idTagQuery, 0, sizeof(idTagQuery));
  610. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  611. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  612. /* Execute SQL statement */
  613. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  614. if( rc != SQLITE_OK )
  615. {
  616. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  617. }
  618. //return ver;
  619. }
  620. void OCPP_deleteIdTagFromLocalList(char idTag[])
  621. {
  622. //int ver = 0;
  623. //int isSuccess = FALSE;
  624. int rc = 0;
  625. char sql[100];
  626. char zErrMsg[100];
  627. memset(sql, 0, 100);
  628. memset(zErrMsg, 0, 100);
  629. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  630. //* Execute SQL statement */
  631. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  632. if( rc != SQLITE_OK )
  633. {
  634. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  635. }
  636. }
  637. int getCurrentYear()
  638. {
  639. int result = 0;
  640. time_t CurrentTime;
  641. struct tm *tm;
  642. CurrentTime = time(NULL);
  643. tm=localtime(&CurrentTime);
  644. result = (tm->tm_year + 1900);
  645. return result;
  646. }
  647. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  648. {
  649. int result = PASS;
  650. char* errMsg = NULL;
  651. char sqlStr[8192];
  652. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  653. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  654. {
  655. result = FAIL;
  656. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  657. }
  658. 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));
  659. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  660. {
  661. result = FAIL;
  662. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  663. }
  664. return result;
  665. }
  666. //==========================================
  667. // Check time passed since today
  668. //==========================================
  669. long long DiffTimebWithNow(struct timeb ST)
  670. {
  671. //return milli-second
  672. struct timeb ET;
  673. long long StartTime,StopTime;
  674. ftime(&ET);
  675. StartTime=(long long)ST.time;
  676. StopTime=(long long)ET.time;
  677. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  678. }
  679. int getTimePassSinceToday(uint8_t gun_index)
  680. {
  681. int result = -1;
  682. static time_t lastTime[4];
  683. time_t t;
  684. struct tm *tmStartToday;
  685. struct timeb tbStartToday;
  686. t=time(NULL);
  687. if(difftime(t, lastTime[gun_index])>0)
  688. {
  689. tmStartToday=localtime(&t);
  690. tmStartToday->tm_hour = 0;
  691. tmStartToday->tm_min = 0;
  692. tmStartToday->tm_sec = 0;
  693. tbStartToday.time = mktime(tmStartToday);
  694. tbStartToday.millitm = 0;
  695. result = DiffTimebWithNow(tbStartToday)/1000;
  696. lastTime[gun_index] = t;
  697. }
  698. return result;
  699. }
  700. void getNowDatetime(uint8_t *data)
  701. {
  702. time_t t = time(NULL);
  703. struct tm tm = *localtime(&t);
  704. 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);
  705. }
  706. int syncDateTimeRTC(uint8_t *data)
  707. {
  708. struct ParsingResult
  709. {
  710. int result;
  711. int scanedElement;
  712. int year;
  713. int month;
  714. int mday;
  715. int hour;
  716. int min;
  717. int sec;
  718. int tz_hour;
  719. int tz_min;
  720. float minSec;
  721. }result;
  722. struct tm tmOrg;
  723. struct tm *tmTarget;
  724. struct timeb tbTarget;
  725. char buf[128];
  726. memset(&result, 0x00, sizeof(struct ParsingResult));
  727. result.result = PASS;
  728. if(strstr((char*)data, ".") != NULL)
  729. {
  730. // Original data with mini second
  731. if(strstr((char*)data, "Z") != NULL)
  732. {
  733. // Original data with Z
  734. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  735. &result.year,
  736. &result.month,
  737. &result.mday,
  738. &result.hour,
  739. &result.min,
  740. &result.sec,
  741. &result.minSec);
  742. }
  743. else
  744. {
  745. // Original data without Z
  746. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  747. &result.year,
  748. &result.month,
  749. &result.mday,
  750. &result.hour,
  751. &result.min,
  752. &result.sec,
  753. &result.minSec,
  754. &result.tz_hour,
  755. &result.tz_min);
  756. }
  757. }
  758. else
  759. {
  760. // Original data without mini second
  761. if(strstr((char*)data, "Z") != NULL)
  762. {
  763. // Original data with Z
  764. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  765. &result.year,
  766. &result.month,
  767. &result.mday,
  768. &result.hour,
  769. &result.min,
  770. &result.sec);
  771. }
  772. else
  773. {
  774. // Original data without Z
  775. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  776. &result.year,
  777. &result.month,
  778. &result.mday,
  779. &result.hour,
  780. &result.min,
  781. &result.sec,
  782. &result.tz_hour,
  783. &result.tz_min);
  784. }
  785. }
  786. tmOrg.tm_year = result.year - 1900;
  787. tmOrg.tm_mon = result.month - 1;
  788. tmOrg.tm_mday = result.mday;
  789. tmOrg.tm_hour = result.hour;
  790. tmOrg.tm_min = result.min;
  791. tmOrg.tm_sec = result.sec;
  792. tmOrg.tm_gmtoff = 0;
  793. tbTarget.time = mktime(&tmOrg);
  794. tbTarget.timezone = 0;
  795. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  796. tmTarget = gmtime(&tbTarget.time);
  797. 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);
  798. //DEBUG_INFO(" org date time: %s\n", data);
  799. //DEBUG_INFO("parse date time: %s\n", buf);
  800. system(buf);
  801. system("/sbin/hwclock -w --systohc");
  802. if(result.scanedElement < 6)
  803. result.result = FAIL;
  804. return result.result;
  805. }
  806. //==========================================
  807. // GetCompositeSchedule logic related function
  808. //==========================================
  809. int DiffTimebSec(struct timeb ST, struct timeb ET)
  810. {
  811. //return milli-second
  812. unsigned int StartTime,StopTime;
  813. StartTime=(unsigned int)ST.time;
  814. StopTime=(unsigned int)ET.time;
  815. return (StopTime-StartTime);
  816. }
  817. int DiffTimebWithNowSec(struct timeb ST)
  818. {
  819. //return milli-second
  820. struct timeb ET;
  821. unsigned int StartTime,StopTime;
  822. ftime(&ET);
  823. StartTime=(unsigned int)ST.time;
  824. StopTime=(unsigned int)ET.time;
  825. return (StopTime-StartTime);
  826. }
  827. int getStartStop(uint8_t *start, uint8_t *stop)
  828. {
  829. int result = -1;
  830. struct tm tmStart;
  831. struct timeb tbStart;
  832. struct tm tmStop;
  833. struct timeb tbStop;
  834. 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) &&
  835. (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))
  836. {
  837. //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);
  838. //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);
  839. tmStart.tm_year -= 1900;
  840. tmStart.tm_mon -= 1;
  841. tbStart.time = mktime(&tmStart);
  842. tbStart.millitm = 0;
  843. tmStop.tm_year -= 1900;
  844. tmStop.tm_mon -= 1;
  845. tbStop.time = mktime(&tmStop);
  846. tbStop.millitm = 0;
  847. result = DiffTimebSec(tbStart, tbStop);
  848. //DEBUG_INFO("getStartStop(): %d\n", result);
  849. }
  850. else
  851. {
  852. DEBUG_WARN("Start or stop date parsing error.\r\n");
  853. }
  854. return result;
  855. }
  856. int isOvertNow(uint8_t *start)
  857. {
  858. int result = NO;
  859. struct tm tmStart;
  860. struct timeb tbStart;
  861. 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))
  862. {
  863. //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);
  864. tmStart.tm_year -= 1900;
  865. tmStart.tm_mon -= 1;
  866. tbStart.time = mktime(&tmStart);
  867. tbStart.millitm = 0;
  868. if(DiffTimebWithNowSec(tbStart) <= 0)
  869. result = NO;
  870. else
  871. result = YES;
  872. }
  873. else
  874. {
  875. DEBUG_WARN("Start date parsing error.\n");
  876. }
  877. return result;
  878. }
  879. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  880. {
  881. int result = -1;
  882. struct tm tmStart;
  883. struct timeb tbStart;
  884. struct tm tmStop;
  885. struct timeb tbStop;
  886. 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) &&
  887. (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))
  888. {
  889. tmStart.tm_year -= 1900;
  890. tmStart.tm_mon -= 1;
  891. tbStart.time = mktime(&tmStart);
  892. tbStart.millitm = 0;
  893. tmStop.tm_year -= 1900;
  894. tmStop.tm_mon -= 1;
  895. tbStop.time = mktime(&tmStop);
  896. tbStop.millitm = 0;
  897. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  898. }
  899. return result;
  900. }
  901. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  902. {
  903. FILE *fp;
  904. char profileFileName[128];
  905. char *line = NULL;
  906. size_t len = 0;
  907. time_t CurrentTime;
  908. struct tm *tmComposite;
  909. struct StructChargingProfile maxProfile;
  910. struct StructChargingProfile defaultTxProfile;
  911. struct StructChargingProfile txProfile;
  912. struct StructChargingSchedulePeriod tmpPeriod;
  913. uint8_t limitMax=0;
  914. uint8_t limitDef=0;
  915. uint8_t limitTx=0;
  916. int compositePeriodIdx = 0;
  917. CurrentTime = time(NULL);
  918. tmComposite=localtime(&CurrentTime);
  919. 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);
  920. if(isUnitA)
  921. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  922. else
  923. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  924. compositeProfile->ChargingSchedule.Duration = durationReq;
  925. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  926. {
  927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  929. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  930. }
  931. compositeProfile->ChargingProfileId = 0;
  932. compositeProfile->StackLevel = 99 ;
  933. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  934. maxProfile.ChargingProfileId = -1;
  935. defaultTxProfile.ChargingProfileId = -1;
  936. txProfile.ChargingProfileId = -1;
  937. maxProfile.ChargingSchedule.Duration = -1;
  938. defaultTxProfile.ChargingSchedule.Duration = -1;
  939. txProfile.ChargingSchedule.Duration = -1;
  940. system("rm -f /tmp/*.json");
  941. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  942. /*
  943. * Search valid charging profile
  944. */
  945. //DEBUG_INFO("====================================\n");
  946. // Search tx profile
  947. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  948. if((access(profileFileName, F_OK))!=-1)
  949. {
  950. fp = fopen(profileFileName, "r");
  951. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  952. {
  953. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  955. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  956. }
  957. txProfile.ChargingProfileId = -1;
  958. txProfile.StackLevel = -1;
  959. while(getline(&line, &len, fp) != -1)
  960. {
  961. json_object *obj = NULL;
  962. obj = json_tokener_parse(line);
  963. if(is_error(obj))
  964. {
  965. DEBUG_ERROR("Parse txProfile from file error.\n");
  966. }
  967. else
  968. {
  969. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  970. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  971. )
  972. {
  973. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  974. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  975. )
  976. {
  977. struct tm tmFrom, tmTo;
  978. struct timeb tbFrom, tbTo;
  979. 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) &&
  980. (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))
  981. {
  982. tmFrom.tm_year -= 1900;
  983. tmFrom.tm_mon -= 1;
  984. tbFrom.time = mktime(&tmFrom);
  985. tmTo.tm_year -= 1900;
  986. tmTo.tm_mon -= 1;
  987. tbTo.time = mktime(&tmTo);
  988. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  989. {
  990. if(txProfile.ChargingProfileId == -1)
  991. DEBUG_INFO("TxProfile found.\n");
  992. else
  993. DEBUG_INFO("TxProfile updated.\n");
  994. // Required item
  995. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  996. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  997. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  998. if(isUnitA)
  999. {
  1000. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1001. 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++)
  1002. {
  1003. 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"));
  1004. 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?
  1005. 3:
  1006. 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")));
  1007. 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")));
  1008. }
  1009. }
  1010. else
  1011. {
  1012. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1013. 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++)
  1014. {
  1015. 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"));
  1016. 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?
  1017. 3:
  1018. 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")));
  1019. 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));
  1020. }
  1021. }
  1022. // Optional item
  1023. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1024. {
  1025. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1026. }
  1027. else
  1028. {
  1029. sprintf((char*)txProfile.ValidFrom, " ");
  1030. }
  1031. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1032. {
  1033. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1034. }
  1035. else
  1036. {
  1037. sprintf((char*)txProfile.ValidTo, " ");
  1038. }
  1039. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1040. {
  1041. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1042. }
  1043. else
  1044. {
  1045. sprintf((char*)txProfile.RecurrencyKind, " ");
  1046. }
  1047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1048. {
  1049. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1050. }
  1051. else
  1052. {
  1053. txProfile.TransactionId = -1;
  1054. }
  1055. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1056. {
  1057. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1058. }
  1059. else
  1060. {
  1061. txProfile.ChargingSchedule.Duration = 86400;
  1062. }
  1063. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1064. {
  1065. 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")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1070. }
  1071. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1072. {
  1073. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1074. }
  1075. else
  1076. {
  1077. txProfile.ChargingSchedule.MinChargingRate = -1;
  1078. }
  1079. }
  1080. }
  1081. }
  1082. else
  1083. {
  1084. if(txProfile.ChargingProfileId == -1)
  1085. DEBUG_INFO("TxProfile found.\n");
  1086. else
  1087. DEBUG_INFO("TxProfile updated.\n");
  1088. // Required item
  1089. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1090. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1091. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1092. if(isUnitA)
  1093. {
  1094. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1095. 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++)
  1096. {
  1097. 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"));
  1098. 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?
  1099. 3:
  1100. 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")));
  1101. 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")));
  1102. }
  1103. }
  1104. else
  1105. {
  1106. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1107. 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++)
  1108. {
  1109. 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"));
  1110. 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?
  1111. 3:
  1112. 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")));
  1113. 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));
  1114. }
  1115. }
  1116. // Optional item
  1117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1118. {
  1119. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1120. }
  1121. else
  1122. {
  1123. sprintf((char*)txProfile.ValidFrom, " ");
  1124. }
  1125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1126. {
  1127. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1128. }
  1129. else
  1130. {
  1131. sprintf((char*)txProfile.ValidTo, " ");
  1132. }
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1134. {
  1135. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)txProfile.RecurrencyKind, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1142. {
  1143. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1144. }
  1145. else
  1146. {
  1147. txProfile.TransactionId = -1;
  1148. }
  1149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1150. {
  1151. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1152. }
  1153. else
  1154. {
  1155. txProfile.ChargingSchedule.Duration = 86400;
  1156. }
  1157. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1158. {
  1159. 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")));
  1160. }
  1161. else
  1162. {
  1163. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1166. {
  1167. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1168. }
  1169. else
  1170. {
  1171. txProfile.ChargingSchedule.MinChargingRate = -1;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. json_object_put(obj);
  1177. }
  1178. fclose(fp);
  1179. /*
  1180. if(txProfile.ChargingProfileId != -1)
  1181. {
  1182. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1183. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1184. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1185. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1186. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1187. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1188. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1189. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1190. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1191. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1192. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1193. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1194. {
  1195. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1196. {
  1197. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1198. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1199. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1200. }
  1201. }
  1202. }
  1203. else
  1204. DEBUG_INFO("TxProfile not found.\n");*/
  1205. }
  1206. // Search default tx profile
  1207. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1208. if((access(profileFileName, F_OK))==-1)
  1209. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1210. if((access(profileFileName, F_OK))!=-1)
  1211. {
  1212. fp = fopen(profileFileName, "r");
  1213. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1214. {
  1215. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1217. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1218. }
  1219. defaultTxProfile.ChargingProfileId = -1;
  1220. defaultTxProfile.StackLevel = -1;
  1221. while(getline(&line, &len, fp) != -1)
  1222. {
  1223. json_object *obj = NULL;
  1224. obj = json_tokener_parse(line);
  1225. if(is_error(obj))
  1226. {
  1227. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1228. }
  1229. else
  1230. {
  1231. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1232. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1233. )
  1234. {
  1235. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1236. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1237. )
  1238. {
  1239. struct tm tmFrom, tmTo;
  1240. struct timeb tbFrom, tbTo;
  1241. 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) &&
  1242. (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))
  1243. {
  1244. tmFrom.tm_year -= 1900;
  1245. tmFrom.tm_mon -= 1;
  1246. tbFrom.time = mktime(&tmFrom);
  1247. tmTo.tm_year -= 1900;
  1248. tmTo.tm_mon -= 1;
  1249. tbTo.time = mktime(&tmTo);
  1250. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1251. {
  1252. if(defaultTxProfile.ChargingProfileId == -1)
  1253. DEBUG_INFO("TxDefaultProfile found.\n");
  1254. else
  1255. DEBUG_INFO("TxDefaultProfile updated.\n");
  1256. // Required item
  1257. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1258. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1259. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1260. if(isUnitA)
  1261. {
  1262. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1263. 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++)
  1264. {
  1265. 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"));
  1266. 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?
  1267. 3:
  1268. 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")));
  1269. 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")));
  1270. }
  1271. }
  1272. else
  1273. {
  1274. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1275. 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++)
  1276. {
  1277. 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"));
  1278. 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?
  1279. 3:
  1280. 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")));
  1281. 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));
  1282. }
  1283. }
  1284. // Optional item
  1285. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1286. {
  1287. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1288. }
  1289. else
  1290. {
  1291. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1292. }
  1293. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1294. {
  1295. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1296. }
  1297. else
  1298. {
  1299. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1300. }
  1301. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1302. {
  1303. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1304. }
  1305. else
  1306. {
  1307. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1308. }
  1309. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1310. {
  1311. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1312. }
  1313. else
  1314. {
  1315. defaultTxProfile.TransactionId = -1;
  1316. }
  1317. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1318. {
  1319. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1320. }
  1321. else
  1322. {
  1323. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1324. }
  1325. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1326. {
  1327. 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")));
  1328. }
  1329. else
  1330. {
  1331. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1332. }
  1333. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1334. {
  1335. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1336. }
  1337. else
  1338. {
  1339. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. else
  1345. {
  1346. if(defaultTxProfile.ChargingProfileId == -1)
  1347. DEBUG_INFO("TxDefaultProfile found.\n");
  1348. else
  1349. DEBUG_INFO("TxDefaultProfile updated.\n");
  1350. // Required item
  1351. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1352. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1353. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1354. if(isUnitA)
  1355. {
  1356. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1357. 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++)
  1358. {
  1359. 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"));
  1360. 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?
  1361. 3:
  1362. 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")));
  1363. 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")));
  1364. }
  1365. }
  1366. else
  1367. {
  1368. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1369. 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++)
  1370. {
  1371. 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"));
  1372. 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?
  1373. 3:
  1374. 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")));
  1375. 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));
  1376. }
  1377. }
  1378. // Optional item
  1379. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1380. {
  1381. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1382. }
  1383. else
  1384. {
  1385. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1386. }
  1387. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1388. {
  1389. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1390. }
  1391. else
  1392. {
  1393. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1394. }
  1395. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1396. {
  1397. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1398. }
  1399. else
  1400. {
  1401. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1402. }
  1403. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1404. {
  1405. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1406. }
  1407. else
  1408. {
  1409. defaultTxProfile.TransactionId = -1;
  1410. }
  1411. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1412. {
  1413. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1414. }
  1415. else
  1416. {
  1417. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1418. }
  1419. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1420. {
  1421. 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")));
  1422. }
  1423. else
  1424. {
  1425. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1426. }
  1427. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1428. {
  1429. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1430. }
  1431. else
  1432. {
  1433. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. json_object_put(obj);
  1439. }
  1440. fclose(fp);
  1441. /*
  1442. if(defaultTxProfile.ChargingProfileId != -1)
  1443. {
  1444. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1445. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1446. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1447. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1448. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1449. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1450. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1451. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1452. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1453. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1454. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1456. {
  1457. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1458. {
  1459. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1460. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1461. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1462. }
  1463. }
  1464. }
  1465. else
  1466. DEBUG_INFO("TxDefaultProfile not found.\n");
  1467. DEBUG_INFO("------------------------------------\n");*/
  1468. }
  1469. // Search max profile
  1470. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1471. if((access(profileFileName, F_OK))!=-1)
  1472. {
  1473. fp = fopen(profileFileName, "r");
  1474. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1475. {
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1478. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1479. }
  1480. maxProfile.ChargingProfileId = -1;
  1481. maxProfile.StackLevel = -1;
  1482. while(getline(&line, &len, fp) != -1)
  1483. {
  1484. json_object *obj = NULL;
  1485. obj = json_tokener_parse(line);
  1486. if(is_error(obj))
  1487. {
  1488. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1489. }
  1490. else
  1491. {
  1492. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1493. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1494. )
  1495. {
  1496. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1497. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1498. )
  1499. {
  1500. struct tm tmFrom, tmTo;
  1501. struct timeb tbFrom, tbTo;
  1502. 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) &&
  1503. (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))
  1504. {
  1505. tmFrom.tm_year -= 1900;
  1506. tmFrom.tm_mon -= 1;
  1507. tbFrom.time = mktime(&tmFrom);
  1508. tmTo.tm_year -= 1900;
  1509. tmTo.tm_mon -= 1;
  1510. tbTo.time = mktime(&tmTo);
  1511. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1512. {
  1513. if(maxProfile.ChargingProfileId == -1)
  1514. DEBUG_INFO("MaxProfile found.\n");
  1515. else
  1516. DEBUG_INFO("MaxProfile updated.\n");
  1517. // Required item
  1518. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1519. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1520. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1521. if(isUnitA)
  1522. {
  1523. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1524. 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++)
  1525. {
  1526. 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"));
  1527. 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?
  1528. 3:
  1529. 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")));
  1530. 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")));
  1531. }
  1532. }
  1533. else
  1534. {
  1535. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1536. 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++)
  1537. {
  1538. 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"));
  1539. 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?
  1540. 3:
  1541. 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")));
  1542. 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));
  1543. }
  1544. }
  1545. // Optional item
  1546. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1547. {
  1548. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1549. }
  1550. else
  1551. {
  1552. sprintf((char*)maxProfile.ValidFrom, " ");
  1553. }
  1554. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1555. {
  1556. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1557. }
  1558. else
  1559. {
  1560. sprintf((char*)maxProfile.ValidTo, " ");
  1561. }
  1562. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1563. {
  1564. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1565. }
  1566. else
  1567. {
  1568. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1569. }
  1570. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1571. {
  1572. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1573. }
  1574. else
  1575. {
  1576. maxProfile.TransactionId = -1;
  1577. }
  1578. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1579. {
  1580. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1581. }
  1582. else
  1583. {
  1584. maxProfile.ChargingSchedule.Duration = 86400;
  1585. }
  1586. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1587. {
  1588. 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")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1593. }
  1594. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1595. {
  1596. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1597. }
  1598. else
  1599. {
  1600. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1601. }
  1602. }
  1603. }
  1604. }
  1605. else
  1606. {
  1607. if(maxProfile.ChargingProfileId == -1)
  1608. DEBUG_INFO("MaxProfile found.\n");
  1609. else
  1610. DEBUG_INFO("MaxProfile updated.\n");
  1611. // Required item
  1612. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1613. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1614. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1615. if(isUnitA)
  1616. {
  1617. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1618. 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++)
  1619. {
  1620. 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"));
  1621. 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?
  1622. 3:
  1623. 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")));
  1624. 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")));
  1625. }
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1630. 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++)
  1631. {
  1632. 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"));
  1633. 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?
  1634. 3:
  1635. 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")));
  1636. 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));
  1637. }
  1638. }
  1639. // Optional item
  1640. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1641. {
  1642. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1643. }
  1644. else
  1645. {
  1646. sprintf((char*)maxProfile.ValidFrom, " ");
  1647. }
  1648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1649. {
  1650. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1651. }
  1652. else
  1653. {
  1654. sprintf((char*)maxProfile.ValidTo, " ");
  1655. }
  1656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1657. {
  1658. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1659. }
  1660. else
  1661. {
  1662. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1663. }
  1664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1665. {
  1666. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1667. }
  1668. else
  1669. {
  1670. maxProfile.TransactionId = -1;
  1671. }
  1672. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1673. {
  1674. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1675. }
  1676. else
  1677. {
  1678. maxProfile.ChargingSchedule.Duration = 86400;
  1679. }
  1680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1681. {
  1682. 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")));
  1683. }
  1684. else
  1685. {
  1686. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1687. }
  1688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1689. {
  1690. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1691. }
  1692. else
  1693. {
  1694. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1695. }
  1696. }
  1697. }
  1698. }
  1699. json_object_put(obj);
  1700. }
  1701. fclose(fp);
  1702. /*
  1703. if(maxProfile.ChargingProfileId !=-1)
  1704. {
  1705. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1706. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1707. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1708. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1709. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1710. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1711. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1712. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1713. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1714. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1715. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1717. {
  1718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1719. {
  1720. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1721. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1722. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1723. }
  1724. }
  1725. }
  1726. else
  1727. DEBUG_INFO("MaxProfile not found.\n");
  1728. DEBUG_INFO("------------------------------------\n");*/
  1729. }
  1730. /*
  1731. * Align found profile start schedule & periods
  1732. */
  1733. //DEBUG_INFO("====================================\n");
  1734. /*
  1735. // For local test usage, force modify found profile start schedule info
  1736. 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);
  1737. 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);
  1738. 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);
  1739. */
  1740. if(txProfile.ChargingProfileId != -1)
  1741. {
  1742. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1743. {
  1744. if(txProfile.ChargingSchedule.Duration != -1)
  1745. {
  1746. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1747. 0:
  1748. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1749. }
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1753. {
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1755. 0:
  1756. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1757. if(idxPeriod > 0)
  1758. {
  1759. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1760. {
  1761. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1768. {
  1769. if(txProfile.ChargingSchedule.Duration != -1)
  1770. {
  1771. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1772. 0:
  1773. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1774. }
  1775. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1776. {
  1777. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1778. {
  1779. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1780. 0:
  1781. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1782. if(idxPeriod > 0)
  1783. {
  1784. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1785. {
  1786. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1787. }
  1788. }
  1789. }
  1790. }
  1791. }
  1792. else
  1793. {
  1794. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1795. {
  1796. if(txProfile.ChargingSchedule.Duration != -1)
  1797. {
  1798. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1799. 0:
  1800. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1801. }
  1802. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1803. {
  1804. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1805. {
  1806. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1807. 0:
  1808. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1809. if(idxPeriod > 0)
  1810. {
  1811. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1812. {
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1814. }
  1815. }
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(txProfile.ChargingSchedule.Duration != -1)
  1822. {
  1823. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1824. 0:
  1825. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1826. }
  1827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1828. {
  1829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1830. {
  1831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1832. 0:
  1833. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1834. if(idxPeriod > 0)
  1835. {
  1836. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1837. {
  1838. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }
  1845. /*
  1846. DEBUG_INFO("txProfile after align.\n");
  1847. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1848. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1849. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1850. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1851. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1852. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1853. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1854. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1855. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1856. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1857. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1858. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1859. {
  1860. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1861. {
  1862. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1863. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1864. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1865. }
  1866. }*/
  1867. }
  1868. if(defaultTxProfile.ChargingProfileId != -1)
  1869. {
  1870. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1871. {
  1872. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1873. {
  1874. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1875. 0:
  1876. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1877. }
  1878. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1879. {
  1880. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1881. {
  1882. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1883. 0:
  1884. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1885. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1886. {
  1887. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1888. }
  1889. if(idxPeriod > 0)
  1890. {
  1891. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1892. {
  1893. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. }
  1899. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1900. {
  1901. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1902. {
  1903. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1904. 0:
  1905. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1906. }
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1910. {
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1912. 0:
  1913. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1914. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1915. {
  1916. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1917. }
  1918. if(idxPeriod > 0)
  1919. {
  1920. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1921. {
  1922. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1923. }
  1924. }
  1925. }
  1926. }
  1927. }
  1928. else
  1929. {
  1930. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1931. {
  1932. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1933. {
  1934. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1935. 0:
  1936. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1937. }
  1938. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1939. {
  1940. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1941. {
  1942. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1943. 0:
  1944. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1945. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1946. {
  1947. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1948. }
  1949. if(idxPeriod > 0)
  1950. {
  1951. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1952. {
  1953. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1954. }
  1955. }
  1956. }
  1957. }
  1958. }
  1959. else
  1960. {
  1961. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1962. {
  1963. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1964. 0:
  1965. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1966. }
  1967. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1968. {
  1969. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1970. {
  1971. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1972. 0:
  1973. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1974. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1975. {
  1976. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1977. }
  1978. if(idxPeriod > 0)
  1979. {
  1980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1981. {
  1982. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. }
  1989. /*
  1990. DEBUG_INFO("defaultTxProfile after align.\n");
  1991. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1992. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1993. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1994. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1995. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1996. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1997. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1998. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1999. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2000. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2001. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2003. {
  2004. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2005. {
  2006. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2007. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2008. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2009. }
  2010. }
  2011. DEBUG_INFO("------------------------------------\n");*/
  2012. }
  2013. if(maxProfile.ChargingProfileId != -1)
  2014. {
  2015. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2016. {
  2017. if(maxProfile.ChargingSchedule.Duration != -1)
  2018. {
  2019. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2020. 0:
  2021. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2022. }
  2023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2024. {
  2025. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2026. {
  2027. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2028. 0:
  2029. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2030. if(idxPeriod > 0)
  2031. {
  2032. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2033. {
  2034. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2035. }
  2036. }
  2037. }
  2038. }
  2039. }
  2040. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2041. {
  2042. if(maxProfile.ChargingSchedule.Duration != -1)
  2043. {
  2044. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2045. 0:
  2046. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2047. }
  2048. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2049. {
  2050. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2051. {
  2052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2053. 0:
  2054. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2055. if(idxPeriod > 0)
  2056. {
  2057. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2058. {
  2059. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. else
  2066. {
  2067. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2068. {
  2069. if(maxProfile.ChargingSchedule.Duration != -1)
  2070. {
  2071. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2072. 0:
  2073. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2074. }
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2078. {
  2079. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2080. 0:
  2081. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2082. if(idxPeriod > 0)
  2083. {
  2084. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2085. {
  2086. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2087. }
  2088. }
  2089. }
  2090. }
  2091. }
  2092. else
  2093. {
  2094. if(maxProfile.ChargingSchedule.Duration != -1)
  2095. {
  2096. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2097. 0:
  2098. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2099. }
  2100. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2101. {
  2102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2103. {
  2104. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2105. 0:
  2106. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2107. if(idxPeriod > 0)
  2108. {
  2109. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2110. {
  2111. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. /*
  2119. DEBUG_INFO("MaxProfile after align.\n");
  2120. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2121. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2122. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2123. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2124. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2125. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2126. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2127. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2128. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2129. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2130. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2131. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2132. {
  2133. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2134. {
  2135. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2136. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2137. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2138. }
  2139. }
  2140. DEBUG_INFO("------------------------------------\n");*/
  2141. }
  2142. /*
  2143. * Merge to conposite schedule
  2144. */
  2145. //DEBUG_INFO("====================================\n");
  2146. // Find each profile period quantity
  2147. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2148. {
  2149. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2150. limitMax = idx+1;
  2151. }
  2152. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2153. {
  2154. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2155. limitDef = idx+1;
  2156. }
  2157. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2158. {
  2159. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2160. limitTx = idx+1;
  2161. }
  2162. // TxProfile found, composite schedule based on it
  2163. if(txProfile.ChargingProfileId != -1)
  2164. {
  2165. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2166. {
  2167. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2168. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2169. (txProfile.ChargingSchedule.Duration > 0))
  2170. {
  2171. if(maxProfile.ChargingProfileId != -1)
  2172. {
  2173. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2174. {
  2175. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2176. {
  2177. if((maxProfile.ChargingSchedule.Duration > 0))
  2178. {
  2179. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2180. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2181. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2182. }
  2183. else
  2184. {
  2185. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2186. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2187. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2188. }
  2189. }
  2190. if(idxMaxPeriod == (limitMax-1))
  2191. {
  2192. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2193. {
  2194. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2195. {
  2196. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2197. compositePeriodIdx++;
  2198. }
  2199. else
  2200. {
  2201. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. else
  2208. {
  2209. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2210. {
  2211. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2212. compositePeriodIdx++;
  2213. }
  2214. else
  2215. {
  2216. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2217. }
  2218. }
  2219. }
  2220. if(idxTxPeriod == (limitTx-1))
  2221. {
  2222. if(defaultTxProfile.ChargingProfileId != -1)
  2223. {
  2224. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2225. {
  2226. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2227. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2228. (defaultTxProfile.ChargingSchedule.Duration>0))
  2229. {
  2230. if(maxProfile.ChargingProfileId != -1)
  2231. {
  2232. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2233. {
  2234. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2235. {
  2236. if((maxProfile.ChargingSchedule.Duration > 0))
  2237. {
  2238. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2239. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2240. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2241. }
  2242. else
  2243. {
  2244. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2245. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2246. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2247. }
  2248. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2249. {
  2250. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2251. {
  2252. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2253. compositePeriodIdx++;
  2254. }
  2255. else
  2256. {
  2257. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2258. }
  2259. }
  2260. // Delete duplicate period
  2261. if(compositePeriodIdx > 1)
  2262. {
  2263. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2264. {
  2265. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2266. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2267. compositePeriodIdx -= 1;
  2268. }
  2269. }
  2270. }
  2271. else
  2272. break;
  2273. }
  2274. }
  2275. else
  2276. {
  2277. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2278. {
  2279. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2280. compositePeriodIdx++;
  2281. }
  2282. else
  2283. {
  2284. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2294. else if(defaultTxProfile.ChargingProfileId != -1)
  2295. {
  2296. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2297. {
  2298. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2299. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2300. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2301. {
  2302. if(maxProfile.ChargingProfileId != -1)
  2303. {
  2304. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2305. {
  2306. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2307. {
  2308. if((maxProfile.ChargingSchedule.Duration > 0))
  2309. {
  2310. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2311. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2312. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2313. }
  2314. else
  2315. {
  2316. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2317. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2318. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2319. }
  2320. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2321. {
  2322. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2323. {
  2324. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2325. compositePeriodIdx++;
  2326. }
  2327. else
  2328. {
  2329. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2330. }
  2331. }
  2332. // Delete duplicate period
  2333. if(compositePeriodIdx > 1)
  2334. {
  2335. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2336. {
  2337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2338. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2339. compositePeriodIdx -= 1;
  2340. }
  2341. }
  2342. }
  2343. else
  2344. break;
  2345. }
  2346. }
  2347. else
  2348. {
  2349. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2350. {
  2351. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2352. compositePeriodIdx++;
  2353. }
  2354. else
  2355. {
  2356. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2357. }
  2358. }
  2359. }
  2360. }
  2361. }
  2362. // Fill other period by MaxProfile
  2363. if(maxProfile.ChargingProfileId != -1)
  2364. {
  2365. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2366. {
  2367. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2368. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2369. (maxProfile.ChargingSchedule.Duration > 0))
  2370. {
  2371. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2372. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2373. {
  2374. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2375. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2376. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2377. }
  2378. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2379. {
  2380. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2381. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2382. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2383. }
  2384. if(tmpPeriod.Limit != -1)
  2385. {
  2386. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2387. {
  2388. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2389. {
  2390. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2391. compositePeriodIdx++;
  2392. }
  2393. else
  2394. {
  2395. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2396. }
  2397. }
  2398. // Delete duplicate period
  2399. if(compositePeriodIdx > 1)
  2400. {
  2401. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2402. {
  2403. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2404. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2405. compositePeriodIdx -= 1;
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2413. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2414. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2415. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2417. {
  2418. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2419. {
  2420. compositeProfile->ChargingProfileId = 1;
  2421. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2422. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2423. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2424. }
  2425. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2426. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2427. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2428. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2429. }
  2430. if(line)
  2431. free(line);
  2432. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2433. }
  2434. //==========================================
  2435. // Init all share memory
  2436. //==========================================
  2437. int InitShareMemory()
  2438. {
  2439. int result = PASS;
  2440. int MeterSMId;
  2441. //creat ShmSysConfigAndInfo
  2442. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2443. {
  2444. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2445. result = FAIL;
  2446. }
  2447. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2448. {
  2449. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2450. result = FAIL;
  2451. }
  2452. else
  2453. {}
  2454. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2455. {
  2456. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2457. result = FAIL;
  2458. }
  2459. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2460. {
  2461. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2462. result = FAIL;
  2463. }
  2464. else
  2465. {}
  2466. //creat ShmPsuData
  2467. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2468. {
  2469. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2470. result = FAIL;
  2471. }
  2472. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2473. {
  2474. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2475. result = FAIL;
  2476. }
  2477. else
  2478. {}
  2479. //creat ShmOCPP16Data
  2480. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2481. {
  2482. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2483. result = FAIL;
  2484. }
  2485. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2486. {
  2487. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2488. result = FAIL;
  2489. }
  2490. else
  2491. {}
  2492. /****************************** For Initial Settings************************************************/
  2493. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2494. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2495. // allocate Configuration memory address
  2496. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2497. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2498. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2499. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2500. //offline MeterValue Interval
  2501. TempMeterValueInterval = 0;
  2502. return result;
  2503. }
  2504. int ProcessShareMemory()
  2505. {
  2506. if(InitShareMemory() == FAIL)
  2507. {
  2508. DEBUG_ERROR("InitShareMemory NG\n");
  2509. if(ShmStatusCodeData!=NULL)
  2510. {
  2511. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2512. }
  2513. sleep(5);
  2514. return FAIL;
  2515. }
  2516. return PASS;
  2517. }
  2518. void CheckSystemValue(void)
  2519. {
  2520. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2521. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2522. char filenmae[100]={0};
  2523. char str[100]={0};
  2524. int tempIndex = 0;
  2525. //===============================
  2526. // send Heartbeat
  2527. //===============================
  2528. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2529. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2530. {
  2531. clientTime.Heartbeat=time((time_t*)NULL);
  2532. if(server_sign == TRUE)
  2533. {
  2534. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2535. }
  2536. else
  2537. {
  2538. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2539. }
  2540. }
  2541. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2542. {
  2543. //parameter for test
  2544. sendHeartbeatRequest(0);
  2545. //==============================================
  2546. // Reset Waiting Time
  2547. //==============================================
  2548. HeartBeatWithNOResponse += 1;
  2549. }
  2550. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2551. {
  2552. //==========================================
  2553. // csu trigger DataTransferReq
  2554. //==========================================
  2555. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2556. {
  2557. sendDataTransferRequest(gun_index);
  2558. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2559. }
  2560. //===============================
  2561. // CSU Trigger Authorize Request
  2562. //===============================
  2563. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2564. {
  2565. sendAuthorizeRequest(0);
  2566. authorizeRetryTimes = authorizeRetryTimes + 1;
  2567. if(authorizeRetryTimes < 3)
  2568. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2569. }
  2570. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2571. {
  2572. authorizeRetryTimes = 0;
  2573. SetOcppConnStatus(FALSE);
  2574. server_sign = FALSE;
  2575. }
  2576. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2577. {
  2578. sendAuthorizeRequest(0);
  2579. }
  2580. //==============================================
  2581. // Charger start transaction
  2582. //==============================================
  2583. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2584. {
  2585. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2586. sendStartTransactionRequest(gun_index);
  2587. clientTime.StartTransaction = time((time_t*)NULL);
  2588. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2589. storeTempStopTransaction(gun_index);
  2590. }
  2591. //==============================================
  2592. // Charger stop transaction
  2593. //==============================================
  2594. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2595. {
  2596. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2597. sendStopTransactionRequest(gun_index);
  2598. clientTime.StopTransaction = time((time_t*)NULL);
  2599. }
  2600. //==============================================
  2601. // Charger status report
  2602. //==============================================
  2603. //--- Check Mode Change ---//
  2604. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2605. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2606. {
  2607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2608. {
  2609. tempIndex = ((gun_index==2) ? 1: 0);
  2610. }
  2611. else
  2612. {
  2613. tempIndex = gun_index;
  2614. }
  2615. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2616. {
  2617. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2618. {
  2619. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2620. {
  2621. // Sent unplug message for California pricing logic
  2622. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2623. {
  2624. uint8_t ts[20];
  2625. getNowDatetime(ts);
  2626. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2627. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2628. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2629. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2630. }
  2631. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2632. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2633. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2634. }
  2635. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2636. {
  2637. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2638. if((access(filenmae,F_OK))!=-1)
  2639. {
  2640. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2641. sprintf(str,"rm -f %s",filenmae);
  2642. system(str);
  2643. }
  2644. }
  2645. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2646. #if 1 // for TempStopTransaction
  2647. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2648. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2649. {
  2650. checkTempStopTransaction(gun_index);
  2651. }
  2652. #endif
  2653. }
  2654. }
  2655. }
  2656. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2657. {
  2658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2659. {
  2660. tempIndex = ((gun_index==2) ? 1: 0);
  2661. }
  2662. else
  2663. {
  2664. tempIndex = gun_index;
  2665. }
  2666. for (int index = 0; index < CCS_QUANTITY; index++)
  2667. {
  2668. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2669. {
  2670. 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]*/ )
  2671. {
  2672. // Sent unplug message for California pricing logic
  2673. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2674. {
  2675. uint8_t ts[20];
  2676. getNowDatetime(ts);
  2677. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2678. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2679. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2680. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2681. }
  2682. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2683. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2684. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2685. }
  2686. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2687. {
  2688. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2689. if((access(filenmae,F_OK))!=-1)
  2690. {
  2691. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2692. sprintf(str,"rm -f %s",filenmae);
  2693. system(str);
  2694. }
  2695. }
  2696. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2697. #if 1 // for TempStopTransaction
  2698. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2699. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2700. {
  2701. checkTempStopTransaction(gun_index);
  2702. }
  2703. #endif
  2704. }
  2705. }
  2706. }
  2707. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2708. {
  2709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2710. {
  2711. tempIndex = ((gun_index==2) ? 1: 0);
  2712. }
  2713. else
  2714. {
  2715. tempIndex = gun_index;
  2716. }
  2717. for (int index = 0; index < GB_QUANTITY; index++)
  2718. {
  2719. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2720. {
  2721. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2722. {
  2723. // Sent unplug message for California pricing logic
  2724. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2725. {
  2726. uint8_t ts[20];
  2727. getNowDatetime(ts);
  2728. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2729. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2730. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2731. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2732. }
  2733. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2734. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2735. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2736. }
  2737. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2738. {
  2739. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2740. if((access(filenmae,F_OK))!=-1)
  2741. {
  2742. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2743. sprintf(str,"rm -f %s",filenmae);
  2744. system(str);
  2745. }
  2746. }
  2747. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2748. #if 1 // for TempStopTransaction
  2749. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2750. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2751. {
  2752. checkTempStopTransaction(gun_index);
  2753. }
  2754. #endif
  2755. }
  2756. }
  2757. }
  2758. else if(gunType[gun_index] == GUN_TYPE_DO)
  2759. {
  2760. tempIndex = gun_index;
  2761. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2762. {
  2763. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2764. {
  2765. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2766. {
  2767. // Sent unplug message for California pricing logic
  2768. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2769. {
  2770. uint8_t ts[20];
  2771. getNowDatetime(ts);
  2772. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2773. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2774. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2775. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2776. }
  2777. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2778. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2779. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2780. }
  2781. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2782. {
  2783. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2784. if((access(filenmae,F_OK))!=-1)
  2785. {
  2786. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2787. sprintf(str,"rm -f %s",filenmae);
  2788. system(str);
  2789. }
  2790. }
  2791. 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);
  2792. #if 1 // for TempStopTransaction
  2793. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2794. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2795. {
  2796. checkTempStopTransaction(gun_index);
  2797. }
  2798. #endif
  2799. }
  2800. }
  2801. }
  2802. else
  2803. {
  2804. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2805. {
  2806. tempIndex = 2;
  2807. }
  2808. else
  2809. {
  2810. tempIndex = gun_index;
  2811. }
  2812. for (int index = 0; index < AC_QUANTITY; index++)
  2813. {
  2814. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2815. {
  2816. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2817. {
  2818. // Sent unplug message for California pricing logic
  2819. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2820. {
  2821. uint8_t ts[20];
  2822. getNowDatetime(ts);
  2823. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  2824. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2825. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2826. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2827. }
  2828. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2829. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2830. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2831. }
  2832. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2833. {
  2834. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2835. if((access(filenmae,F_OK))!=-1)
  2836. {
  2837. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2838. sprintf(str,"rm -f %s",filenmae);
  2839. system(str);
  2840. }
  2841. }
  2842. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2843. #if 1 // for TempStopTransaction
  2844. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2845. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2846. {
  2847. checkTempStopTransaction(gun_index);
  2848. }
  2849. #endif
  2850. }
  2851. }// END
  2852. }
  2853. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  2854. (
  2855. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  2856. )
  2857. )
  2858. {
  2859. if(SystemInitial > 0)
  2860. SystemInitial -= 1;
  2861. sendStatusNotificationRequest(gun_index);
  2862. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2863. }
  2864. //==============================================
  2865. // CSU Trigger Smart Charging Profilw
  2866. //==============================================
  2867. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2868. {
  2869. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2870. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2871. }
  2872. //==============================================
  2873. // Meter report
  2874. //==============================================
  2875. // Trigger MeterValue
  2876. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2877. {
  2878. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2879. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2880. }
  2881. // ClockAlign MeterValue
  2882. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2883. {
  2884. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2885. {
  2886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2887. {
  2888. tempIndex = ((gun_index==2) ? 1: 0);
  2889. }
  2890. else
  2891. {
  2892. tempIndex = gun_index;
  2893. }
  2894. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2895. {
  2896. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2897. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2898. {
  2899. reqClockAlignMeter[gun_index] = 1;
  2900. }
  2901. }// End for CHAdeMO
  2902. }
  2903. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2904. {
  2905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2906. {
  2907. tempIndex = ((gun_index==2) ? 1: 0);
  2908. }
  2909. else
  2910. {
  2911. tempIndex = gun_index;
  2912. }
  2913. for (int index = 0; index < CCS_QUANTITY; index++)
  2914. {
  2915. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2916. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2917. {
  2918. reqClockAlignMeter[gun_index] = 1;
  2919. }
  2920. } // End for CCS
  2921. }
  2922. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2923. {
  2924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2925. {
  2926. tempIndex = ((gun_index==2) ? 1: 0);
  2927. }
  2928. else
  2929. {
  2930. tempIndex = gun_index;
  2931. }
  2932. for (int index = 0; index < GB_QUANTITY; index++)
  2933. {
  2934. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2935. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2936. {
  2937. reqClockAlignMeter[gun_index] = 1;
  2938. }
  2939. }// End for GB
  2940. }
  2941. else if(gunType[gun_index] == GUN_TYPE_DO)
  2942. {
  2943. tempIndex = gun_index;
  2944. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2945. {
  2946. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2947. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2948. {
  2949. reqClockAlignMeter[gun_index] = 1;
  2950. }
  2951. }
  2952. }
  2953. else
  2954. {
  2955. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2956. {
  2957. tempIndex = 2;
  2958. }
  2959. else
  2960. {
  2961. tempIndex = gun_index;
  2962. }
  2963. for (int index = 0; index < AC_QUANTITY; index++)
  2964. {
  2965. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2966. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2967. {
  2968. reqClockAlignMeter[gun_index] = 1;
  2969. }
  2970. }//End for AC
  2971. }
  2972. if(reqClockAlignMeter[gun_index] == 1)
  2973. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2974. }
  2975. // Sample period MeterValue
  2976. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  2977. {
  2978. //check Transaction active
  2979. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2980. {
  2981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2982. {
  2983. tempIndex = ((gun_index==2) ? 1: 0);
  2984. }
  2985. else
  2986. {
  2987. tempIndex = gun_index;
  2988. }
  2989. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2990. {
  2991. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2992. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2993. {
  2994. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2995. {
  2996. reqSampleMeter[gun_index] = 1;
  2997. }
  2998. }
  2999. }// End for CHAdeMO
  3000. }
  3001. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3002. {
  3003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3004. {
  3005. tempIndex = ((gun_index==2) ? 1: 0);
  3006. }
  3007. else
  3008. {
  3009. tempIndex = gun_index;
  3010. }
  3011. for (int index = 0; index < CCS_QUANTITY; index++)
  3012. {
  3013. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3014. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3015. {
  3016. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3017. {
  3018. reqSampleMeter[gun_index] = 1;
  3019. }
  3020. }
  3021. } // End for CCS
  3022. }
  3023. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3024. {
  3025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3026. {
  3027. tempIndex = ((gun_index==2) ? 1: 0);
  3028. }
  3029. else
  3030. {
  3031. tempIndex = gun_index;
  3032. }
  3033. for (int index = 0; index < GB_QUANTITY; index++)
  3034. {
  3035. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3036. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3037. {
  3038. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3039. {
  3040. reqSampleMeter[gun_index] = 1;
  3041. }
  3042. }
  3043. }// End for GB
  3044. }
  3045. else if(gunType[gun_index] == GUN_TYPE_DO)
  3046. {
  3047. tempIndex = gun_index;
  3048. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3049. {
  3050. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3051. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3052. {
  3053. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3054. {
  3055. reqSampleMeter[gun_index] = 1;
  3056. }
  3057. }
  3058. }
  3059. }
  3060. else
  3061. {
  3062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3063. {
  3064. tempIndex = 2;
  3065. }
  3066. else
  3067. {
  3068. tempIndex = gun_index;
  3069. }
  3070. for (int index = 0; index < AC_QUANTITY; index++)
  3071. {
  3072. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3073. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3074. {
  3075. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3076. {
  3077. reqSampleMeter[gun_index] = 1;
  3078. }
  3079. }
  3080. }//End for AC
  3081. }
  3082. if(reqSampleMeter[gun_index] == 1)
  3083. {
  3084. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3085. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3086. storeTempStopTransaction(gun_index);
  3087. }
  3088. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3089. }
  3090. //==============================================
  3091. // Check Connector reserved
  3092. //==============================================
  3093. //===============================
  3094. // Check if Reserve is expired
  3095. //===============================
  3096. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3097. {
  3098. double diff_t;
  3099. struct tm tp;
  3100. // current time
  3101. time_t t = time(NULL);
  3102. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3103. tp.tm_isdst = -1;
  3104. time_t utc = mktime(&tp);
  3105. diff_t = difftime(utc, t);
  3106. if(diff_t <= 0)
  3107. {
  3108. DEBUG_INFO("reserve expired.\n");
  3109. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3110. }
  3111. }//END OF Check if Reserve is expired
  3112. //==========================================
  3113. // csu trigger FirmwareStatusNotificationReq
  3114. //==========================================
  3115. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3116. {
  3117. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3118. }
  3119. //==========================================
  3120. // csu trigger DiagnosticsStatusNotificationReq
  3121. //==========================================
  3122. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3123. {
  3124. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3125. }
  3126. //==========================================
  3127. // csu trigger CancelReservationConf
  3128. //==========================================
  3129. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3130. {
  3131. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3132. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3133. }
  3134. //==========================================
  3135. // csu trigger ChangeAvailabilityConf
  3136. //==========================================
  3137. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3138. {
  3139. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3140. }
  3141. //==========================================
  3142. // csu trigger UnlockConnectorConf
  3143. //==========================================
  3144. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3145. {
  3146. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3147. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3148. }
  3149. //==========================================
  3150. // csu trigger ReserveNowConf
  3151. //==========================================
  3152. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3153. {
  3154. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3155. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3156. }
  3157. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3158. {
  3159. sendSignCertificateRequest();
  3160. }
  3161. }
  3162. }
  3163. //==========================================
  3164. // send request routine
  3165. //==========================================
  3166. int sendAuthorizeRequest(int gun_index)
  3167. {
  3168. mtrace();
  3169. int result = FAIL;
  3170. char message[100]={0};
  3171. char guid[37];
  3172. char tempdata[65]={0};
  3173. DEBUG_INFO("sendAuthorizeRequest...\n");
  3174. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3175. //Local Authorize
  3176. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3177. {
  3178. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3179. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3180. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3181. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3182. result = PASS;
  3183. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3184. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3185. authorizeRetryTimes = 0;
  3186. return result;
  3187. }
  3188. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  3189. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3190. {
  3191. // Query from cache
  3192. DEBUG_INFO("Authorize from cache.\n");
  3193. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3194. // Query from list
  3195. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3196. {
  3197. DEBUG_INFO("Authorize from list.\n");
  3198. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3199. }
  3200. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3201. {
  3202. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3203. {
  3204. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3205. }
  3206. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3207. {
  3208. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3209. }
  3210. if(!GetOcppConnStatus())
  3211. {
  3212. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3213. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3214. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3215. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3216. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3217. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3218. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3219. authorizeRetryTimes = 0;
  3220. return result;
  3221. }
  3222. }
  3223. else
  3224. {
  3225. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3226. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3227. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3228. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3229. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3230. else
  3231. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3232. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3233. result = PASS;
  3234. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3235. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3236. authorizeRetryTimes = 0;
  3237. return result;
  3238. }
  3239. }
  3240. //initialize struct Authorize
  3241. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3242. //get data from shared memory
  3243. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3244. random_uuid(guid);
  3245. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3246. LWS_Send(message);
  3247. sprintf(tempdata, "Authorize,%d", gun_index);
  3248. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3249. {
  3250. result = PASS;
  3251. DEBUG_INFO("Authorize mapItem pass\n");
  3252. }
  3253. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3254. return result;
  3255. }
  3256. int sendBootNotificationRequest(void)
  3257. {
  3258. mtrace();
  3259. int result = FAIL;
  3260. char message[500]={0}, payload[700]={0};
  3261. char guid[37]={0};
  3262. char tempdata[65]={0};
  3263. // Fill BootNotification fields
  3264. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3265. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3266. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3267. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3268. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3269. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3270. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3271. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3272. ShmOCPP16Data->ChargeBoxId
  3273. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3274. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3275. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3276. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3277. ,ShmOCPP16Data->BootNotification.CpIccid
  3278. ,ShmOCPP16Data->BootNotification.CpImsi);
  3279. random_uuid(guid);
  3280. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3281. LWS_Send(message);
  3282. sprintf(tempdata, "BootNotification,0");
  3283. 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*/)
  3284. {
  3285. result = PASS;
  3286. }
  3287. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3288. strcpy(queuedata,message);
  3289. return result;
  3290. }
  3291. int sendDataTransferRequest(int gun_index)
  3292. {
  3293. mtrace();
  3294. char message[1000]={0};
  3295. char guid[37]={0};
  3296. char tempdata[65]={0};
  3297. int result = FAIL;
  3298. random_uuid(guid);
  3299. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3300. MESSAGE_TYPE_CALL,
  3301. guid,
  3302. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3303. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3304. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3305. LWS_Send(message);
  3306. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3307. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3308. {
  3309. result = PASS;
  3310. DEBUG_INFO("DataTransfer mapItem pass\n");
  3311. }
  3312. return result;
  3313. }
  3314. int sendDiagnosticsStatusNotificationRequest(char *status)
  3315. {
  3316. mtrace();
  3317. int result = FAIL;
  3318. char message[110]={0};
  3319. char guid[37]={0};
  3320. char tempdata[65]={0};
  3321. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3322. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3323. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3324. random_uuid(guid);
  3325. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3326. LWS_SendNow(message);
  3327. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3328. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3329. {
  3330. result = PASS;
  3331. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3332. }
  3333. //#ifdef SystemLogMessage
  3334. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3335. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3336. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3337. //#endif
  3338. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3339. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3340. //record status
  3341. if(strcmp(status,"Idle")==0)
  3342. {
  3343. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3344. }
  3345. else if(strcmp(status,"Uploaded")==0)
  3346. {
  3347. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3348. }
  3349. else if(strcmp(status,"UploadFailed")==0)
  3350. {
  3351. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3352. }
  3353. else if(strcmp(status,"Uploading")==0)
  3354. {
  3355. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3356. }
  3357. return result;
  3358. }
  3359. int sendFirmwareStatusNotificationRequest(char *status)
  3360. {
  3361. mtrace();
  3362. int result = FAIL;
  3363. char message[110]={0};
  3364. char guid[37]={0};
  3365. char tempdata[65]={0};
  3366. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3367. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3368. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3369. random_uuid(guid);
  3370. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3371. LWS_SendNow(message);
  3372. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3373. 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*/)
  3374. {
  3375. result = PASS;
  3376. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3377. }
  3378. //#ifdef SystemLogMessage
  3379. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3380. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3381. //#endif
  3382. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3383. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3384. //record status
  3385. if(strcmp(status,"Downloaded")==0)
  3386. {
  3387. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3388. }
  3389. else if(strcmp(status,"DownloadFailed")==0)
  3390. {
  3391. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3392. }
  3393. else if(strcmp(status,"Downloading")==0)
  3394. {
  3395. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3396. }
  3397. else if(strcmp(status,"Idle")==0)
  3398. {
  3399. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3400. }
  3401. else if(strcmp(status,"InstallationFailed")==0)
  3402. {
  3403. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3404. }
  3405. else if(strcmp(status,"Installing")==0)
  3406. {
  3407. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3408. }
  3409. else if(strcmp(status,"Installed")==0)
  3410. {
  3411. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3412. }
  3413. return result;
  3414. }
  3415. int sendHeartbeatRequest(int gun_index)
  3416. {
  3417. mtrace();
  3418. int result = FAIL;
  3419. char message[80]={0};
  3420. char guid[37]={0};
  3421. char tempdata[65]={0};
  3422. random_uuid(guid);
  3423. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3424. , MESSAGE_TYPE_CALL
  3425. , guid );
  3426. LWS_Send(message);
  3427. sprintf(tempdata, "Heartbeat,%d", 0);
  3428. 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*/)
  3429. {
  3430. result = PASS;
  3431. }
  3432. return result;
  3433. }
  3434. int sendStartTransactionRequest(int gun_index)
  3435. {
  3436. mtrace();
  3437. int result = FAIL;
  3438. char message[250]={0};
  3439. char guid[37]={0};
  3440. struct timeval tmnow;
  3441. struct tm *tm;
  3442. char buf[28];//, usec_buf[6];
  3443. char tempdata[65]={0};
  3444. int tempIndex = 0;
  3445. DEBUG_INFO("sendStartTransactionRequest...\n");
  3446. gettimeofday(&tmnow, NULL);
  3447. time_t t;
  3448. t = time(NULL);
  3449. /*UTC time and date*/
  3450. tm = gmtime(&t);
  3451. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3452. #if 0 // remove temporally
  3453. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3454. strcat(buf,".");
  3455. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3456. strcat(buf,usec_buf);
  3457. #endif
  3458. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3459. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3460. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3461. // clear StartTransaction Response
  3462. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3463. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3464. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3465. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3466. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3467. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3468. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3469. {
  3470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3471. {
  3472. tempIndex = ((gun_index==2) ? 1: 0);
  3473. }
  3474. else
  3475. {
  3476. tempIndex = gun_index;
  3477. }
  3478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3479. {
  3480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3481. {
  3482. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3483. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3484. }
  3485. }
  3486. }
  3487. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3488. {
  3489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3490. {
  3491. tempIndex = ((gun_index==2) ? 1: 0);
  3492. }
  3493. else
  3494. {
  3495. tempIndex = gun_index;
  3496. }
  3497. for (int index = 0; index < CCS_QUANTITY; index++)
  3498. {
  3499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3500. {
  3501. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3502. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3503. }
  3504. }
  3505. }
  3506. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3509. {
  3510. tempIndex = ((gun_index==2) ? 1: 0);
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < GB_QUANTITY; index++)
  3517. {
  3518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3519. {
  3520. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3521. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3522. }
  3523. }
  3524. }
  3525. else if(gunType[gun_index] == GUN_TYPE_DO)
  3526. {
  3527. tempIndex = gun_index;
  3528. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3529. {
  3530. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3531. {
  3532. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3533. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3534. }
  3535. }
  3536. }
  3537. else
  3538. {
  3539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3540. {
  3541. tempIndex = 2;
  3542. }
  3543. else
  3544. {
  3545. tempIndex = gun_index;
  3546. }
  3547. for (int index = 0; index < AC_QUANTITY; index++)
  3548. {
  3549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3550. {
  3551. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3552. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3553. }
  3554. }
  3555. }
  3556. random_uuid(guid);
  3557. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3558. {
  3559. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3560. , gun_index +1
  3561. , MESSAGE_TYPE_CALL
  3562. , guid
  3563. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3564. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3565. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3566. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3567. }
  3568. else
  3569. {
  3570. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3571. , gun_index +1
  3572. , MESSAGE_TYPE_CALL
  3573. , guid
  3574. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3575. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3576. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3577. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3578. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3579. }
  3580. #if 1
  3581. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3582. 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*/)
  3583. {
  3584. result = PASS;
  3585. }
  3586. #endif
  3587. strcpy(queuedata, message);
  3588. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3589. OCPP_insert_transaction_msg(YES, queuedata);
  3590. return result;
  3591. }
  3592. int sendStatusNotificationRequest(int gun_index)
  3593. {
  3594. mtrace();
  3595. int result = FAIL;
  3596. char message[600]={0};
  3597. char guid[37];
  3598. int currentStatus = 0;
  3599. struct timeval tmnow;
  3600. struct tm *tm;
  3601. char buf[28];//, usec_buf[6];
  3602. char tempdata[65]={0};
  3603. int tempIndex = 0;
  3604. uint8_t isStateChanged = TRUE;
  3605. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3606. gettimeofday(&tmnow, NULL);
  3607. time_t t;
  3608. t = time(NULL);
  3609. /*UTC time and date*/
  3610. tm = gmtime(&t);
  3611. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3612. #if 0 // remove temporally
  3613. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3614. strcat(buf,".");
  3615. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3616. strcat(buf,usec_buf);
  3617. #endif
  3618. //printf("%s",buf);
  3619. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3620. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3621. // it's option
  3622. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3623. /*
  3624. enum _SYSTEM_STATUS
  3625. {
  3626. S_BOOTING = 0,
  3627. S_IDLE, = 1
  3628. S_AUTHORIZING, =2
  3629. S_REASSIGN_CHECK, =3
  3630. S_REASSIGN, =4
  3631. S_PRECHARGE, =5
  3632. S_PREPARING_FOR_EV, =6
  3633. S_PREPARING_FOR_EVSE, =7
  3634. S_CHARGING, =8
  3635. S_TERMINATING, =9
  3636. S_COMPLETE, =10
  3637. S_ALARM, =11
  3638. S_FAULT =12
  3639. }
  3640. */
  3641. //check Transaction active
  3642. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3643. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3644. {
  3645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3646. {
  3647. tempIndex = ((gun_index==2) ? 1: 0);
  3648. }
  3649. else
  3650. {
  3651. tempIndex = gun_index;
  3652. }
  3653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3654. {
  3655. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3656. {
  3657. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3658. {
  3659. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3660. {
  3661. currentStatus = Preparing; //OCPP Status: Preparing
  3662. }
  3663. else
  3664. {
  3665. currentStatus = Available; //OCPP Status: Available
  3666. }
  3667. }
  3668. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3669. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3670. ) //S_PRECHARGE
  3671. {
  3672. currentStatus = Preparing; //OCPP Status: Preparing
  3673. }
  3674. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3675. {
  3676. currentStatus = Charging; //OCPP Status: Charging
  3677. }
  3678. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3679. {
  3680. currentStatus = Finishing; //OCPP Status: Finishing
  3681. }
  3682. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3683. {
  3684. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3685. }
  3686. 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
  3687. {
  3688. currentStatus = Unavailable; //OCPP Status: Unavailable
  3689. }
  3690. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3691. {
  3692. currentStatus = Faulted; //OCPP Status: Faulted
  3693. }
  3694. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3695. {
  3696. currentStatus = Reserved; //OCPP Status: Reserved
  3697. }
  3698. } //end of the same index
  3699. }//end of for CHAdeMO_QUANTITY
  3700. }
  3701. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3702. {
  3703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3704. {
  3705. tempIndex = ((gun_index==2) ? 1: 0);
  3706. }
  3707. else
  3708. {
  3709. tempIndex = gun_index;
  3710. }
  3711. for (int index = 0; index < CCS_QUANTITY; index++)
  3712. {
  3713. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3714. {
  3715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3716. {
  3717. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3718. {
  3719. currentStatus = Preparing; //OCPP Status: Preparing
  3720. }
  3721. else
  3722. {
  3723. currentStatus = Available; //OCPP Status: Available
  3724. }
  3725. }
  3726. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3727. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3728. ) //S_PRECHARGE
  3729. {
  3730. currentStatus = Preparing; //OCPP Status: Preparing
  3731. }
  3732. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3733. {
  3734. currentStatus = Charging; //OCPP Status: Charging
  3735. }
  3736. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3737. {
  3738. currentStatus = Finishing; //OCPP Status: Finishing
  3739. }
  3740. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3741. {
  3742. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3743. }
  3744. 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
  3745. {
  3746. currentStatus = Unavailable; //OCPP Status : Unavailable
  3747. }
  3748. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3749. {
  3750. currentStatus = Faulted; //OCPP Status: Faulted
  3751. }
  3752. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3753. {
  3754. currentStatus = Reserved; //OCPP Status: Reserved
  3755. }
  3756. } //end of the same index
  3757. } // end of for CCS_QUANTITY
  3758. }
  3759. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3760. {
  3761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3762. {
  3763. tempIndex = ((gun_index==2) ? 1: 0);
  3764. }
  3765. else
  3766. {
  3767. tempIndex = gun_index;
  3768. }
  3769. for (int index = 0; index < GB_QUANTITY; index++)
  3770. {
  3771. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3772. {
  3773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3774. {
  3775. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3776. {
  3777. currentStatus = Preparing; //OCPP Status: Preparing
  3778. }
  3779. else
  3780. {
  3781. currentStatus = Available; //OCPP Status: Available
  3782. }
  3783. }
  3784. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3785. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3786. ) //S_PRECHARGE
  3787. {
  3788. currentStatus = Preparing; //OCPP Status: Preparing
  3789. }
  3790. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3791. {
  3792. currentStatus = Charging; //OCPP Status: Charging
  3793. }
  3794. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3795. {
  3796. currentStatus = Finishing; //OCPP Status: Finishing
  3797. }
  3798. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3799. {
  3800. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3801. }
  3802. 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
  3803. {
  3804. currentStatus = Unavailable; //OCPP Status: Unavailable
  3805. }
  3806. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3807. {
  3808. currentStatus = Faulted; //OCPP Status: Faulted
  3809. }
  3810. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3811. {
  3812. currentStatus = Reserved; //OCPP Status: Reserved
  3813. }
  3814. } //end of the same index
  3815. } // end of for GB_QUANTITY
  3816. }
  3817. else if(gunType[gun_index] == GUN_TYPE_DO)
  3818. {
  3819. tempIndex = gun_index;
  3820. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3821. {
  3822. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3823. {
  3824. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3825. {
  3826. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3827. {
  3828. currentStatus = Preparing; //OCPP Status: Preparing
  3829. }
  3830. else
  3831. {
  3832. currentStatus = Available; //OCPP Status: Available
  3833. }
  3834. }
  3835. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3836. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3837. ) //S_PRECHARGE
  3838. {
  3839. currentStatus = Preparing; //OCPP Status: Preparing
  3840. }
  3841. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3842. {
  3843. currentStatus = Charging; //OCPP Status: Charging
  3844. }
  3845. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3846. {
  3847. currentStatus = Finishing; //OCPP Status: Finishing
  3848. }
  3849. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3850. {
  3851. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3852. }
  3853. 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
  3854. {
  3855. currentStatus = Unavailable; //OCPP Status: Unavailable
  3856. }
  3857. 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
  3858. {
  3859. currentStatus = Faulted; //OCPP Status: Faulted
  3860. }
  3861. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3862. {
  3863. currentStatus = Reserved; //OCPP Status: Reserved
  3864. }
  3865. } //end of the same index
  3866. }
  3867. }
  3868. else
  3869. {
  3870. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3871. {
  3872. tempIndex = 2;
  3873. }
  3874. else
  3875. {
  3876. tempIndex = gun_index;
  3877. }
  3878. for (int index = 0; index < AC_QUANTITY; index++)
  3879. {
  3880. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3881. {
  3882. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3883. {
  3884. 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))
  3885. {
  3886. currentStatus = Preparing; //OCPP Status: Preparing
  3887. }
  3888. else
  3889. {
  3890. currentStatus = Available; //OCPP Status: Available
  3891. }
  3892. }
  3893. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3894. {
  3895. currentStatus = Preparing; //OCPP Status: Preparing
  3896. }
  3897. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3898. {
  3899. currentStatus = Charging; //OCPP Status: Charging
  3900. }
  3901. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3902. {
  3903. currentStatus = Finishing; //OCPP Status: Finishing
  3904. }
  3905. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3906. {
  3907. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3908. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3909. else
  3910. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3911. }
  3912. 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
  3913. {
  3914. currentStatus = Unavailable; //OCPP Status: Unavailable
  3915. }
  3916. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3917. {
  3918. currentStatus = Faulted; //OCPP Status: Faulted
  3919. }
  3920. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3921. {
  3922. currentStatus = Reserved; //OCPP Status: Reserved
  3923. }
  3924. }//end of the same index
  3925. }//end of for AC_QUANTITY
  3926. }
  3927. //it's option
  3928. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3929. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  3930. {
  3931. isStateChanged = FALSE;
  3932. }
  3933. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3934. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3935. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3936. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3937. random_uuid(guid);
  3938. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3939. , MESSAGE_TYPE_CALL
  3940. , guid
  3941. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3942. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3943. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3944. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3945. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3946. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3947. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3948. if((server_sign == TRUE) && isStateChanged)
  3949. {
  3950. LWS_Send(message);
  3951. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3952. 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*/)
  3953. {
  3954. //DEBUG_ERROR("statusNotification mapitem pass");
  3955. result = PASS;
  3956. }
  3957. }
  3958. else
  3959. {
  3960. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3961. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3962. result = PASS;
  3963. }
  3964. return result;
  3965. }
  3966. int sendStopTransactionRequest(int gun_index)
  3967. {
  3968. mtrace();
  3969. int result = FAIL;
  3970. //char message[1500]={0};
  3971. char guid[37]={0};
  3972. char tempdata[65]={0};
  3973. int tempIndex = 0;
  3974. char TempStopTransaction[256];
  3975. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3976. //int idx_sample=0;
  3977. DEBUG_INFO("sendStopTransactionRequest \n");
  3978. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3979. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3980. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3981. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3982. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3983. {
  3984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3985. {
  3986. tempIndex = ((gun_index==2) ? 1: 0);
  3987. }
  3988. else
  3989. {
  3990. tempIndex = gun_index;
  3991. }
  3992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3993. {
  3994. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3995. {
  3996. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3997. }
  3998. }// END OF CHAdeMO_QUANTITY
  3999. }
  4000. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4001. {
  4002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4003. {
  4004. tempIndex = ((gun_index==2) ? 1: 0);
  4005. }
  4006. else
  4007. {
  4008. tempIndex = gun_index;
  4009. }
  4010. for (int index = 0; index < CCS_QUANTITY; index++)
  4011. {
  4012. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4013. {
  4014. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4015. }
  4016. }// END OF CCS_QUANTITY
  4017. }
  4018. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4019. {
  4020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4021. {
  4022. tempIndex = ((gun_index==2) ? 1: 0);
  4023. }
  4024. else
  4025. {
  4026. tempIndex = gun_index;
  4027. }
  4028. for (int index = 0; index < GB_QUANTITY; index++)
  4029. {
  4030. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4031. {
  4032. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4033. }
  4034. }// END OF GB_QUANTITY
  4035. }
  4036. else if(gunType[gun_index] == GUN_TYPE_DO)
  4037. {
  4038. tempIndex = gun_index;
  4039. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4040. {
  4041. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4042. {
  4043. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4044. }
  4045. }// END OF GB_QUANTITY
  4046. }
  4047. else
  4048. {
  4049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4050. {
  4051. tempIndex = 2;
  4052. }
  4053. else
  4054. {
  4055. tempIndex = gun_index;
  4056. }
  4057. for (int index = 0; index < AC_QUANTITY; index++)
  4058. {
  4059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4060. {
  4061. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4062. }
  4063. }// END OF AC_QUANTITY
  4064. }
  4065. //====================================== Stop Transaction Time =====================================================
  4066. struct timeval tmnow;
  4067. struct tm *tm;
  4068. char buf[28];//, usec_buf[6];
  4069. gettimeofday(&tmnow, NULL);
  4070. time_t t;
  4071. t = time(NULL);
  4072. /*UTC time and date*/
  4073. tm = gmtime(&t);
  4074. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4076. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4077. random_uuid(guid);
  4078. /***********************************transactionData******************************************************/
  4079. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4081. //=================================
  4082. // Transaction_Begin
  4083. //=================================
  4084. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4085. {
  4086. //============================================ Energy.Active.Import.Interval ================================
  4087. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4091. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4092. 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))
  4093. {
  4094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4095. }
  4096. else
  4097. {
  4098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4099. }
  4100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4102. }
  4103. //=================================
  4104. // Transaction_End
  4105. //=================================
  4106. // ================================= Current.Import L1 ===============================================
  4107. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4108. {
  4109. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4110. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4111. {
  4112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4113. {
  4114. tempIndex = ((gun_index==2) ? 1: 0);
  4115. }
  4116. else
  4117. {
  4118. tempIndex = gun_index;
  4119. }
  4120. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4121. {
  4122. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4123. {
  4124. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4125. }
  4126. }// End of for CHAdeMO_QUANTITY
  4127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4128. }
  4129. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4130. {
  4131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4132. {
  4133. tempIndex = ((gun_index==2) ? 1: 0);
  4134. }
  4135. else
  4136. {
  4137. tempIndex = gun_index;
  4138. }
  4139. for (int index = 0; index < CCS_QUANTITY; index++)
  4140. {
  4141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4142. {
  4143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4144. }
  4145. }// End of for CCS_QUANTITY
  4146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4147. }
  4148. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4149. {
  4150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4151. {
  4152. tempIndex = ((gun_index==2) ? 1: 0);
  4153. }
  4154. else
  4155. {
  4156. tempIndex = gun_index;
  4157. }
  4158. for (int index = 0; index < GB_QUANTITY; index++)
  4159. {
  4160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4161. {
  4162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4163. }
  4164. }// End of for GB_QUANTITY
  4165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4166. }
  4167. else if(gunType[gun_index] == GUN_TYPE_DO)
  4168. {
  4169. tempIndex = gun_index;
  4170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4173. {
  4174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4175. }
  4176. }
  4177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4178. }
  4179. else
  4180. {
  4181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4182. {
  4183. tempIndex = 2;
  4184. }
  4185. else
  4186. {
  4187. tempIndex = gun_index;
  4188. }
  4189. for (int index = 0; index < AC_QUANTITY; index++)
  4190. {
  4191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4192. {
  4193. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4194. }
  4195. }// End of for AC_QUANTITY
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4197. }
  4198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4203. }
  4204. // ================================= Energy.Active.Import.Interval ==============================================
  4205. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4206. {
  4207. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4208. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4209. {
  4210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4211. {
  4212. tempIndex = ((gun_index==2) ? 1: 0);
  4213. }
  4214. else
  4215. {
  4216. tempIndex = gun_index;
  4217. }
  4218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4219. {
  4220. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4221. {
  4222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4223. }
  4224. }// END OF CHAdeMO_QUANTITY
  4225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4226. }
  4227. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4228. {
  4229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4230. {
  4231. tempIndex = ((gun_index==2) ? 1: 0);
  4232. }
  4233. else
  4234. {
  4235. tempIndex = gun_index;
  4236. }
  4237. for (int index = 0; index < CCS_QUANTITY; index++)
  4238. {
  4239. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4240. {
  4241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4242. }
  4243. }// END OF CCS_QUANTITY
  4244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4245. }
  4246. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4247. {
  4248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4249. {
  4250. tempIndex = ((gun_index==2) ? 1: 0);
  4251. }
  4252. else
  4253. {
  4254. tempIndex = gun_index;
  4255. }
  4256. for (int index = 0; index < GB_QUANTITY; index++)
  4257. {
  4258. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4259. {
  4260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4261. }
  4262. }// END OF GB_QUANTITY
  4263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4264. }
  4265. else if(gunType[gun_index] == GUN_TYPE_DO)
  4266. {
  4267. tempIndex = gun_index;
  4268. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4269. {
  4270. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4271. {
  4272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4273. }
  4274. }
  4275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4276. }
  4277. else
  4278. {
  4279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4280. {
  4281. tempIndex = 2;
  4282. }
  4283. else
  4284. {
  4285. tempIndex = gun_index;
  4286. }
  4287. for (int index = 0; index < AC_QUANTITY; index++)
  4288. {
  4289. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4290. {
  4291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4292. }
  4293. }// END OF AC_QUANTITY
  4294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4295. }
  4296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4301. }
  4302. //=================================== Power.Active.Import ==================================================
  4303. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4304. {
  4305. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4306. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4307. {
  4308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4309. {
  4310. tempIndex = ((gun_index==2) ? 1: 0);
  4311. }
  4312. else
  4313. {
  4314. tempIndex = gun_index;
  4315. }
  4316. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4317. {
  4318. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4319. {
  4320. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4321. }
  4322. } // End for CHAdeMO_QUANTITY
  4323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4324. }
  4325. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4326. {
  4327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4328. {
  4329. tempIndex = ((gun_index==2) ? 1: 0);
  4330. }
  4331. else
  4332. {
  4333. tempIndex = gun_index;
  4334. }
  4335. for (int index = 0; index < CCS_QUANTITY; index++)
  4336. {
  4337. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4338. {
  4339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4340. }
  4341. } // END for CCS_QUANTITY
  4342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4343. }
  4344. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4345. {
  4346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4347. {
  4348. tempIndex = ((gun_index==2) ? 1: 0);
  4349. }
  4350. else
  4351. {
  4352. tempIndex = gun_index;
  4353. }
  4354. for (int index = 0; index < GB_QUANTITY; index++)
  4355. {
  4356. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4357. {
  4358. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4359. }
  4360. }// END for GB_QUANTITY
  4361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4362. }
  4363. else if(gunType[gun_index] == GUN_TYPE_DO)
  4364. {
  4365. tempIndex = gun_index;
  4366. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4367. {
  4368. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4369. {
  4370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4371. }
  4372. }
  4373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4374. }
  4375. else
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4378. {
  4379. tempIndex = 2;
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < AC_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4388. {
  4389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4390. }
  4391. } // END for AC_QUANTITY
  4392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4393. }
  4394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4399. }
  4400. //============================ Voltage L1 ====================================
  4401. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4402. {
  4403. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4404. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4405. {
  4406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4407. {
  4408. tempIndex = ((gun_index==2) ? 1: 0);
  4409. }
  4410. else
  4411. {
  4412. tempIndex = gun_index;
  4413. }
  4414. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4415. {
  4416. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4417. {
  4418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4419. }
  4420. } // END OF FOR CHAdeMO_QUANTITY
  4421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4422. }
  4423. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4424. {
  4425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4426. {
  4427. tempIndex = ((gun_index==2) ? 1: 0);
  4428. }
  4429. else
  4430. {
  4431. tempIndex = gun_index;
  4432. }
  4433. for (int index = 0; index < CCS_QUANTITY; index++)
  4434. {
  4435. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4436. {
  4437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4438. }
  4439. } // END OF FOR CCS_QUANTITY
  4440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4441. }
  4442. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4443. {
  4444. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4445. {
  4446. tempIndex = ((gun_index==2) ? 1: 0);
  4447. }
  4448. else
  4449. {
  4450. tempIndex = gun_index;
  4451. }
  4452. for (int index = 0; index < GB_QUANTITY; index++)
  4453. {
  4454. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4455. {
  4456. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4457. }
  4458. } // END OF FOR GB_QUANTITY
  4459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4460. }
  4461. else if(gunType[gun_index] == GUN_TYPE_DO)
  4462. {
  4463. tempIndex = gun_index;
  4464. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4465. {
  4466. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4467. {
  4468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4469. }
  4470. }
  4471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4472. }
  4473. else
  4474. {
  4475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4476. {
  4477. tempIndex = 2;
  4478. }
  4479. else
  4480. {
  4481. tempIndex = gun_index;
  4482. }
  4483. for (int index = 0; index < AC_QUANTITY; index++)
  4484. {
  4485. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4486. {
  4487. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4488. }
  4489. } // END OF FOR AC_QUANTITY
  4490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4491. }
  4492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4497. }
  4498. //====================== End SoC ================================
  4499. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4500. {
  4501. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4502. 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))
  4503. {
  4504. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4505. {
  4506. tempIndex = ((gun_index==2) ? 1: 0);
  4507. }
  4508. else
  4509. {
  4510. tempIndex = gun_index;
  4511. }
  4512. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4513. {
  4514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4515. {
  4516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4517. {
  4518. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4519. }
  4520. }
  4521. }
  4522. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4523. {
  4524. for (int index = 0; index < CCS_QUANTITY; index++)
  4525. {
  4526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4527. {
  4528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4529. }
  4530. }
  4531. }
  4532. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4533. {
  4534. for (int index = 0; index < GB_QUANTITY; index++)
  4535. {
  4536. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4537. {
  4538. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4539. }
  4540. }
  4541. }
  4542. else if(gunType[gun_index] == GUN_TYPE_DO)
  4543. {
  4544. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4545. {
  4546. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4547. {
  4548. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4549. }
  4550. }
  4551. }
  4552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4558. } // END FOR DC CASE
  4559. }
  4560. // ================================= Current.Import L2 ===============================================
  4561. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4562. {
  4563. // AC 3 phse L2 current
  4564. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4565. {
  4566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4567. {
  4568. tempIndex = 2;
  4569. }
  4570. else
  4571. {
  4572. tempIndex = gun_index;
  4573. }
  4574. for (int index = 0; index < AC_QUANTITY; index++)
  4575. {
  4576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4577. {
  4578. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4579. }
  4580. }// End of for AC_QUANTITY
  4581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4582. }
  4583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4588. }
  4589. // ================================= Current.Import L3 ===============================================
  4590. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4591. {
  4592. // AC 3 phse L3 current
  4593. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4594. {
  4595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4596. {
  4597. tempIndex = 2;
  4598. }
  4599. else
  4600. {
  4601. tempIndex = gun_index;
  4602. }
  4603. for (int index = 0; index < AC_QUANTITY; index++)
  4604. {
  4605. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4606. {
  4607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4608. }
  4609. }// End of for AC_QUANTITY
  4610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4611. }
  4612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4617. }
  4618. //============================ Voltage L2 ====================================
  4619. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4620. {
  4621. // AC 3 phse L2 voltage
  4622. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4623. {
  4624. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4625. {
  4626. tempIndex = 2;
  4627. }
  4628. else
  4629. {
  4630. tempIndex = gun_index;
  4631. }
  4632. for (int index = 0; index < AC_QUANTITY; index++)
  4633. {
  4634. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4635. {
  4636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4637. }
  4638. } // END OF FOR AC_QUANTITY
  4639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4640. }
  4641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4646. }
  4647. //============================ Voltage L3 ====================================
  4648. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4649. {
  4650. // AC 3 phse L3 voltage
  4651. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4652. {
  4653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4654. {
  4655. tempIndex = 2;
  4656. }
  4657. else
  4658. {
  4659. tempIndex = gun_index;
  4660. }
  4661. for (int index = 0; index < AC_QUANTITY; index++)
  4662. {
  4663. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4664. {
  4665. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4666. }
  4667. } // END OF FOR AC_QUANTITY
  4668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4669. }
  4670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4675. }
  4676. //====================== Start SoC ================================
  4677. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4678. {
  4679. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4680. 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))
  4681. {
  4682. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4683. {
  4684. tempIndex = ((gun_index==2) ? 1: 0);
  4685. }
  4686. else
  4687. {
  4688. tempIndex = gun_index;
  4689. }
  4690. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4691. {
  4692. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4693. {
  4694. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4695. {
  4696. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4697. }
  4698. }
  4699. }
  4700. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4701. {
  4702. for (int index = 0; index < CCS_QUANTITY; index++)
  4703. {
  4704. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4705. {
  4706. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4707. }
  4708. }
  4709. }
  4710. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4711. {
  4712. for (int index = 0; index < GB_QUANTITY; index++)
  4713. {
  4714. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4715. {
  4716. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4717. }
  4718. }
  4719. }
  4720. else if(gunType[gun_index] == GUN_TYPE_DO)
  4721. {
  4722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4723. {
  4724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4725. {
  4726. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4727. }
  4728. }
  4729. }
  4730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4736. } // END FOR DC CASE
  4737. }
  4738. //================================================ Message create ====================================================
  4739. json_object *StopTransaction = json_object_new_object();
  4740. json_object *transactionDatas = json_object_new_array();
  4741. json_object *sampledValues = json_object_new_array();
  4742. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4743. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4744. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4745. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4746. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4747. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4748. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4749. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4750. {
  4751. json_object *transactionData = json_object_new_object();
  4752. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4753. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4754. {
  4755. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4756. {
  4757. json_object *sampledValue = json_object_new_object();
  4758. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4759. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4760. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4761. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4762. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4763. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4764. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4765. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4766. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4767. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4768. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4769. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4770. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4771. json_object_array_add(sampledValues, sampledValue);
  4772. }
  4773. }
  4774. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4775. json_object_array_add(transactionDatas, transactionData);
  4776. }
  4777. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4778. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4779. ,MESSAGE_TYPE_CALL
  4780. ,guid
  4781. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4782. json_object_put(StopTransaction);
  4783. #if 1 // for TempStopTransaction
  4784. //Delete TempStopTransaction
  4785. if((access(TempStopTransaction,F_OK))!=-1)
  4786. {
  4787. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4788. }
  4789. #endif
  4790. #if 1
  4791. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4792. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4793. {
  4794. result = PASS;
  4795. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4796. }
  4797. #endif
  4798. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4799. OCPP_insert_transaction_msg(NO, queuedata);
  4800. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4801. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4802. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4803. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4804. {
  4805. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4806. }
  4807. //for test
  4808. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4809. return result;
  4810. }
  4811. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4812. {
  4813. mtrace();
  4814. int result = FAIL;
  4815. char guid[37]={0};
  4816. char tempdata[65]={0};
  4817. int tempIndex = 0;
  4818. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4819. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4820. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4821. //set value
  4822. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4823. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4824. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4825. -1);
  4826. random_uuid(guid);
  4827. //UTC Date time
  4828. struct timeval tmnow;
  4829. struct tm *tm;
  4830. char buf[28];//, usec_buf[6];
  4831. gettimeofday(&tmnow, NULL);
  4832. time_t t;
  4833. t = time(NULL);
  4834. /*UTC time and date*/
  4835. tm = gmtime(&t);
  4836. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4838. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4839. //********************************(1)Current.Import L1************************************************/
  4840. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4841. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4842. (dataType == ReadingContext_Trigger))
  4843. {
  4844. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4845. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4846. {
  4847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4848. {
  4849. tempIndex = ((gun_index==2) ? 1: 0);
  4850. }
  4851. else
  4852. {
  4853. tempIndex = gun_index;
  4854. }
  4855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4856. {
  4857. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4858. {
  4859. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4860. }
  4861. }
  4862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4863. }
  4864. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4865. {
  4866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4867. {
  4868. tempIndex = ((gun_index==2) ? 1: 0);
  4869. }
  4870. else
  4871. {
  4872. tempIndex = gun_index;
  4873. }
  4874. for (int index = 0; index < CCS_QUANTITY; index++)
  4875. {
  4876. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4877. {
  4878. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4879. }
  4880. }
  4881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4882. }
  4883. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4886. {
  4887. tempIndex = ((gun_index==2) ? 1: 0);
  4888. }
  4889. else
  4890. {
  4891. tempIndex = gun_index;
  4892. }
  4893. for (int index = 0; index < GB_QUANTITY; index++)
  4894. {
  4895. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4896. {
  4897. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4898. }
  4899. }
  4900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4901. }
  4902. else if(gunType[gun_index] == GUN_TYPE_DO)
  4903. {
  4904. tempIndex = gun_index;
  4905. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4906. {
  4907. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4908. {
  4909. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4910. }
  4911. }
  4912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4913. }
  4914. else
  4915. {
  4916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4917. {
  4918. tempIndex = 2;
  4919. }
  4920. else
  4921. {
  4922. tempIndex = gun_index;
  4923. }
  4924. for (int index = 0; index < AC_QUANTITY; index++)
  4925. {
  4926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4927. {
  4928. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4929. }
  4930. }
  4931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4932. }
  4933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4938. }
  4939. //********************************(2)Energy.Active.Import.Register ************************************************/
  4940. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4941. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4942. (dataType == ReadingContext_Trigger))
  4943. {
  4944. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4945. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4946. {
  4947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4948. {
  4949. tempIndex = ((gun_index==2) ? 1: 0);
  4950. }
  4951. else
  4952. {
  4953. tempIndex = gun_index;
  4954. }
  4955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4956. {
  4957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4958. {
  4959. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4960. }
  4961. }
  4962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4963. }
  4964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  4975. {
  4976. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4977. {
  4978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4979. }
  4980. }
  4981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4982. }
  4983. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4984. {
  4985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4986. {
  4987. tempIndex = ((gun_index==2) ? 1: 0);
  4988. }
  4989. else
  4990. {
  4991. tempIndex = gun_index;
  4992. }
  4993. for (int index = 0; index < GB_QUANTITY; index++)
  4994. {
  4995. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4996. {
  4997. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4998. }
  4999. }
  5000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5001. }
  5002. else if(gunType[gun_index] == GUN_TYPE_DO)
  5003. {
  5004. tempIndex = gun_index;
  5005. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5006. {
  5007. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5008. {
  5009. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5010. }
  5011. }
  5012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5013. }
  5014. else
  5015. {
  5016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5017. {
  5018. tempIndex = 2;
  5019. }
  5020. else
  5021. {
  5022. tempIndex = gun_index;
  5023. }
  5024. for (int index = 0; index < AC_QUANTITY; index++)
  5025. {
  5026. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5027. {
  5028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5029. }
  5030. }
  5031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5032. }
  5033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5038. }
  5039. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5040. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5041. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5042. (dataType == ReadingContext_Trigger))
  5043. {
  5044. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5045. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5046. {
  5047. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5048. {
  5049. tempIndex = ((gun_index==2) ? 1: 0);
  5050. }
  5051. else
  5052. {
  5053. tempIndex = gun_index;
  5054. }
  5055. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5056. {
  5057. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5058. {
  5059. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5060. }
  5061. } // END OF FOR CHAdeMO_QUANTITY
  5062. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5063. }
  5064. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5065. {
  5066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5067. {
  5068. tempIndex = ((gun_index==2) ? 1: 0);
  5069. }
  5070. else
  5071. {
  5072. tempIndex = gun_index;
  5073. }
  5074. for (int index = 0; index < CCS_QUANTITY; index++)
  5075. {
  5076. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5077. {
  5078. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5079. }
  5080. } // END OF CCS_QUANTITY
  5081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5082. }
  5083. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5084. {
  5085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5086. {
  5087. tempIndex = ((gun_index==2) ? 1: 0);
  5088. }
  5089. else
  5090. {
  5091. tempIndex = gun_index;
  5092. }
  5093. for (int index = 0; index < GB_QUANTITY; index++)
  5094. {
  5095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5096. {
  5097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5098. }
  5099. } // END OF GB_QUANTITY
  5100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5101. }
  5102. else if(gunType[gun_index] == GUN_TYPE_DO)
  5103. {
  5104. tempIndex = gun_index;
  5105. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5106. {
  5107. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5108. {
  5109. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5110. }
  5111. }
  5112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5113. }
  5114. else
  5115. {
  5116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5117. {
  5118. tempIndex = 2;
  5119. }
  5120. else
  5121. {
  5122. tempIndex = gun_index;
  5123. }
  5124. for (int index = 0; index < AC_QUANTITY; index++)
  5125. {
  5126. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5127. {
  5128. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5129. }
  5130. }
  5131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5132. }
  5133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5138. }
  5139. //********************************(4)Power.Active.Import************************************************/
  5140. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5141. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5142. (dataType == ReadingContext_Trigger))
  5143. {
  5144. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5145. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5146. {
  5147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5148. {
  5149. tempIndex = ((gun_index==2) ? 1: 0);
  5150. }
  5151. else
  5152. {
  5153. tempIndex = gun_index;
  5154. }
  5155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5156. {
  5157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5158. {
  5159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5160. }
  5161. } // END OF FOR
  5162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5163. }
  5164. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5165. {
  5166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5167. {
  5168. tempIndex = ((gun_index==2) ? 1: 0);
  5169. }
  5170. else
  5171. {
  5172. tempIndex = gun_index;
  5173. }
  5174. for (int index = 0; index < CCS_QUANTITY; index++)
  5175. {
  5176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5177. {
  5178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5179. }
  5180. }
  5181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5182. }
  5183. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5184. {
  5185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5186. {
  5187. tempIndex = ((gun_index==2) ? 1: 0);
  5188. }
  5189. else
  5190. {
  5191. tempIndex = gun_index;
  5192. }
  5193. for (int index = 0; index < GB_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5196. {
  5197. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5198. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5199. }
  5200. }
  5201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5202. }
  5203. else if(gunType[gun_index] == GUN_TYPE_DO)
  5204. {
  5205. tempIndex = gun_index;
  5206. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5207. {
  5208. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5209. {
  5210. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5211. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5212. }
  5213. }
  5214. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5215. }
  5216. else
  5217. {
  5218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5219. {
  5220. tempIndex = 2;
  5221. }
  5222. else
  5223. {
  5224. tempIndex = gun_index;
  5225. }
  5226. for (int index = 0; index < AC_QUANTITY; index++)
  5227. {
  5228. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5229. {
  5230. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5231. }
  5232. }
  5233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5234. }
  5235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5240. }
  5241. //***********************************************(5)VOLTAGE L1******************************************************/
  5242. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5243. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5244. (dataType == ReadingContext_Trigger))
  5245. {
  5246. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5247. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5248. {
  5249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5250. {
  5251. tempIndex = ((gun_index==2) ? 1: 0);
  5252. }
  5253. else
  5254. {
  5255. tempIndex = gun_index;
  5256. }
  5257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5258. {
  5259. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5260. {
  5261. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5262. }
  5263. }
  5264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5265. }
  5266. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5267. {
  5268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5269. {
  5270. tempIndex = ((gun_index==2) ? 1: 0);
  5271. }
  5272. else
  5273. {
  5274. tempIndex = gun_index;
  5275. }
  5276. for (int index = 0; index < CCS_QUANTITY; index++)
  5277. {
  5278. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5279. {
  5280. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5281. }
  5282. }
  5283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5284. }
  5285. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5286. {
  5287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5288. {
  5289. tempIndex = ((gun_index==2) ? 1: 0);
  5290. }
  5291. else
  5292. {
  5293. tempIndex = gun_index;
  5294. }
  5295. for (int index = 0; index < GB_QUANTITY; index++)
  5296. {
  5297. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5298. {
  5299. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5300. }
  5301. }
  5302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5303. }
  5304. else if(gunType[gun_index] == GUN_TYPE_DO)
  5305. {
  5306. tempIndex = gun_index;
  5307. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5308. {
  5309. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5310. {
  5311. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5312. }
  5313. }
  5314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5315. }
  5316. else
  5317. {
  5318. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5319. {
  5320. tempIndex = 2;
  5321. }
  5322. else
  5323. {
  5324. tempIndex = gun_index;
  5325. }
  5326. for (int index = 0; index < AC_QUANTITY; index++)
  5327. {
  5328. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5329. {
  5330. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5331. }
  5332. }
  5333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5334. }
  5335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5340. }
  5341. //***********************************************(6)SOC******************************************************/
  5342. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5343. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5344. (dataType == ReadingContext_Trigger))
  5345. {
  5346. 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))
  5347. {
  5348. //idx_sample=5;
  5349. //sampledValue = NULL;
  5350. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5351. {
  5352. tempIndex = ((gun_index==2) ? 1: 0);
  5353. }
  5354. else
  5355. {
  5356. tempIndex = gun_index;
  5357. }
  5358. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5359. {
  5360. //tempIndex = ((gun_index==2) ? 1: 0);
  5361. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5362. {
  5363. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5364. {
  5365. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5366. }
  5367. }
  5368. }
  5369. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5370. {
  5371. //tempIndex = ((gun_index==2) ? 1: 0);
  5372. for (int index = 0; index < CCS_QUANTITY; index++)
  5373. {
  5374. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5375. {
  5376. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5377. }
  5378. }
  5379. }
  5380. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5381. {
  5382. //tempIndex = ((gun_index==2) ? 1: 0);
  5383. for (int index = 0; index < GB_QUANTITY; index++)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5386. {
  5387. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5388. }
  5389. }
  5390. }
  5391. else if(gunType[gun_index] == GUN_TYPE_DO)
  5392. {
  5393. //tempIndex = ((gun_index==2) ? 1: 0);
  5394. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5395. {
  5396. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5397. {
  5398. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5399. }
  5400. }
  5401. }
  5402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5408. }
  5409. }
  5410. //********************************(7)Current.Import L2************************************************/
  5411. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5412. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5413. (dataType == ReadingContext_Trigger))
  5414. {
  5415. // Only for AC 3 phase
  5416. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5417. {
  5418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5419. {
  5420. tempIndex = 2;
  5421. }
  5422. else
  5423. {
  5424. tempIndex = gun_index;
  5425. }
  5426. for (int index = 0; index < AC_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5429. {
  5430. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5431. }
  5432. }
  5433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5434. }
  5435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5437. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5440. }
  5441. //********************************(8)Current.Import L3************************************************/
  5442. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5443. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5444. (dataType == ReadingContext_Trigger))
  5445. {
  5446. // Only for AC 3 phase
  5447. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5448. {
  5449. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5450. {
  5451. tempIndex = 2;
  5452. }
  5453. else
  5454. {
  5455. tempIndex = gun_index;
  5456. }
  5457. for (int index = 0; index < AC_QUANTITY; index++)
  5458. {
  5459. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5460. {
  5461. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5462. }
  5463. }
  5464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5465. }
  5466. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5468. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5471. }
  5472. //***********************************************(9)VOLTAGE L2******************************************************/
  5473. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5474. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5475. (dataType == ReadingContext_Trigger))
  5476. {
  5477. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5478. {
  5479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5480. {
  5481. tempIndex = 2;
  5482. }
  5483. else
  5484. {
  5485. tempIndex = gun_index;
  5486. }
  5487. for (int index = 0; index < AC_QUANTITY; index++)
  5488. {
  5489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5490. {
  5491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5492. }
  5493. }
  5494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5495. }
  5496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5501. }
  5502. //***********************************************(10)VOLTAGE L3******************************************************/
  5503. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5504. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5505. (dataType == ReadingContext_Trigger))
  5506. {
  5507. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5508. {
  5509. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5510. {
  5511. tempIndex = 2;
  5512. }
  5513. else
  5514. {
  5515. tempIndex = gun_index;
  5516. }
  5517. for (int index = 0; index < AC_QUANTITY; index++)
  5518. {
  5519. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5520. {
  5521. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5522. }
  5523. }
  5524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5525. }
  5526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5531. }
  5532. // Message create ====================================================================================================
  5533. if(TRUE)
  5534. {
  5535. json_object *MeterValueReq = json_object_new_object();
  5536. json_object *MeterValues = json_object_new_array();
  5537. json_object *sampledValues = json_object_new_array();
  5538. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5539. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5540. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5541. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5542. {
  5543. json_object *MeterValue = json_object_new_object();
  5544. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5545. {
  5546. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5547. {
  5548. json_object *sampledValue = json_object_new_object();
  5549. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5550. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5551. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5552. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5553. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5554. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5555. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5556. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5557. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5558. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5559. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5560. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5561. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5562. json_object_array_add(sampledValues, sampledValue);
  5563. }
  5564. }
  5565. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5566. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5567. json_object_array_add(MeterValues, MeterValue);
  5568. }
  5569. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5570. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5571. ,gun_index + 1
  5572. ,MESSAGE_TYPE_CALL
  5573. ,guid
  5574. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5575. json_object_put(MeterValueReq);
  5576. }
  5577. // Put request guid to hash map
  5578. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5579. 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*/)
  5580. {
  5581. result = PASS;
  5582. //DEBUG_INFO("MeterValues mapitem pass\n");
  5583. }
  5584. if((dataType != ReadingContext_Trigger) &&
  5585. (dataType != ReadingContext_Sample_Clock) &&
  5586. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5587. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5588. else
  5589. {
  5590. if(FirstHeartBeat)
  5591. LWS_Send(queuedata +2);
  5592. }
  5593. return result;
  5594. }
  5595. int sendLogStatusNotificationRequest(char *status)
  5596. {
  5597. mtrace();
  5598. int result = PASS;
  5599. char message[4096]={0};
  5600. char guid[37]={0};
  5601. char tempdata[128]={0};
  5602. json_object *LogStatusNotification = json_object_new_object();
  5603. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5604. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5605. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5606. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5607. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5608. random_uuid(guid);
  5609. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5610. json_object_put(LogStatusNotification);
  5611. LWS_Send(message);
  5612. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5613. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5614. {
  5615. result = PASS;
  5616. }
  5617. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5618. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5619. return result;
  5620. }
  5621. int sendSecurityEventNotificationRequest()
  5622. {
  5623. mtrace();
  5624. int result = PASS;
  5625. char message[4096]={0};
  5626. char guid[37]={0};
  5627. char tempdata[128]={0};
  5628. json_object *SecurityEventNotification = json_object_new_object();
  5629. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5630. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5631. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5632. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5633. random_uuid(guid);
  5634. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5635. json_object_put(SecurityEventNotification);
  5636. LWS_Send(message);
  5637. sprintf(tempdata, "SecurityEventNotification,0");
  5638. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5639. {
  5640. result = PASS;
  5641. }
  5642. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5643. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5644. return result;
  5645. }
  5646. int sendSignCertificateRequest()
  5647. {
  5648. mtrace();
  5649. int result = PASS;
  5650. char message[4096]={0};
  5651. char guid[37]={0};
  5652. char tempdata[128]={0};
  5653. json_object *SignCertificate = json_object_new_object();
  5654. DEBUG_INFO("sendSignCertificateRequest...\n");
  5655. // Read csr file content
  5656. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5657. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5658. char *line = NULL;
  5659. size_t len = 0;
  5660. while(getline(&line, &len, fp) != -1)
  5661. {
  5662. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5663. {
  5664. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5665. }
  5666. }
  5667. fclose(fp);
  5668. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5669. random_uuid(guid);
  5670. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5671. json_object_put(SignCertificate);
  5672. LWS_Send(message);
  5673. sprintf(tempdata, "SignCertificate,0");
  5674. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5675. {
  5676. result = PASS;
  5677. }
  5678. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5679. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5680. return result;
  5681. }
  5682. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5683. {
  5684. mtrace();
  5685. int result = PASS;
  5686. char message[110]={0};
  5687. char guid[37]={0};
  5688. char tempdata[65]={0};
  5689. json_object *FirmwareStatusNotification = json_object_new_object();
  5690. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5691. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5692. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5693. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5694. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5695. random_uuid(guid);
  5696. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5697. json_object_put(FirmwareStatusNotification);
  5698. LWS_Send(message);
  5699. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5700. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5701. {
  5702. result = PASS;
  5703. }
  5704. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5705. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5706. return result;
  5707. }
  5708. //==========================================
  5709. // send confirm routine
  5710. //==========================================
  5711. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5712. {
  5713. mtrace();
  5714. int result = FAIL;
  5715. char message[100]={0};
  5716. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5717. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5718. LWS_Send(message);
  5719. result = TRUE;
  5720. return result;
  5721. }
  5722. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5723. {
  5724. mtrace();
  5725. int result = FAIL;
  5726. char message[100]={0};
  5727. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5728. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5729. LWS_Send(message);
  5730. result = TRUE;
  5731. return result;
  5732. }
  5733. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5734. {
  5735. mtrace();
  5736. int result = FAIL;
  5737. char message[100]={0};
  5738. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5739. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5740. LWS_Send(message);
  5741. result = TRUE;
  5742. return result;
  5743. }
  5744. int sendClearCacheConfirmation(char *uuid,char *payload)
  5745. {
  5746. mtrace();
  5747. int result = FAIL;
  5748. char message[500]={0};
  5749. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5750. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5751. LWS_Send(message);
  5752. return result;
  5753. }
  5754. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5755. {
  5756. mtrace();
  5757. int result = FAIL;
  5758. char message[500]={0};
  5759. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5760. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5761. LWS_Send(message);
  5762. return result;
  5763. }
  5764. int sendDataTransferConfirmation(char *uuid,char *payload)
  5765. {
  5766. mtrace();
  5767. char statusStr[20]={0};
  5768. char dataStr[10]={0};
  5769. char sstr[20]={0};
  5770. int c = 0;
  5771. char *loc;
  5772. int result = FAIL;
  5773. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5774. /**********************status**************************/
  5775. loc = strstr(payload, "status");
  5776. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5777. c = 0;
  5778. while (loc[3+strlen("status")+c] != '\"')
  5779. {
  5780. sstr[c] = loc[3+strlen("status")+c];
  5781. c++;
  5782. }
  5783. sstr[c] = '\0';
  5784. strcpy(statusStr, sstr);
  5785. /**********************data**************************/
  5786. loc = strstr(payload, "data");
  5787. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5788. c = 0;
  5789. while (loc[3+strlen("data")+c] != '\"')
  5790. {
  5791. sstr[c] = loc[3+strlen("data")+c];
  5792. c++;
  5793. }
  5794. sstr[c] = '\0';
  5795. strcpy(dataStr, sstr);
  5796. return result;
  5797. }
  5798. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5799. {
  5800. mtrace();
  5801. int result = FAIL;
  5802. char message[1000]={0};
  5803. int CompositeScheduleIndex = 0;
  5804. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5805. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5806. if(nPeriod == 0)
  5807. {
  5808. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5809. {
  5810. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5811. ,MESSAGE_TYPE_CALLRESULT
  5812. ,uuid
  5813. ,payload
  5814. ,connectorIdInt);
  5815. }
  5816. else
  5817. {
  5818. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5819. ,MESSAGE_TYPE_CALLRESULT
  5820. ,uuid
  5821. ,payload
  5822. ,connectorIdInt
  5823. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5824. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5825. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5826. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5827. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5828. }
  5829. }
  5830. else
  5831. {
  5832. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5833. ,MESSAGE_TYPE_CALLRESULT
  5834. ,uuid
  5835. ,payload
  5836. ,connectorIdInt
  5837. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5838. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5839. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5840. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5841. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5842. {
  5843. if (idx_sample == 0)
  5844. {
  5845. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5846. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5847. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5848. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5849. }
  5850. else
  5851. {
  5852. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5853. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5854. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5855. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5856. }
  5857. }
  5858. sprintf(message + strlen(message), "]}}]");
  5859. }
  5860. LWS_Send(message);
  5861. result = TRUE;
  5862. return result;
  5863. }
  5864. int sendGetConfigurationConfirmation(char *uuid)
  5865. {
  5866. mtrace();
  5867. int result = FAIL;
  5868. int MaxKeySupported = 0;
  5869. int sentConfigurationNumber= 0;
  5870. int sentunConfigurationNumber= 0;
  5871. char message[4000]={0};
  5872. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5873. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5874. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5875. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5876. ,MESSAGE_TYPE_CALLRESULT
  5877. ,uuid );
  5878. //configuration key
  5879. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5880. {
  5881. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5882. {
  5883. if (sentConfigurationNumber == 0)
  5884. {
  5885. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5886. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5887. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5888. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5889. }
  5890. else
  5891. {
  5892. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5893. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5894. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5895. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5896. }
  5897. sentConfigurationNumber = sentConfigurationNumber + 1;
  5898. }
  5899. }
  5900. sprintf(message + strlen(message), "]");
  5901. if(UnknownKeynum != 0)
  5902. {
  5903. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5904. //unkown key
  5905. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5906. {
  5907. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5908. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5909. if(sentunConfigurationNumber == 0)
  5910. {
  5911. sprintf(message + strlen(message), "\"%s\""
  5912. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5913. }
  5914. else
  5915. {
  5916. sprintf(message + strlen(message), ",\"%s\""
  5917. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5918. }
  5919. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5920. }
  5921. sprintf(message + strlen(message), "]");
  5922. }
  5923. sprintf(message + strlen(message), "}]");
  5924. LWS_Send(message);
  5925. return result;
  5926. }
  5927. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5928. {
  5929. mtrace();
  5930. int result = FAIL;
  5931. char message[400]={0};
  5932. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5933. if(strcmp(payload,"")==0)
  5934. {
  5935. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5936. }
  5937. else
  5938. {
  5939. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5940. }
  5941. LWS_Send(message);
  5942. result = TRUE;
  5943. return result;
  5944. }
  5945. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5946. {
  5947. mtrace();
  5948. int result = FAIL;
  5949. char message[80]={0};
  5950. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5951. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5952. LWS_Send(message);
  5953. result = TRUE;
  5954. return result;
  5955. }
  5956. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5957. {
  5958. mtrace();
  5959. int result = FAIL;
  5960. char message[80]={0};
  5961. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5962. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5963. LWS_Send(message);
  5964. result = TRUE;
  5965. return result;
  5966. }
  5967. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5968. {
  5969. mtrace();
  5970. int result = FAIL;
  5971. char message[80]={0};
  5972. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5973. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5974. LWS_Send(message);
  5975. result = TRUE;
  5976. return result;
  5977. }
  5978. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5979. {
  5980. mtrace();
  5981. int result = FAIL;
  5982. char message[80]={0};
  5983. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5984. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5985. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5986. LWS_Send(message);
  5987. result = TRUE;
  5988. return result;
  5989. }
  5990. int sendResetConfirmation(char *uuid,char *payload)
  5991. {
  5992. mtrace();
  5993. int result = FAIL;
  5994. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5995. char message[80]={0};
  5996. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5997. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5998. LWS_Send(message);
  5999. result = TRUE;
  6000. return result;
  6001. }
  6002. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6003. {
  6004. mtrace();
  6005. int result = FAIL;
  6006. char message[500]={0};
  6007. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6008. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6009. LWS_Send(message);
  6010. result = TRUE;
  6011. return result;
  6012. }
  6013. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6014. {
  6015. mtrace();
  6016. int result = FAIL;
  6017. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6018. char message[80]={0};
  6019. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6020. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6021. LWS_Send(message);
  6022. result = TRUE;
  6023. return result;
  6024. }
  6025. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6026. {
  6027. mtrace();
  6028. int result = FAIL;
  6029. char message[80]={0};
  6030. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6031. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6032. LWS_Send(message);
  6033. result = TRUE;
  6034. return result;
  6035. }
  6036. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6037. {
  6038. mtrace();
  6039. int result = FAIL;
  6040. char message[80]={0};
  6041. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6042. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6043. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6044. LWS_Send(message);
  6045. result = TRUE;
  6046. return result;
  6047. }
  6048. int sendUpdateFirmwareConfirmation(char *uuid)
  6049. {
  6050. mtrace();
  6051. int result = FAIL;
  6052. char message[60]={0};
  6053. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6054. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6055. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6056. LWS_Send(message);
  6057. result = TRUE;
  6058. return result;
  6059. }
  6060. int sendCertificateSignedConfirmation(char *uuid)
  6061. {
  6062. mtrace();
  6063. int result = PASS;
  6064. char message[4096]={0};
  6065. json_object *CertificateSigned = json_object_new_object();
  6066. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6067. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6068. sprintf(message,"[%d,\"%s\",%s]"
  6069. ,MESSAGE_TYPE_CALLRESULT
  6070. ,uuid
  6071. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6072. json_object_put(CertificateSigned);
  6073. LWS_Send(message);
  6074. return result;
  6075. }
  6076. int sendDeleteCertificateConfirmation(char *uuid)
  6077. {
  6078. mtrace();
  6079. int result = PASS;
  6080. char message[4096]={0};
  6081. json_object *DeleteCertificate = json_object_new_object();
  6082. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6083. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6084. sprintf(message,"[%d,\"%s\",%s]"
  6085. ,MESSAGE_TYPE_CALLRESULT
  6086. ,uuid
  6087. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6088. json_object_put(DeleteCertificate);
  6089. LWS_Send(message);
  6090. return result;
  6091. }
  6092. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6093. {
  6094. mtrace();
  6095. int result = PASS;
  6096. char message[4096]={0};
  6097. json_object *ExtendedTriggerMessage = json_object_new_object();
  6098. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6099. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6100. sprintf(message,"[%d,\"%s\",%s]"
  6101. ,MESSAGE_TYPE_CALLRESULT
  6102. ,uuid
  6103. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6104. json_object_put(ExtendedTriggerMessage);
  6105. LWS_Send(message);
  6106. return result;
  6107. }
  6108. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6109. {
  6110. mtrace();
  6111. int result = PASS;
  6112. char message[4096]={0};
  6113. json_object *GetInstalledCertificateIds = json_object_new_object();
  6114. json_object *certificateHashDataDatas = json_object_new_array();
  6115. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6116. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6117. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6118. {
  6119. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6120. {
  6121. json_object *certificateHashData = json_object_new_object();
  6122. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6123. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6124. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6125. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6126. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6127. }
  6128. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6129. }
  6130. else
  6131. {
  6132. json_object_put(certificateHashDataDatas);
  6133. }
  6134. sprintf(message,"[%d,\"%s\",%s]"
  6135. ,MESSAGE_TYPE_CALLRESULT
  6136. ,uuid
  6137. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6138. json_object_put(GetInstalledCertificateIds);
  6139. LWS_Send(message);
  6140. return result;
  6141. }
  6142. int sendGetLogConfirmation(char *uuid)
  6143. {
  6144. mtrace();
  6145. int result = PASS;
  6146. char message[4096]={0};
  6147. json_object *GetLog = json_object_new_object();
  6148. DEBUG_INFO("sendGetLogConfirmation...\n");
  6149. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6150. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6151. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6152. sprintf(message,"[%d,\"%s\",%s]"
  6153. ,MESSAGE_TYPE_CALLRESULT
  6154. ,uuid
  6155. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6156. json_object_put(GetLog);
  6157. LWS_Send(message);
  6158. return result;
  6159. }
  6160. int sendInstallCertificateConfirmation(char *uuid)
  6161. {
  6162. mtrace();
  6163. int result = PASS;
  6164. char message[4096]={0};
  6165. json_object *InstallCertificate = json_object_new_object();
  6166. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6167. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6168. sprintf(message,"[%d,\"%s\",%s]"
  6169. ,MESSAGE_TYPE_CALLRESULT
  6170. ,uuid
  6171. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6172. json_object_put(InstallCertificate);
  6173. LWS_Send(message);
  6174. return result;
  6175. }
  6176. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6177. {
  6178. mtrace();
  6179. int result = PASS;
  6180. char message[4096]={0};
  6181. json_object *SignedUpdateFirmware = json_object_new_object();
  6182. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6183. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6184. sprintf(message,"[%d,\"%s\",%s]"
  6185. ,MESSAGE_TYPE_CALLRESULT
  6186. ,uuid
  6187. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6188. json_object_put(SignedUpdateFirmware);
  6189. LWS_Send(message);
  6190. return result;
  6191. }
  6192. int sendUnknownConfirmation(char *uuid)
  6193. {
  6194. mtrace();
  6195. int result = PASS;
  6196. char message[256]={0};
  6197. DEBUG_INFO("sendUnknownConfirmation...\n");
  6198. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6199. LWS_Send(message);
  6200. return result;
  6201. }
  6202. //==========================================
  6203. // Handle server request routine Start
  6204. //==========================================
  6205. int handleCancelReservationRequest(char *uuid, char *payload)
  6206. {
  6207. mtrace();
  6208. int result = FAIL;
  6209. int gunNO = 0;
  6210. int reservationIdInt = -1;
  6211. char comfirmstr[20];
  6212. DEBUG_INFO("handleCancelReservationRequest...\n");
  6213. json_object *CancelReservation;
  6214. CancelReservation = json_tokener_parse(payload);
  6215. if(!is_error(CancelReservation))
  6216. {
  6217. // Required data
  6218. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6219. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6220. }
  6221. json_object_put(CancelReservation);
  6222. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6223. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6224. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6225. if(reservationIdInt != -1)
  6226. {
  6227. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6228. //check Transaction active
  6229. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6230. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6231. {
  6232. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6233. {
  6234. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6235. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6236. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6237. {
  6238. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6239. }
  6240. else
  6241. {
  6242. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6243. }
  6244. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6245. goto end;
  6246. }
  6247. }
  6248. for (int index = 0; index < CCS_QUANTITY; index++)
  6249. {
  6250. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6251. {
  6252. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6253. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6254. if(gunType[2] == GUN_TYPE_CCS)
  6255. {
  6256. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6257. }
  6258. else
  6259. {
  6260. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6261. }
  6262. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6263. goto end;
  6264. }
  6265. }
  6266. for (int index = 0; index < GB_QUANTITY; index++)
  6267. {
  6268. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6269. {
  6270. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6271. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6272. if(gunType[2] == GUN_TYPE_GBT)
  6273. {
  6274. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6275. }
  6276. else
  6277. {
  6278. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6279. }
  6280. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6281. goto end;
  6282. }
  6283. }
  6284. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6285. {
  6286. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6287. {
  6288. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6289. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6290. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6291. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6292. goto end;
  6293. }
  6294. }
  6295. for (int index = 0; index < AC_QUANTITY; index++)
  6296. {
  6297. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6298. {
  6299. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6300. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6302. {
  6303. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6304. }
  6305. else
  6306. {
  6307. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6308. }
  6309. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6310. goto end;
  6311. }
  6312. }
  6313. }
  6314. //The reservationId does NOT match the reservationId
  6315. sendCancelReservationConfirmation(uuid, comfirmstr);
  6316. end:
  6317. // Fill in ocpp packet uuid
  6318. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6319. return result;
  6320. }
  6321. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6322. {
  6323. mtrace();
  6324. int result = FAIL;
  6325. int gunIndex = 0;
  6326. char typeStr[16]={0};
  6327. char comfirmstr[20];
  6328. int specificId = FALSE;
  6329. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6330. json_object *ChangeAvailability;
  6331. ChangeAvailability = json_tokener_parse(payload);
  6332. if(!is_error(ChangeAvailability))
  6333. {
  6334. // Required data
  6335. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6336. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6337. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6338. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6339. }
  6340. json_object_put(ChangeAvailability);
  6341. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6342. {
  6343. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6344. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6345. }
  6346. else if(gunIndex == 0)
  6347. {
  6348. for(int i=0; i < gunTotalNumber; i++)
  6349. {
  6350. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6351. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6352. }
  6353. }
  6354. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6356. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6357. {
  6358. specificId = TRUE;
  6359. }
  6360. if(specificId == FALSE)
  6361. goto end;
  6362. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6363. {
  6364. //----------------------gunIndex is 0 ------------------------------------------------//
  6365. if(gunIndex == 0)
  6366. {
  6367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6368. {
  6369. for(int i=0; i < gunTotalNumber; i++)
  6370. {
  6371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6372. {
  6373. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6374. {
  6375. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6376. {
  6377. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6378. goto end;
  6379. }
  6380. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6381. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6382. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6383. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6384. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6385. {
  6386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6387. goto end;
  6388. }
  6389. }
  6390. }//END FOR CHAdeMO_QUANTITY
  6391. for (int index = 0; index < CCS_QUANTITY; index++)
  6392. {
  6393. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6394. {
  6395. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6396. {
  6397. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6398. goto end;
  6399. }
  6400. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6401. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6402. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6403. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6404. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6405. {
  6406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6407. goto end;
  6408. }
  6409. }
  6410. }//END FOR CCS_QUANTITY
  6411. for (int index = 0; index < GB_QUANTITY; index++)
  6412. {
  6413. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6414. {
  6415. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6416. {
  6417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6418. goto end;
  6419. }
  6420. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6421. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6422. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6423. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6424. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6425. {
  6426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6427. goto end;
  6428. }
  6429. }
  6430. }// END FOR GB_QUANTITY
  6431. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6432. {
  6433. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6434. {
  6435. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6436. {
  6437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6438. goto end;
  6439. }
  6440. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6441. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6443. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6444. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6445. {
  6446. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6447. goto end;
  6448. }
  6449. }
  6450. }// END FOR GENERAL_GUN_QUANTITY
  6451. for (int index = 0; index < AC_QUANTITY; index++)
  6452. {
  6453. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6454. {
  6455. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6456. {
  6457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6458. goto end;
  6459. }
  6460. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6461. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6462. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6463. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6464. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6465. {
  6466. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6467. goto end;
  6468. }
  6469. }
  6470. }//END FOR AC_QUANTITY
  6471. }// END FOR gunTotalNumber
  6472. }
  6473. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6474. {
  6475. for(int i=0; i < gunTotalNumber; i++)
  6476. {
  6477. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6478. {
  6479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6480. goto end;
  6481. }
  6482. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6483. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6484. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6485. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6486. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6487. {
  6488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6489. goto end;
  6490. }
  6491. }
  6492. }
  6493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6494. goto end;
  6495. }
  6496. //----------------------gunIndex is not 0 ------------------------------------------------//
  6497. //check Transaction active
  6498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6499. {
  6500. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6501. {
  6502. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6503. {
  6504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6505. goto end;
  6506. }
  6507. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6508. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6509. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6510. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6511. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6512. {
  6513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6514. goto end;
  6515. }
  6516. else
  6517. {
  6518. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6519. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6520. goto end;
  6521. }
  6522. }
  6523. }//END FOR CHAdeMO_QUANTITY
  6524. for (int index = 0; index < CCS_QUANTITY; index++)
  6525. {
  6526. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6527. {
  6528. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6529. {
  6530. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6531. goto end;
  6532. }
  6533. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6534. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6535. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6536. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6537. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6538. {
  6539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6540. goto end;
  6541. }
  6542. else
  6543. {
  6544. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6546. goto end;
  6547. }
  6548. }
  6549. }//END FOR CCS_QUANTITY
  6550. for (int index = 0; index < GB_QUANTITY; index++)
  6551. {
  6552. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6553. {
  6554. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6555. {
  6556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6557. goto end;
  6558. }
  6559. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6560. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6561. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6562. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6563. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6564. {
  6565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6566. goto end;
  6567. }
  6568. else
  6569. {
  6570. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6572. goto end;
  6573. }
  6574. }
  6575. }// END FOR GB_QUANTITY
  6576. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6577. {
  6578. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6579. {
  6580. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6581. {
  6582. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6583. goto end;
  6584. }
  6585. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6586. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6587. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6588. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6589. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6590. {
  6591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6592. goto end;
  6593. }
  6594. else
  6595. {
  6596. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6597. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6598. goto end;
  6599. }
  6600. }
  6601. }// END FOR GENERAL_GUN_QUANTITY
  6602. for (int index = 0; index < AC_QUANTITY; index++)
  6603. {
  6604. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6605. {
  6606. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6607. {
  6608. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6609. goto end;
  6610. }
  6611. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6612. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6613. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6614. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6615. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6616. {
  6617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6618. goto end;
  6619. }
  6620. else
  6621. {
  6622. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6624. goto end;
  6625. }
  6626. }
  6627. }//END FOR AC_QUANTITY
  6628. }//END FOR AvailabilityTypeStr[Inoperative]
  6629. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6630. {
  6631. //----------------------gunIndex is 0 ------------------------------------------------//
  6632. if(gunIndex == 0)
  6633. {
  6634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6635. {
  6636. for(int i=0; i < gunTotalNumber; i++)
  6637. {
  6638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6639. {
  6640. 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
  6641. {
  6642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6643. goto end;
  6644. }
  6645. }//END FOR CHAdeMO_QUANTITY
  6646. for (int index = 0; index < CCS_QUANTITY; index++)
  6647. {
  6648. 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
  6649. {
  6650. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6651. goto end;
  6652. }
  6653. }//END FOR CCS_QUANTITY
  6654. for (int index = 0; index < GB_QUANTITY; index++)
  6655. {
  6656. 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
  6657. {
  6658. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6659. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6660. goto end;
  6661. }
  6662. }// END FOR GB_QUANTITY
  6663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6664. {
  6665. 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
  6666. {
  6667. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6669. goto end;
  6670. }
  6671. }// END FOR GENERAL_GUN_QUANTITY
  6672. for (int index = 0; index < AC_QUANTITY; index++)
  6673. {
  6674. 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
  6675. {
  6676. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6677. goto end;
  6678. }
  6679. }//END FOR CHAdeMO_QUANTITY
  6680. }// END FOR gunTotalNumber
  6681. }
  6682. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6683. {
  6684. for(int i=0; i < gunTotalNumber; i++)
  6685. {
  6686. for (int index = 0; index < AC_QUANTITY; index++)
  6687. {
  6688. 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
  6689. {
  6690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6691. goto end;
  6692. }
  6693. }//END FOR CHAdeMO_QUANTITY
  6694. } // END FOR gunTotalNumber
  6695. }
  6696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6697. goto end;
  6698. }
  6699. //----------------------gunIndex is not 0 ------------------------------------------------//
  6700. //check Transaction active
  6701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6702. {
  6703. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6704. {
  6705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6706. goto end;
  6707. }
  6708. }//END FOR CHAdeMO_QUANTITY
  6709. for (int index = 0; index < CCS_QUANTITY; index++)
  6710. {
  6711. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6712. {
  6713. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6714. goto end;
  6715. }
  6716. }//END FOR CCS_QUANTITY
  6717. for (int index = 0; index < GB_QUANTITY; index++)
  6718. {
  6719. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6720. {
  6721. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6722. goto end;
  6723. }
  6724. }// END FOR GB_QUANTITY
  6725. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6726. {
  6727. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6728. {
  6729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6730. goto end;
  6731. }
  6732. }// END FOR GENERAL_GUN_QUANTITY
  6733. for (int index = 0; index < AC_QUANTITY; index++)
  6734. {
  6735. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6736. {
  6737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6738. goto end;
  6739. }
  6740. }//END FOR AC_QUANTITY
  6741. }//END FOR AvailabilityTypeStr[Operative]
  6742. end:
  6743. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6744. {
  6745. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6746. }
  6747. else
  6748. {
  6749. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6750. }
  6751. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6752. {
  6753. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6754. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6755. }
  6756. else if(gunIndex == 0)
  6757. {
  6758. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6759. {
  6760. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6761. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6762. }
  6763. }
  6764. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6765. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6766. return result;
  6767. }
  6768. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6769. {
  6770. mtrace();
  6771. int result = FAIL;
  6772. char keystr[40]={0};
  6773. char valuestr[256]={0};
  6774. char comfirmstr[20]={0};
  6775. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6776. json_object *ChangeConfiguration;
  6777. ChangeConfiguration = json_tokener_parse(payload);
  6778. if(!is_error(ChangeConfiguration))
  6779. {
  6780. // Required data
  6781. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6782. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6783. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6784. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6785. }
  6786. json_object_put(ChangeConfiguration);
  6787. if((uuid==NULL) || (payload ==NULL) )
  6788. {
  6789. DEBUG_ERROR("Payload is null\n");
  6790. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6791. }
  6792. else
  6793. {
  6794. int status = setKeyValue(keystr, valuestr);
  6795. switch(status)
  6796. {
  6797. case ConfigurationStatus_Accepted:
  6798. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6799. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6800. StoreConfigurationTable();
  6801. break;
  6802. case RebootRequired:
  6803. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6804. StoreConfigurationTable();
  6805. break;
  6806. case NotSupported:
  6807. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6808. break;
  6809. case ConfigurationStatus_Rejected:
  6810. default:
  6811. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6812. break;
  6813. }
  6814. }
  6815. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6816. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6817. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6818. {
  6819. ChageWebSocketPingInterval(atoi(valuestr));
  6820. }
  6821. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6822. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6823. {
  6824. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6825. SetOcppConnStatus(FALSE);
  6826. }
  6827. return result;
  6828. }
  6829. int handleClearCacheRequest(char *uuid, char *payload)
  6830. {
  6831. mtrace();
  6832. int result = FAIL;
  6833. char comfirmstr[20];
  6834. char rmFileCmd[100]={0};
  6835. struct stat stats;
  6836. DEBUG_INFO("handleClearCacheRequest...\n");
  6837. stat("/Storage/OCPP", &stats);
  6838. // Check for directory existence
  6839. if (S_ISDIR(stats.st_mode) == 1)
  6840. {}
  6841. else
  6842. {
  6843. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6844. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6845. system(rmFileCmd);
  6846. }
  6847. if(OCPP_cleanLocalCache())
  6848. {
  6849. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6850. }
  6851. else
  6852. {
  6853. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6854. }
  6855. sendClearCacheConfirmation(uuid, comfirmstr);
  6856. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6857. return result;
  6858. }
  6859. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6860. {
  6861. mtrace();
  6862. int result = FAIL;
  6863. int resultRename;
  6864. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6865. char chargingProfilePurposeStr[26]={0};
  6866. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6867. char tempchargingProfilePurposeStr[26]={0};
  6868. char str[100]={0};
  6869. char fname[200]={0};
  6870. char comfirmstr[20]={0};
  6871. char word[1600]={0};
  6872. int clearflag = FALSE;
  6873. int chargingProfileIdIsNULL = FALSE;
  6874. int connectorIsNULL = FALSE;
  6875. int chargingProfilePurposeIsNULL = FALSE;
  6876. int stackLevelIsNULL = FALSE;
  6877. //int GotoEnd = FALSE;
  6878. FILE *fptr1, *fptr2;
  6879. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6880. int n_chargingProfile=0;
  6881. int isEmptyFile = FALSE;
  6882. char sLineWord[1600]={0};
  6883. char chargingProfiles[10][100]={0};
  6884. int ChargeProfileCount = 0;
  6885. int ch;
  6886. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6887. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6888. json_object *ClearChargingProfile;
  6889. ClearChargingProfile = json_tokener_parse(payload);
  6890. if(!is_error(ClearChargingProfile))
  6891. {
  6892. // Optional data
  6893. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6894. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6895. else
  6896. chargingProfileIdIsNULL = TRUE;
  6897. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6898. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6899. else
  6900. connectorIsNULL = TRUE;
  6901. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6902. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6903. else
  6904. chargingProfilePurposeIsNULL = TRUE;
  6905. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6906. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6907. else
  6908. stackLevelIsNULL = TRUE;
  6909. }
  6910. json_object_put(ClearChargingProfile);
  6911. if(connectorIsNULL == FALSE)
  6912. {
  6913. switch(connectorIdInt)
  6914. {
  6915. case 0:
  6916. if(chargingProfilePurposeIsNULL == TRUE)
  6917. {
  6918. int l = 0;
  6919. strcpy(fname, ChargePointMaxProfile_JSON);
  6920. if((access(fname,F_OK))!=-1)
  6921. {
  6922. strcpy(chargingProfiles[l], fname);
  6923. l = l + 1;
  6924. }
  6925. strcpy(fname, TxDefaultProfile_0_JSON);
  6926. if((access(fname,F_OK))!=-1)
  6927. {
  6928. strcpy(chargingProfiles[l], fname);
  6929. l = l + 1;
  6930. }
  6931. ChargeProfileCount = l;
  6932. }
  6933. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6934. {
  6935. strcpy(fname, ChargePointMaxProfile_JSON);
  6936. if((access(fname,F_OK))!=-1)
  6937. {
  6938. strcpy(chargingProfiles[0], fname);
  6939. ChargeProfileCount = 1;
  6940. }
  6941. }
  6942. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6943. {
  6944. strcpy(fname, TxDefaultProfile_0_JSON);
  6945. if((access(fname,F_OK))!=-1)
  6946. {
  6947. strcpy(chargingProfiles[0], fname);
  6948. ChargeProfileCount = 1;
  6949. }
  6950. }
  6951. break;
  6952. default:
  6953. if(chargingProfilePurposeIsNULL == TRUE)
  6954. {
  6955. int m = 0;
  6956. memset(fname, 0, ARRAY_SIZE(fname));
  6957. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6958. if((access(fname,F_OK))!=-1)
  6959. {
  6960. strcpy(chargingProfiles[m], fname);
  6961. m = m + 1;
  6962. }
  6963. memset(fname, 0, ARRAY_SIZE(fname));
  6964. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6965. if((access(fname,F_OK))!=-1)
  6966. {
  6967. strcpy(chargingProfiles[m], fname);
  6968. m = m + 1;
  6969. }
  6970. ChargeProfileCount = m;
  6971. }
  6972. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6973. {
  6974. //strcpy(fname, TxDefaultProfile_1_JSON);
  6975. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6976. if((access(fname,F_OK))!=-1)
  6977. {
  6978. strcpy(chargingProfiles[0], fname);
  6979. ChargeProfileCount = 1;
  6980. }
  6981. }
  6982. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6983. {
  6984. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6985. if((access(fname,F_OK))!=-1)
  6986. {
  6987. strcpy(chargingProfiles[0], fname);
  6988. ChargeProfileCount = 1;
  6989. }
  6990. //strcpy(fname, TxProfile_1_JSON);
  6991. }
  6992. //strcpy(fname, ChargePointMaxProfile_JSON );
  6993. break;
  6994. }
  6995. }
  6996. else // Check all Charging Profiles
  6997. {
  6998. int i = 0;
  6999. char fnametemp[200]={0};
  7000. ChargeProfileCount = 0;
  7001. //Check ChargePointMaxProfile.json exit
  7002. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7003. {
  7004. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7005. i = i + 1;
  7006. }
  7007. //Check TxDefaultProfile_0.json exit
  7008. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7009. {
  7010. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7011. i = i + 1;
  7012. }
  7013. //Check TxDefaultProfile_%d.json
  7014. for(int j=1; j <= gunTotalNumber; j++)
  7015. {
  7016. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7017. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7018. if((access(fnametemp,F_OK))!=-1)
  7019. {
  7020. strcpy(chargingProfiles[i], fnametemp);
  7021. i = i + 1;
  7022. }
  7023. }
  7024. //Check TxProfile_%d.json
  7025. for(int j=1; j <= gunTotalNumber; j++)
  7026. {
  7027. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7028. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7029. if((access(fnametemp,F_OK))!=-1)
  7030. {
  7031. strcpy(chargingProfiles[i], fnametemp);
  7032. i = i + 1;
  7033. }
  7034. }
  7035. ChargeProfileCount = i;
  7036. }// End connectorIsNULL is TRUE
  7037. if(ChargeProfileCount == 0)
  7038. {
  7039. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7040. goto end;
  7041. }
  7042. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7043. {
  7044. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7045. goto end;
  7046. }
  7047. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7048. {
  7049. memset(str, 0, ARRAY_SIZE(str));
  7050. // clear temp file
  7051. sprintf(str,"rm -f %s",temp);
  7052. system(str);
  7053. for(int k=0; k < ChargeProfileCount; k++)
  7054. {
  7055. memset(str, 0, ARRAY_SIZE(str));
  7056. //clear file in C
  7057. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7058. system(str);
  7059. }
  7060. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7061. goto end;
  7062. }
  7063. else if(connectorIsNULL == TRUE)
  7064. {
  7065. for(int k=0; k < ChargeProfileCount; k++)
  7066. {
  7067. fptr1 = fopen(chargingProfiles[k], "r");
  7068. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7069. //Check Charging Profile Count
  7070. while(fscanf(fptr1, "%s", word) != EOF)
  7071. {
  7072. //DEBUG_INFO("word=%s\n",word);
  7073. if(strstr(word, "chargingProfileId")!= NULL)
  7074. {
  7075. //DEBUG_INFO("test chargingProfileId \n");
  7076. n_chargingProfile = n_chargingProfile + 1;
  7077. //DEBUG_INFO("chargingProfileId Found\n");
  7078. }
  7079. }
  7080. rewind(fptr1);
  7081. //search Charging Profile Element
  7082. //int i= 0;
  7083. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7084. {
  7085. json_object *tmpProfilee;
  7086. tmpProfilee = json_tokener_parse(sLineWord);
  7087. if(!is_error(tmpProfilee))
  7088. {
  7089. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7090. {
  7091. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7092. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7093. }
  7094. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7095. {
  7096. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7097. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7098. }
  7099. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7100. {
  7101. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7102. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7103. }
  7104. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7105. {
  7106. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7107. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7108. }
  7109. }
  7110. json_object_put(tmpProfilee);
  7111. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7112. {
  7113. //------- not write to fptr2-------//
  7114. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7115. //clearflag = TRUE;
  7116. }
  7117. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7118. {
  7119. //------- not write to fptr2-------//
  7120. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7121. }
  7122. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7123. {
  7124. //------- not write to fptr2-------//
  7125. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7126. }
  7127. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7128. {
  7129. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7130. }
  7131. else
  7132. {
  7133. fprintf(fptr2, sLineWord);//writing data into file
  7134. }
  7135. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7136. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7137. if(clearflag == TRUE)
  7138. {
  7139. fclose(fptr1);
  7140. fclose(fptr2);
  7141. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7142. system(str);
  7143. // clear temp file
  7144. sprintf(str,"rm -f %s",temp);
  7145. system(str);
  7146. }
  7147. else
  7148. {
  7149. fclose(fptr1);
  7150. fclose(fptr2);
  7151. memset(str, 0, ARRAY_SIZE(str));
  7152. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7153. system(str);
  7154. resultRename = rename(temp, chargingProfiles[k]);
  7155. if(resultRename == 0)
  7156. {
  7157. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7158. }
  7159. else
  7160. {
  7161. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7162. }
  7163. if(comfirmstr[0]== 0)
  7164. {
  7165. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7166. }
  7167. //Check chargingProfile is empty file
  7168. /*------ Read the file ----------------*/
  7169. fptr1=fopen(chargingProfiles[k],"r");
  7170. ch=fgetc(fptr1);
  7171. rewind(fptr1);
  7172. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7173. if(ch!=EOF)
  7174. {
  7175. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7176. {
  7177. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7178. if(sLineWord[0]=='\0')
  7179. {
  7180. isEmptyFile = TRUE;
  7181. break;
  7182. }
  7183. else
  7184. {
  7185. isEmptyFile = FALSE;
  7186. break;
  7187. }
  7188. }
  7189. }
  7190. else
  7191. isEmptyFile = TRUE;
  7192. fclose(fptr1);
  7193. if(isEmptyFile == TRUE)
  7194. {
  7195. memset(str, 0, ARRAY_SIZE(str));
  7196. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7197. system(str);
  7198. }
  7199. }
  7200. }// End of while(int k=0; k < ChargePointCount; k++)
  7201. }
  7202. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7203. {
  7204. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7205. for(int k=0; k < ChargeProfileCount; k++)
  7206. {
  7207. fptr1 = fopen(chargingProfiles[k], "r");
  7208. fptr2 = fopen(temp, "w+");
  7209. //Check Charging Profile Count
  7210. while(fscanf(fptr1, "%s", word) != EOF)
  7211. {
  7212. //DEBUG_INFO("word=%s\n",word);
  7213. if(strstr(word, "chargingProfileId")!= NULL)
  7214. {
  7215. n_chargingProfile = n_chargingProfile + 1;
  7216. }
  7217. }
  7218. rewind(fptr1);
  7219. //search Charging Profile Element
  7220. //int i= 0;
  7221. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7222. {
  7223. json_object *tmpProfilee;
  7224. tmpProfilee = json_tokener_parse(sLineWord);
  7225. if(!is_error(tmpProfilee))
  7226. {
  7227. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7228. {
  7229. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7230. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7231. }
  7232. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7233. {
  7234. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7235. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7236. }
  7237. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7238. {
  7239. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7240. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7241. }
  7242. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7243. {
  7244. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7245. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7246. }
  7247. }
  7248. json_object_put(tmpProfilee);
  7249. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7250. {
  7251. //------- not write to fptr2-------//
  7252. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7253. //clearflag = TRUE;
  7254. }
  7255. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7256. {
  7257. //------- not write to fptr2-------//
  7258. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7259. }
  7260. else if(stackLevelIsNULL == TRUE)
  7261. {
  7262. //Clear Whole File
  7263. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7264. clearflag = TRUE;
  7265. break;
  7266. }
  7267. else
  7268. {
  7269. fprintf(fptr2, sLineWord);//writing data into file
  7270. }
  7271. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7272. }
  7273. if(clearflag == TRUE)
  7274. {
  7275. fclose(fptr1);
  7276. fclose(fptr2);
  7277. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7278. system(str);
  7279. // clear temp file
  7280. sprintf(str,"rm -f %s",temp);
  7281. system(str);
  7282. }
  7283. else
  7284. {
  7285. fclose(fptr1);
  7286. fclose(fptr2);
  7287. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7288. system(str);
  7289. resultRename = rename(temp, chargingProfiles[k]);
  7290. if(resultRename == 0)
  7291. {
  7292. DEBUG_INFO("File ChargingProfile renamed successfully");
  7293. }
  7294. else
  7295. {
  7296. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7297. }
  7298. if(comfirmstr[0]== 0)
  7299. {
  7300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7301. }
  7302. //Check chargingProfile is empty file
  7303. /*------ Read the file ----------------*/
  7304. fptr1=fopen(chargingProfiles[k],"r");
  7305. ch=fgetc(fptr1);
  7306. rewind(fptr1);
  7307. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7308. if(ch!=EOF)
  7309. {
  7310. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7311. {
  7312. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7313. if(sLineWord[0]=='\0')
  7314. {
  7315. isEmptyFile = TRUE;
  7316. break;
  7317. }
  7318. else
  7319. {
  7320. isEmptyFile = FALSE;
  7321. break;
  7322. }
  7323. }
  7324. }
  7325. else
  7326. isEmptyFile = TRUE;
  7327. fclose(fptr1);
  7328. if(isEmptyFile == TRUE)
  7329. {
  7330. memset(str, 0, ARRAY_SIZE(str));
  7331. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7332. system(str);
  7333. }
  7334. /*------- End of reading ---------------*/
  7335. }
  7336. } // while(int k=0; k < ChargeProfileCount; k++)
  7337. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7338. end:
  7339. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7340. {
  7341. if(connectorIdInt == 0)
  7342. {
  7343. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7344. {
  7345. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7346. }
  7347. }
  7348. else
  7349. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7350. }
  7351. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7352. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7353. return result;
  7354. }
  7355. void createFirmwareVersionByDataTransfer(void)
  7356. {
  7357. json_object *FirmwareDataTransfer = json_object_new_object();
  7358. // AC & DC model
  7359. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7360. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7361. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7362. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7363. // DC model
  7364. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7365. {
  7366. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7367. {
  7368. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7369. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7370. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7371. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7372. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7373. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7374. }
  7375. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7376. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7377. {
  7378. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7379. }
  7380. }
  7381. else
  7382. {
  7383. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7384. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7387. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7390. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7391. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7392. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7393. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7394. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7395. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7396. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7397. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7398. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7399. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7400. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7401. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7402. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7403. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7404. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7405. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7406. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7407. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7408. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7409. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7410. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7411. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7412. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7413. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7414. }
  7415. // 4G model
  7416. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7417. {
  7418. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7419. }
  7420. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7421. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7422. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7423. json_object_put(FirmwareDataTransfer);
  7424. }
  7425. int handleDataTransferRequest(char *uuid, char *payload)
  7426. {
  7427. mtrace();
  7428. json_object *response = json_object_new_object();
  7429. int result = FAIL;
  7430. char tempvendorId[255]={0};
  7431. char tempmessageId[50]={0};
  7432. char tempdata[512]={0};
  7433. char message[2048]={0};
  7434. DEBUG_INFO("handleDataTransferRequest...\n");
  7435. if((uuid != NULL) && (payload != NULL))
  7436. {
  7437. json_object *DataTransfer;
  7438. DataTransfer = json_tokener_parse(payload);
  7439. if(!is_error(DataTransfer))
  7440. {
  7441. // Required data
  7442. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7443. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7444. // Optional data
  7445. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7446. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7447. if(json_object_object_get(DataTransfer, "data") != NULL)
  7448. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7449. result = PASS;
  7450. }
  7451. json_object_put(DataTransfer);
  7452. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7453. {
  7454. // Send all moudle firmware version on EVSE
  7455. createFirmwareVersionByDataTransfer();
  7456. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7457. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7458. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7459. json_object_put(response);
  7460. }
  7461. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7462. {
  7463. system("/usr/bin/run_tmate_restart.sh &");
  7464. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7465. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7466. json_object_put(response);
  7467. }
  7468. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7469. {
  7470. json_object *data;
  7471. data = json_tokener_parse(tempdata);
  7472. if(!is_error(data))
  7473. {
  7474. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7475. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7476. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7477. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7478. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7479. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7480. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7481. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7482. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7483. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7484. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7485. }
  7486. else
  7487. {
  7488. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7489. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7490. }
  7491. json_object_put(data);
  7492. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7493. json_object_put(response);
  7494. }
  7495. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7496. {
  7497. json_object *data;
  7498. data = json_tokener_parse(tempdata);
  7499. if(!is_error(data))
  7500. {
  7501. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7502. if(json_object_object_get(data, "idToken") != NULL)
  7503. {
  7504. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7505. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7506. }
  7507. if(json_object_object_get(data, "price") != NULL)
  7508. {
  7509. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7510. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7511. }
  7512. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7513. }
  7514. else
  7515. {
  7516. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7517. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7518. }
  7519. json_object_put(data);
  7520. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7521. json_object_put(response);
  7522. }
  7523. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7524. {
  7525. json_object *data;
  7526. data = json_tokener_parse(tempdata);
  7527. if(!is_error(data))
  7528. {
  7529. if(json_object_object_get(data, "txId") != NULL)
  7530. {
  7531. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7532. for(int idx = 0;idx<gunTotalNumber;idx++)
  7533. {
  7534. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7535. {
  7536. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  7537. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7538. if(json_object_object_get(data, "description") != NULL)
  7539. {
  7540. // California pricing V1.0
  7541. DEBUG_INFO("California pricing V1.0\n");
  7542. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7543. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7544. }
  7545. else
  7546. {
  7547. // California pricing V1.1
  7548. DEBUG_INFO("California pricing V1.1\n");
  7549. if(json_object_object_get(data, "timestamp") != NULL)
  7550. {
  7551. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  7552. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  7553. }
  7554. if(json_object_object_get(data, "meterValue") != NULL)
  7555. {
  7556. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  7557. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  7558. }
  7559. if(json_object_object_get(data, "cost") != NULL)
  7560. {
  7561. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  7562. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  7563. }
  7564. if(json_object_object_get(data, "state") != NULL)
  7565. {
  7566. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  7567. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  7568. }
  7569. if(json_object_object_get(data, "chargingPrice") != NULL)
  7570. {
  7571. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  7572. {
  7573. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  7574. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  7575. }
  7576. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  7577. {
  7578. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  7579. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  7580. }
  7581. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  7582. {
  7583. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  7584. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  7585. }
  7586. }
  7587. if(json_object_object_get(data, "idlePrice") != NULL)
  7588. {
  7589. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  7590. {
  7591. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  7592. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  7593. }
  7594. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  7595. {
  7596. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  7597. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  7598. }
  7599. }
  7600. if(json_object_object_get(data, "nextPeriod") != NULL)
  7601. {
  7602. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  7603. {
  7604. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  7605. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  7606. }
  7607. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  7608. {
  7609. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  7610. {
  7611. 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")));
  7612. ShmOCPP16Data->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"));
  7613. }
  7614. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  7615. {
  7616. 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")));
  7617. ShmOCPP16Data->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"));
  7618. }
  7619. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  7620. {
  7621. 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")));
  7622. ShmOCPP16Data->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"));
  7623. }
  7624. }
  7625. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  7626. {
  7627. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  7628. {
  7629. 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")));
  7630. ShmOCPP16Data->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"));
  7631. }
  7632. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  7633. {
  7634. 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")));
  7635. ShmOCPP16Data->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"));
  7636. }
  7637. }
  7638. }
  7639. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  7640. {
  7641. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  7642. {
  7643. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  7644. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  7645. }
  7646. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  7647. {
  7648. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  7649. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  7650. }
  7651. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  7652. {
  7653. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  7654. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  7655. }
  7656. }
  7657. }
  7658. }
  7659. }
  7660. }
  7661. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7662. }
  7663. else
  7664. {
  7665. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7666. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7667. }
  7668. json_object_put(data);
  7669. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7670. json_object_put(response);
  7671. }
  7672. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7673. {
  7674. json_object *data;
  7675. data = json_tokener_parse(tempdata);
  7676. if(!is_error(data))
  7677. {
  7678. if(json_object_object_get(data, "txId") != NULL)
  7679. {
  7680. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7681. for(int idx = 0;idx<gunTotalNumber;idx++)
  7682. {
  7683. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7684. {
  7685. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  7686. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7687. if(json_object_object_get(data, "description") != NULL)
  7688. {
  7689. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7690. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7691. }
  7692. }
  7693. }
  7694. }
  7695. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7696. }
  7697. else
  7698. {
  7699. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7700. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7701. }
  7702. json_object_put(data);
  7703. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7704. json_object_put(response);
  7705. }
  7706. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7707. {
  7708. json_object *data;
  7709. data = json_tokener_parse(tempdata);
  7710. if(!is_error(data))
  7711. {
  7712. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7713. if(json_object_object_get(data, "Content_Type") != NULL)
  7714. {
  7715. 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))
  7716. {
  7717. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7718. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7719. {
  7720. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7721. }
  7722. }
  7723. else
  7724. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7725. }
  7726. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7727. }
  7728. else
  7729. {
  7730. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7731. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7732. }
  7733. json_object_put(data);
  7734. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7735. json_object_put(response);
  7736. }
  7737. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7738. {
  7739. json_object *data;
  7740. data = json_tokener_parse(tempdata);
  7741. if(!is_error(data))
  7742. {
  7743. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7744. if(json_object_object_get(data, "Page_Index") != NULL)
  7745. {
  7746. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7747. }
  7748. if(json_object_object_get(data, "Duration") != NULL)
  7749. {
  7750. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7751. }
  7752. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7753. }
  7754. else
  7755. {
  7756. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7757. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7758. }
  7759. json_object_put(data);
  7760. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7761. json_object_put(response);
  7762. }
  7763. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7764. {
  7765. json_object *data;
  7766. data = json_tokener_parse(tempdata);
  7767. if(!is_error(data))
  7768. {
  7769. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7770. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7771. {
  7772. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7773. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7774. else
  7775. {
  7776. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7777. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7778. }
  7779. }
  7780. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7781. {
  7782. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7783. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7784. else
  7785. {
  7786. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7787. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7788. }
  7789. }
  7790. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7791. {
  7792. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7793. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7794. else
  7795. {
  7796. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7797. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7798. }
  7799. }
  7800. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7801. {
  7802. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7803. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7804. else
  7805. {
  7806. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7807. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7808. }
  7809. }
  7810. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7811. {
  7812. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7813. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7814. else
  7815. {
  7816. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7817. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7818. }
  7819. }
  7820. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7821. {
  7822. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7823. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7824. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7825. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7826. else
  7827. {
  7828. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7829. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7830. }
  7831. }
  7832. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7833. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7834. }
  7835. else
  7836. {
  7837. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7838. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7839. }
  7840. json_object_put(data);
  7841. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7842. json_object_put(response);
  7843. }
  7844. else
  7845. {
  7846. // Can not find valid message id
  7847. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7848. }
  7849. }
  7850. else
  7851. {
  7852. // Payload is null
  7853. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7854. }
  7855. LWS_Send(message);
  7856. return result;
  7857. }
  7858. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7859. {
  7860. mtrace();
  7861. int result = FAIL;
  7862. int connectorIdInt, durationInt;
  7863. char chargingRateUnitStr[4]={0};
  7864. char comfirmstr[20];
  7865. int confirmPeriods = 0;
  7866. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7867. json_object *GetCompositeSchedule;
  7868. GetCompositeSchedule = json_tokener_parse(payload);
  7869. if(!is_error(GetCompositeSchedule))
  7870. {
  7871. // Required data
  7872. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7873. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7874. else
  7875. connectorIdInt = -1;
  7876. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7877. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7878. else
  7879. durationInt = 86400;
  7880. // Optional data
  7881. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7882. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7883. }
  7884. json_object_put(GetCompositeSchedule);
  7885. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7886. if((connectorIdInt == 0) ||
  7887. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7888. {
  7889. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7890. struct StructChargingProfile tmpProfile[1];
  7891. if(strstr(chargingRateUnitStr, "W") != NULL)
  7892. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7893. else
  7894. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7895. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7896. {
  7897. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7898. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7899. }
  7900. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7901. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7902. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7903. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7904. {
  7905. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7906. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7907. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7908. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7909. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7910. {
  7911. confirmPeriods = idx;
  7912. break;
  7913. }
  7914. }
  7915. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7916. {
  7917. confirmPeriods += 1;
  7918. }
  7919. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7920. }
  7921. else
  7922. {
  7923. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7924. }
  7925. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7926. return result;
  7927. }
  7928. int handleGetConfigurationRequest(char *uuid, char *payload)
  7929. {
  7930. mtrace();
  7931. int result = FAIL;
  7932. int MaxKeySupported = 0;
  7933. int n_keys = 0;
  7934. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7935. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7936. json_object *GetConfiguration;
  7937. GetConfiguration = json_tokener_parse(payload);
  7938. if(!is_error(GetConfiguration))
  7939. {
  7940. // Optional data
  7941. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7942. {
  7943. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7944. {
  7945. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7946. n_keys = idx + 1;
  7947. }
  7948. }
  7949. }
  7950. json_object_put(GetConfiguration);
  7951. UnknownKeynum = 0;
  7952. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7953. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7954. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7955. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7956. if(n_keys != 0)
  7957. {
  7958. for(int i=0;i<n_keys;i++)
  7959. {
  7960. getKeyValue(requestKey[i]);
  7961. }
  7962. }
  7963. else
  7964. {
  7965. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7966. getKeyValue("");
  7967. }
  7968. processUnkownKey();
  7969. sendGetConfigurationConfirmation(uuid);
  7970. return result;
  7971. }
  7972. static char fnamePlusPath[100]={0};
  7973. static char fnamePWithNoPath[60]={0};
  7974. void checkUploadLog(void)
  7975. {
  7976. FILE *fp;
  7977. /* Open the command for reading. */
  7978. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7979. if (fp == NULL) {
  7980. DEBUG_WARN("Failed to run command\n" );
  7981. exit(1);
  7982. }
  7983. int ftppathlen = 0;
  7984. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7985. int i = 0;
  7986. /* Read the output a line at a time - output it. */
  7987. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7988. if(i==0)
  7989. {
  7990. ftppathlen = strlen(fnamePlusPath);
  7991. DEBUG_INFO("%s\n", fnamePlusPath);
  7992. fnamePlusPath[ftppathlen]='\0';
  7993. break;
  7994. }
  7995. i= i+1;
  7996. }
  7997. /* close */
  7998. pclose(fp);
  7999. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8000. {
  8001. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8002. {
  8003. fnamePlusPath[k]='\0';
  8004. }
  8005. }
  8006. i=1;
  8007. //char fname[60]={0};
  8008. while(i < ftppathlen)
  8009. {
  8010. int len=ftppathlen-i;
  8011. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8012. {
  8013. DEBUG_INFO("compare '/' all right\n");
  8014. break;
  8015. }
  8016. i=i+1;
  8017. }
  8018. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8019. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8020. fnamePWithNoPath[i+1] = '\0';
  8021. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8022. {
  8023. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8024. {
  8025. fnamePWithNoPath[j]='\0';
  8026. }
  8027. }
  8028. FILE* fp1 = fopen(fnamePlusPath, "r");
  8029. if (fp1)
  8030. {
  8031. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8032. // file exists
  8033. fclose(fp1);
  8034. }
  8035. else
  8036. {
  8037. // file doesn't exist
  8038. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8039. }
  8040. }
  8041. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8042. {
  8043. mtrace();
  8044. int result = FAIL;
  8045. time_t CurrentTime;
  8046. struct tm *tm;
  8047. pthread_t th_Status;
  8048. CurrentTime = time(NULL);
  8049. tm = localtime(&CurrentTime);
  8050. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8051. sprintf((char*)ShmOCPP16Data->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);
  8052. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8053. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8054. return result;
  8055. }
  8056. void* GetDiagnosticsProcess(void* data)
  8057. {
  8058. pthread_detach(pthread_self());
  8059. mtrace();
  8060. int retriesInt=0, retryIntervalInt=0;
  8061. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8062. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  8063. int port=0;
  8064. int isSuccess = FALSE;
  8065. char cmdBuf[2048];
  8066. struct tm *tmNow;
  8067. time_t CurrentTime;
  8068. struct tm tmStart;
  8069. struct tm tmStop;
  8070. CurrentTime = time(NULL);
  8071. tmNow=localtime(&CurrentTime);
  8072. uint16_t targetYear, targetMonth;
  8073. json_object *GetDiagnostics;
  8074. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8075. GetDiagnostics = json_tokener_parse(data);
  8076. if(!is_error(GetDiagnostics))
  8077. {
  8078. // Required data
  8079. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8080. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8081. // Optional data
  8082. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8083. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8084. else
  8085. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8086. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8087. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8088. else
  8089. retryIntervalInt = 30;
  8090. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8091. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8092. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8093. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8094. }
  8095. json_object_put(GetDiagnostics);
  8096. // Pack log to compress file
  8097. 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) &&
  8098. (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))
  8099. {
  8100. // Pack system log
  8101. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8102. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8103. targetYear = tmStart.tm_year;
  8104. targetMonth = tmStart.tm_mon;
  8105. do
  8106. {
  8107. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8108. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8109. if(targetMonth+1>=13)
  8110. {
  8111. targetYear += 1;
  8112. targetMonth = 1;
  8113. }
  8114. else
  8115. {
  8116. targetMonth += 1;
  8117. }
  8118. }while((targetYear < (tmNow->tm_year+1900)) ||
  8119. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8120. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8121. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8122. system(cmdBuf);
  8123. // Pack charging & event log
  8124. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8125. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8126. targetYear = tmStart.tm_year;
  8127. targetMonth = tmStart.tm_mon;
  8128. do
  8129. {
  8130. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8131. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8132. if(targetMonth+1>=13)
  8133. {
  8134. targetYear += 1;
  8135. targetMonth = 1;
  8136. }
  8137. else
  8138. {
  8139. targetMonth += 1;
  8140. }
  8141. }while((targetYear < (tmNow->tm_year+1900)) ||
  8142. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8143. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8144. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8145. system(cmdBuf);
  8146. // Combine log file
  8147. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8148. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8149. }
  8150. else
  8151. {
  8152. system("exec /root/logPackTools 'log' 6");
  8153. }
  8154. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8155. system(cmdBuf);
  8156. checkUploadLog();
  8157. //****************location*******************/
  8158. if(strcmp(locationstr,"")==0)
  8159. {
  8160. DEBUG_INFO("location is <Empty>!\n");
  8161. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8162. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8163. goto end;
  8164. }
  8165. memset(protocol, 0, ARRAY_SIZE(protocol));
  8166. memset(user, 0, ARRAY_SIZE(user) );
  8167. memset(password, 0, ARRAY_SIZE(password));
  8168. memset(host, 0, ARRAY_SIZE(host));
  8169. memset(path, 0, ARRAY_SIZE(path));
  8170. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8171. memset(host1, 0, ARRAY_SIZE(host1));
  8172. memset(path1, 0, ARRAY_SIZE(path1));
  8173. /*location: ftp://user:password@host:port/path*/
  8174. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8175. if((access(fnamePlusPath,F_OK))!=-1)
  8176. {
  8177. DEBUG_INFO("fnamePlusPath exist.\n");
  8178. }
  8179. else
  8180. {
  8181. DEBUG_INFO("fnamePlusPath not exist!\n");
  8182. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8183. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8184. goto end;
  8185. }
  8186. if(strchr(locationstr,'@')==NULL)
  8187. {
  8188. sscanf(locationstr,
  8189. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8190. protocol, host, &port, path);
  8191. strcpy(user,"anonymous");
  8192. strcpy(password,"");
  8193. }
  8194. else
  8195. {
  8196. //DEBUG_INFO("pch=%s\n", pch);
  8197. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8198. protocol, user, password, host, &port, path);
  8199. }
  8200. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8201. {
  8202. DEBUG_INFO("protocol is not ftp/http ! \n");
  8203. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8204. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8205. goto end;
  8206. }
  8207. if(strncmp(locationstr,"http", 4) == 0)
  8208. {
  8209. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8210. sprintf(ftppath,"/%s", path);
  8211. do
  8212. {
  8213. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8214. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8215. sleep(3);
  8216. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8217. if(!isSuccess)
  8218. {
  8219. DEBUG_INFO("Diagnostics fail.\n");
  8220. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8221. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8222. sleep(retryIntervalInt);
  8223. }
  8224. else
  8225. {
  8226. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8227. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8228. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8229. }
  8230. retriesInt--;
  8231. }while((isSuccess == 0)&&(retriesInt >= 0));
  8232. }
  8233. else
  8234. {
  8235. sscanf(host,"%[^/]%s",host1, path1);
  8236. if(strlen(path) > 0)
  8237. sprintf(ftppath,"/%s", path);
  8238. else
  8239. sprintf(ftppath,"/%s", path1);
  8240. int ftppathlen=strlen(ftppath);
  8241. int i=1;
  8242. char filenametemp[50];
  8243. while(i < ftppathlen)
  8244. {
  8245. int len=ftppathlen-i;
  8246. if(ftppath[len]== 47) // '/' ascll code: 47
  8247. {
  8248. DEBUG_INFO("find '/' all right\n");
  8249. break;
  8250. }
  8251. i=i+1;
  8252. }
  8253. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8254. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8255. filenametemp[i+1] = 0;
  8256. if(port == 0)
  8257. port = 21;
  8258. do
  8259. {
  8260. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8261. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8262. sleep(3);
  8263. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8264. if(!isSuccess)
  8265. {
  8266. DEBUG_INFO("Diagnostics fail.\n");
  8267. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8268. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8269. sleep(retryIntervalInt);
  8270. }
  8271. else
  8272. {
  8273. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8274. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8275. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8276. }
  8277. retriesInt--;
  8278. }while((!isSuccess)&&(retriesInt >= 0));
  8279. }
  8280. end:
  8281. system("rm -f /mnt/*");
  8282. sleep(5);
  8283. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8284. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8285. pthread_exit(NULL);
  8286. }
  8287. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8288. {
  8289. mtrace();
  8290. int result = FAIL;
  8291. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8292. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8293. {
  8294. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8295. locallistVersion = -1;
  8296. }
  8297. else
  8298. {
  8299. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8300. OCPP_getListVerion();
  8301. }
  8302. //from db.OCPP_getListVerion
  8303. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8304. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8305. sendGetLocalListVersionConfirmation(uuid,"");
  8306. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8307. return result;
  8308. }
  8309. int handleRemoteStartRequest(char *uuid, char *payload)
  8310. {
  8311. mtrace();
  8312. int result = FAIL;
  8313. int connectorIdInt=0;
  8314. int tempIndex = 0;
  8315. int connectorIdIsNULL, chargingProfileIsNULL;
  8316. char comfirmstr[20]={0};
  8317. char cmdBuf[512];
  8318. json_object *RemoteStartTransaction;
  8319. FILE *fp;
  8320. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8321. if(server_pending == TRUE)
  8322. {
  8323. return 0;
  8324. }
  8325. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8326. RemoteStartTransaction = json_tokener_parse(payload);
  8327. if(!is_error(RemoteStartTransaction))
  8328. {
  8329. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8330. {
  8331. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8332. if(connectorIdInt <= gunTotalNumber)
  8333. {
  8334. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8335. // Required data
  8336. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8337. // Optional data
  8338. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8339. {
  8340. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8341. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8342. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8343. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8344. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8345. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8346. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8347. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8348. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8349. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8350. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8351. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8352. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8353. {
  8354. sprintf((char*)ShmOCPP16Data->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")));
  8355. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8356. ShmOCPP16Data->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"));
  8357. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8358. ShmOCPP16Data->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"));
  8359. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8360. sprintf((char*)ShmOCPP16Data->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")));
  8361. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8362. {
  8363. 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++)
  8364. {
  8365. ShmOCPP16Data->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"));
  8366. ShmOCPP16Data->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"));
  8367. 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)
  8368. ShmOCPP16Data->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"));
  8369. }
  8370. }
  8371. }
  8372. }
  8373. else
  8374. chargingProfileIsNULL = TRUE;
  8375. }
  8376. }
  8377. else
  8378. connectorIdIsNULL = TRUE;
  8379. }
  8380. else
  8381. connectorIdIsNULL = TRUE;
  8382. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8383. {
  8384. DEBUG_WARN("Connector id is NULL\n.");
  8385. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8386. goto end;
  8387. }
  8388. /*
  8389. enum _SYSTEM_STATUS
  8390. {
  8391. S_BOOTING = 0,
  8392. S_IDLE, = 1
  8393. S_AUTHORIZING, = 2
  8394. S_REASSIGN_CHECK, = 3
  8395. S_REASSIGN, = 4
  8396. S_PRECHARGE, = 5
  8397. S_PREPARING_FOR_EV, = 6
  8398. S_PREPARING_FOR_EVSE, = 7
  8399. S_CHARGING, = 8
  8400. S_TERMINATING, = 9
  8401. S_COMPLETE, = 10
  8402. S_ALARM, = 11
  8403. S_FAULT = 12
  8404. }
  8405. */
  8406. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8407. {
  8408. //check Transaction active
  8409. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8410. {
  8411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8412. {
  8413. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8414. }
  8415. else
  8416. {
  8417. tempIndex = connectorIdInt -1;
  8418. }
  8419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8420. {
  8421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8422. {
  8423. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8424. {
  8425. //Reserved
  8426. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8427. }
  8428. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8429. {
  8430. //Reserved
  8431. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8432. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8433. goto end;
  8434. }
  8435. else
  8436. {
  8437. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8438. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8439. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8440. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8441. {
  8442. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8443. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8444. goto end;
  8445. }
  8446. }//END FOR ELSE
  8447. }
  8448. }// END FOR CHAdeMO_QUANTITY
  8449. }
  8450. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8451. {
  8452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8453. {
  8454. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8455. }
  8456. else
  8457. {
  8458. tempIndex = connectorIdInt -1;
  8459. }
  8460. for (int index = 0; index < CCS_QUANTITY; index++)
  8461. {
  8462. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8463. {
  8464. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8465. {
  8466. //Reserved
  8467. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8468. }
  8469. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8470. {
  8471. //Reserved
  8472. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8473. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8474. goto end;
  8475. }
  8476. else
  8477. {
  8478. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8479. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8480. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8481. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8482. {
  8483. DEBUG_WARN("CCS connector not allow start\n.");
  8484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8485. goto end;
  8486. }
  8487. }// END FOR ELSE
  8488. }
  8489. }// END FOR CCS_QUANTITY
  8490. }
  8491. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8492. {
  8493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8494. {
  8495. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8496. }
  8497. else
  8498. {
  8499. tempIndex = connectorIdInt -1;
  8500. }
  8501. for (int index = 0; index < GB_QUANTITY; index++)
  8502. {
  8503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8504. {
  8505. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8506. {
  8507. //Reserved
  8508. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8509. }
  8510. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8511. {
  8512. //Reserved
  8513. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8515. goto end;
  8516. }
  8517. else
  8518. {
  8519. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8520. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8521. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8522. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8523. {
  8524. DEBUG_WARN("GB connector not allow start\n.");
  8525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8526. goto end;
  8527. }
  8528. }// END FOR ELSE
  8529. }
  8530. } // END FOR GB_QUANTITY
  8531. }
  8532. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8533. {
  8534. tempIndex = connectorIdInt -1;
  8535. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8536. {
  8537. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8538. {
  8539. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8540. {
  8541. //Reserved
  8542. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8543. }
  8544. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8545. {
  8546. //Reserved
  8547. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8548. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8549. goto end;
  8550. }
  8551. else
  8552. {
  8553. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8554. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8555. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8556. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8557. {
  8558. DEBUG_WARN("GB connector not allow start\n.");
  8559. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8560. goto end;
  8561. }
  8562. }// END FOR ELSE
  8563. }
  8564. } // END FOR GB_QUANTITY
  8565. }
  8566. else
  8567. {
  8568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8569. {
  8570. tempIndex = 2;
  8571. }
  8572. else
  8573. {
  8574. tempIndex = connectorIdInt -1;
  8575. }
  8576. for (int index = 0; index < AC_QUANTITY; index++)
  8577. {
  8578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8579. {
  8580. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8581. {
  8582. //Reserved
  8583. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8584. }
  8585. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8586. {
  8587. //Reserved
  8588. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8589. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8590. goto end;
  8591. }
  8592. else
  8593. {
  8594. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8595. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8596. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8597. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8598. {
  8599. DEBUG_WARN("AC connector not allow start\n.");
  8600. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8601. goto end;
  8602. }
  8603. }//END FOR ELSE
  8604. }
  8605. }// END FOR AC_QUANTITY
  8606. }
  8607. if(chargingProfileIsNULL == FALSE)
  8608. {
  8609. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8610. {
  8611. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8613. //memset idTag
  8614. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8615. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8616. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8617. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8618. // Save profile to file
  8619. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8620. system(cmdBuf);
  8621. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8622. fp = fopen(cmdBuf, "w");
  8623. 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));
  8624. fclose(fp);
  8625. }
  8626. else
  8627. {
  8628. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8629. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8630. }
  8631. }
  8632. else
  8633. {
  8634. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8635. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8636. //memset idTag
  8637. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8638. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8639. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8640. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8641. }
  8642. }
  8643. else
  8644. {
  8645. DEBUG_WARN("Connector id over\n.");
  8646. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8647. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8648. }
  8649. end:
  8650. json_object_put(RemoteStartTransaction);
  8651. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8652. {
  8653. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8654. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8655. }
  8656. //OCPP send RemoteStartConfirmation by first.
  8657. sendRemoteStartConfirmation(uuid, comfirmstr);
  8658. return result;
  8659. }
  8660. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8661. {
  8662. mtrace();
  8663. int result = FAIL;
  8664. int match = FALSE;
  8665. int GunNO = 0;
  8666. int tempIndex = 0;
  8667. int transactionIdInt=0;
  8668. int transactionIdIsNULL= TRUE;
  8669. char comfirmstr[20];
  8670. json_object *RemoteStopTransaction;
  8671. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8672. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8673. if(server_pending == TRUE)
  8674. {
  8675. return 0;
  8676. }
  8677. RemoteStopTransaction = json_tokener_parse(payload);
  8678. if(!is_error(RemoteStopTransaction))
  8679. {
  8680. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8681. {
  8682. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8683. transactionIdIsNULL = FALSE;
  8684. }
  8685. }
  8686. json_object_put(RemoteStopTransaction);
  8687. if(transactionIdIsNULL == FALSE)
  8688. {
  8689. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8690. {
  8691. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8692. {
  8693. //check Transaction active
  8694. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8695. {
  8696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8697. {
  8698. tempIndex = ((gun_index==2) ? 1: 0);
  8699. }
  8700. else
  8701. {
  8702. tempIndex = gun_index;
  8703. }
  8704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8705. {
  8706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8707. {
  8708. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8709. {
  8710. match = TRUE;
  8711. GunNO = gun_index;
  8712. }
  8713. }
  8714. }// END FOR CHAdeMO_QUANTITY
  8715. }
  8716. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8717. {
  8718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8719. {
  8720. tempIndex = ((gun_index==2) ? 1: 0);
  8721. }
  8722. else
  8723. {
  8724. tempIndex = gun_index;
  8725. }
  8726. for (int index = 0; index < CCS_QUANTITY; index++)
  8727. {
  8728. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8729. {
  8730. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8731. {
  8732. match = TRUE;
  8733. GunNO = gun_index;
  8734. }
  8735. }
  8736. }// END FOR CCS_QUANTITY
  8737. }
  8738. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8739. {
  8740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8741. {
  8742. tempIndex = ((gun_index==2) ? 1: 0);
  8743. }
  8744. else
  8745. {
  8746. tempIndex = gun_index;
  8747. }
  8748. for (int index = 0; index < GB_QUANTITY; index++)
  8749. {
  8750. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8751. {
  8752. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8753. {
  8754. match = TRUE;
  8755. GunNO = gun_index;
  8756. }
  8757. }
  8758. }// END FOR GB_QUANTITY
  8759. }
  8760. else if(gunType[gun_index] == GUN_TYPE_DO)
  8761. {
  8762. tempIndex = gun_index;
  8763. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8764. {
  8765. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8766. {
  8767. 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
  8768. {
  8769. match = TRUE;
  8770. GunNO = gun_index;
  8771. }
  8772. }
  8773. }// END FOR GB_QUANTITY
  8774. }
  8775. else
  8776. {
  8777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8778. {
  8779. tempIndex = 2;
  8780. }
  8781. else
  8782. {
  8783. tempIndex = gun_index;
  8784. }
  8785. for (int index = 0; index < AC_QUANTITY; index++)
  8786. {
  8787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8788. {
  8789. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8790. {
  8791. match = TRUE;
  8792. GunNO = gun_index;
  8793. }
  8794. }
  8795. }// END FOR CHAdeMO_QUANTITY
  8796. } // END FOR AC ELSE
  8797. }// CHECK IF ResponseTransactionId == transactionIdInt
  8798. }//END FOR
  8799. if( match == TRUE)
  8800. {
  8801. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8802. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8803. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8804. }
  8805. else
  8806. {
  8807. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8808. }
  8809. }
  8810. else
  8811. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8812. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8813. return result;
  8814. }
  8815. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8816. {
  8817. mtrace();
  8818. int result = FAIL;
  8819. int connectorIdInt=0, reservationIdInt=0;
  8820. int tempIndex = 0;
  8821. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8822. char comfirmstr[20]={0};
  8823. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8824. int c = 0;
  8825. char *loc;
  8826. //char *ptr;
  8827. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8828. strcpy(sstrtemp, stringtrimspace(payload));
  8829. //***(1)connectorId ****/
  8830. c=0;
  8831. loc = strstr(sstrtemp, "connectorId");
  8832. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8833. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8834. {
  8835. sstr[c] = loc[strlen("connectorId")+2+c];
  8836. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8837. c++;
  8838. }
  8839. sstr[c] = '\0';
  8840. connectorIdInt = atoi(sstr);
  8841. //***(2)expiryDate ****/
  8842. loc = strstr(sstrtemp, "expiryDate");
  8843. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8844. c = 0;
  8845. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8846. {
  8847. sstr[c] = loc[3+strlen("expiryDate")+c];
  8848. c++;
  8849. }
  8850. sstr[c] = '\0';
  8851. strcpy(expiryDatestr, sstr);
  8852. //***(3)idTag ****/
  8853. loc = strstr(sstrtemp, "idTag");
  8854. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8855. c = 0;
  8856. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8857. {
  8858. sstr[c] = loc[3+strlen("idTag")+c];
  8859. c++;
  8860. }
  8861. sstr[c] = '\0';
  8862. strcpy(idTagstr, sstr);
  8863. //***(4)parentIdTag ****/
  8864. loc = strstr(sstrtemp, "parentIdTag");
  8865. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8866. c = 0;
  8867. if(loc == NULL)
  8868. {
  8869. strcpy(parentIdTagstr, "");
  8870. }
  8871. else
  8872. {
  8873. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8874. {
  8875. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8876. c++;
  8877. }
  8878. sstr[c] = '\0';
  8879. strcpy(parentIdTagstr, sstr);
  8880. }
  8881. //***(5)reservationId ****/
  8882. c=0;
  8883. loc = strstr(sstrtemp, "reservationId");
  8884. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8885. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8886. {
  8887. sstr[c] = loc[strlen("reservationId")+2+c];
  8888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8889. c++;
  8890. }
  8891. sstr[c] = '\0';
  8892. reservationIdInt = atoi(sstr);
  8893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8894. /*
  8895. enum SYSTEM_STATUS
  8896. {
  8897. SYS_MODE_BOOTING = 0,
  8898. SYS_MODE_IDLE = 1,
  8899. SYS_MODE_AUTHORIZING = 2,
  8900. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8901. SYS_MODE_REASSIGN = 4,
  8902. SYS_MODE_PREPARING = 5,
  8903. SYS_MODE_PREPARE_FOR_EV = 6,
  8904. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8905. SYS_MODE_CHARGING = 8,
  8906. SYS_MODE_TERMINATING = 9,
  8907. SYS_MODE_COMPLETE = 10,
  8908. SYS_MODE_ALARM = 11,
  8909. SYS_MODE_FAULT = 12,
  8910. SYS_MODE_RESERVATION = 13,
  8911. SYS_MODE_BOOKING = 14,
  8912. SYS_MODE_MAINTAIN = 15,
  8913. SYS_MODE_DEBUG = 16,
  8914. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8915. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8916. SYS_MODE_UPDATE = 19
  8917. };
  8918. */
  8919. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8920. {
  8921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8922. goto end;
  8923. }
  8924. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8925. {
  8926. //check Transaction active
  8927. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8928. {
  8929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8930. {
  8931. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8932. }
  8933. else
  8934. {
  8935. tempIndex = connectorIdInt -1;
  8936. }
  8937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8938. {
  8939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8940. {
  8941. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8942. {
  8943. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8944. {
  8945. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8946. {
  8947. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8949. }
  8950. 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'))
  8951. {
  8952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8953. }
  8954. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8955. {
  8956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8957. }
  8958. else
  8959. {
  8960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8961. }
  8962. }
  8963. 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
  8964. {
  8965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8966. }
  8967. }
  8968. else
  8969. {
  8970. //replace reservation
  8971. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8973. }
  8974. }
  8975. } // END FOR CHAdeMO_QUANTITY
  8976. }
  8977. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8978. {
  8979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8980. {
  8981. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8982. }
  8983. else
  8984. {
  8985. tempIndex = connectorIdInt -1;
  8986. }
  8987. for (int index = 0; index < CCS_QUANTITY; index++)
  8988. {
  8989. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8990. {
  8991. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8992. {
  8993. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8994. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8995. {
  8996. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8997. {
  8998. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9000. }
  9001. 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'))
  9002. {
  9003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9004. }
  9005. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9006. {
  9007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9008. }
  9009. else
  9010. {
  9011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9012. }
  9013. }
  9014. 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
  9015. {
  9016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9017. }
  9018. }
  9019. else
  9020. {
  9021. //replace reservation
  9022. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9024. }
  9025. }
  9026. } // END FOR CCS_QUANTITY
  9027. }
  9028. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9029. {
  9030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9031. {
  9032. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9033. }
  9034. else
  9035. {
  9036. tempIndex = connectorIdInt -1;
  9037. }
  9038. for (int index = 0; index < GB_QUANTITY; index++)
  9039. {
  9040. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9041. {
  9042. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9043. {
  9044. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9045. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9046. {
  9047. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9048. {
  9049. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9051. }
  9052. 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'))
  9053. {
  9054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9055. }
  9056. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9057. {
  9058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9059. }
  9060. else
  9061. {
  9062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9063. }
  9064. }
  9065. 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
  9066. {
  9067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9068. }
  9069. }
  9070. else
  9071. {
  9072. //replace reservation
  9073. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9075. }
  9076. }
  9077. }// END FOR GB_QUANTITY
  9078. }
  9079. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9080. {
  9081. tempIndex = connectorIdInt -1;
  9082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9083. {
  9084. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9085. {
  9086. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9087. {
  9088. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9089. 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
  9090. {
  9091. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9092. {
  9093. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9095. }
  9096. 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'))
  9097. {
  9098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9099. }
  9100. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9101. {
  9102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9103. }
  9104. else
  9105. {
  9106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9107. }
  9108. }
  9109. 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
  9110. {
  9111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9112. }
  9113. }
  9114. else
  9115. {
  9116. //replace reservation
  9117. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9118. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9119. }
  9120. }
  9121. }// END FOR GB_QUANTITY
  9122. }
  9123. else
  9124. {
  9125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9126. {
  9127. tempIndex = 2;
  9128. }
  9129. else
  9130. {
  9131. tempIndex = (connectorIdInt -1);
  9132. }
  9133. for (int index = 0; index < AC_QUANTITY; index++)
  9134. {
  9135. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9136. {
  9137. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9138. {
  9139. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9140. {
  9141. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9142. {
  9143. 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))
  9144. {
  9145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9146. }
  9147. else
  9148. {
  9149. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9151. }
  9152. }
  9153. 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'))
  9154. {
  9155. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9156. }
  9157. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9158. {
  9159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9160. }
  9161. else
  9162. {
  9163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9164. }
  9165. }
  9166. 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
  9167. {
  9168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9169. }
  9170. }
  9171. else
  9172. {
  9173. //replace reservation
  9174. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9176. }
  9177. }
  9178. } // END FOR AC_QUANTITY
  9179. }
  9180. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9181. }
  9182. else if(connectorIdInt == 0)
  9183. {
  9184. //check Transaction active
  9185. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9186. {
  9187. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9188. {
  9189. 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'))
  9190. {
  9191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9192. goto end;
  9193. }
  9194. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9195. {
  9196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9197. goto end;
  9198. }
  9199. 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
  9200. {
  9201. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9202. goto end;
  9203. }
  9204. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9205. {
  9206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9207. goto end;
  9208. }
  9209. }
  9210. }// END FOR CHAdeMO_QUANTITY
  9211. for (int index = 0; index < CCS_QUANTITY; index++)
  9212. {
  9213. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9214. {
  9215. 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'))
  9216. {
  9217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9218. goto end;
  9219. }
  9220. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9221. {
  9222. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9223. goto end;
  9224. }
  9225. 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
  9226. {
  9227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9228. goto end;
  9229. }
  9230. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9231. {
  9232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9233. goto end;
  9234. }
  9235. }
  9236. } // END FOR CCS_QUANTITY
  9237. for (int index = 0; index < GB_QUANTITY; index++)
  9238. {
  9239. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9240. {
  9241. 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'))
  9242. {
  9243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9244. goto end;
  9245. }
  9246. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9247. {
  9248. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9249. goto end;
  9250. }
  9251. 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
  9252. {
  9253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9254. goto end;
  9255. }
  9256. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9257. {
  9258. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9259. goto end;
  9260. }
  9261. }
  9262. } // END FOR GB_QUANTITY
  9263. for (int index = 0; index < AC_QUANTITY; index++)
  9264. {
  9265. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9266. {
  9267. 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'))
  9268. {
  9269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9270. goto end;
  9271. }
  9272. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9273. {
  9274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9275. goto end;
  9276. }
  9277. 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
  9278. {
  9279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9280. goto end;
  9281. }
  9282. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9283. {
  9284. 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))
  9285. {
  9286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9287. goto end;
  9288. }
  9289. }
  9290. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9291. {
  9292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9293. goto end;
  9294. }
  9295. }
  9296. }// END FOR AC_QUANTITY
  9297. //The connectorId is 0
  9298. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9299. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9300. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9301. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9302. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9303. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9304. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9305. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9306. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9307. result = TRUE;
  9308. return result;
  9309. }
  9310. else
  9311. {
  9312. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9313. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9314. }
  9315. if(strcmp(comfirmstr,"Accepted") == 0)
  9316. {
  9317. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9318. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9319. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9320. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9321. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9322. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9323. result = TRUE;
  9324. return result;
  9325. }
  9326. end:
  9327. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9328. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9329. return result;
  9330. }
  9331. int handleResetRequest(char *uuid, char *payload)
  9332. {
  9333. mtrace();
  9334. int result = FAIL;
  9335. char sstr[10]={0},sstrtemp[30]={ 0 };
  9336. char typestr[10]={0};
  9337. char comfirmstr[20]={0};
  9338. int c = 0;
  9339. char *loc;
  9340. DEBUG_INFO("handleResetRequest...\n");
  9341. strcpy(sstrtemp, stringtrimspace(payload));
  9342. loc = strstr(sstrtemp, "type");
  9343. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9344. c = 0;
  9345. while (loc[3+strlen("type")+c] != '\"')
  9346. {
  9347. sstr[c] = loc[3+strlen("type")+c];
  9348. c++;
  9349. }
  9350. sstr[c] = '\0';
  9351. strcpy(typestr,sstr);
  9352. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9353. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9354. {
  9355. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9356. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9357. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9358. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9359. }
  9360. else
  9361. {
  9362. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9363. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9364. result = PASS;
  9365. }
  9366. sendResetConfirmation(uuid, comfirmstr);
  9367. return result;
  9368. }
  9369. int handleSendLocalListRequest(char *uuid, char *payload)
  9370. {
  9371. mtrace();
  9372. int result = FAIL;
  9373. char comfirmstr[20];
  9374. int checkState_Faulted = FALSE;
  9375. json_object *SendLocalList;
  9376. DEBUG_INFO("handleSendLocalListRequest...\n");
  9377. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9378. {
  9379. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9380. goto end;
  9381. }
  9382. //check Charge Point state
  9383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9384. {
  9385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9386. {
  9387. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9388. }
  9389. }
  9390. for (int index = 0; index < CCS_QUANTITY; index++)
  9391. {
  9392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9393. {
  9394. checkState_Faulted = TRUE; //OCPP Status
  9395. }
  9396. }
  9397. for (int index = 0; index < GB_QUANTITY; index++)
  9398. {
  9399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9400. {
  9401. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9402. }
  9403. }
  9404. //check Charge Point state
  9405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9406. {
  9407. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9408. {
  9409. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9410. }
  9411. }
  9412. //check Charge Point state
  9413. for (int index = 0; index < AC_QUANTITY; index++)
  9414. {
  9415. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9416. {
  9417. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9418. }
  9419. }
  9420. if(checkState_Faulted == TRUE)
  9421. {
  9422. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9423. goto end;
  9424. }
  9425. // Parsing payload
  9426. SendLocalList = json_tokener_parse(payload);
  9427. if(!is_error(SendLocalList))
  9428. {
  9429. // Required data
  9430. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9431. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9432. // Optional data
  9433. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9434. {
  9435. //Check UpdateType
  9436. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9437. {
  9438. //Local list full update
  9439. DEBUG_INFO("Local list full update.\n");
  9440. OCPP_getListVerion();
  9441. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9442. {
  9443. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9444. goto end;
  9445. }
  9446. OCPP_cleanLocalList();
  9447. }
  9448. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9449. {
  9450. //Local list different update
  9451. DEBUG_INFO("Local list different update.\n");
  9452. OCPP_getListVerion();
  9453. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9454. {
  9455. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9456. goto end;
  9457. }
  9458. }
  9459. else
  9460. {
  9461. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9462. goto end;
  9463. }
  9464. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9465. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9466. {
  9467. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  9468. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9469. {
  9470. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  9471. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9472. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  9473. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9474. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  9475. }
  9476. // Add to db
  9477. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9478. {
  9479. //Local list full update
  9480. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9481. idx,
  9482. ShmOCPP16Data->SendLocalList.ListVersion,
  9483. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9484. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9485. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9486. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9487. // update list
  9488. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9489. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9490. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9491. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9492. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9493. }
  9494. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9495. {
  9496. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9497. idx,
  9498. ShmOCPP16Data->SendLocalList.ListVersion,
  9499. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9500. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9501. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9502. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9503. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9504. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9505. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9506. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9507. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9508. }
  9509. }
  9510. }
  9511. else
  9512. {
  9513. //Check UpdateType
  9514. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9515. {
  9516. //Local list full update
  9517. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9518. OCPP_cleanLocalList();
  9519. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9520. goto end;
  9521. }
  9522. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9523. {
  9524. //Local list different update
  9525. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9526. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9527. goto end;
  9528. }
  9529. }
  9530. result = PASS;
  9531. }
  9532. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9533. end:
  9534. json_object_put(SendLocalList);
  9535. sendSendLocalListConfirmation(uuid, comfirmstr);
  9536. return result;
  9537. }
  9538. #define MAX 200
  9539. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9540. {
  9541. mtrace();
  9542. int result = FAIL;
  9543. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9544. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9545. char chargingProfilePurposeStr[30]={0};
  9546. char chargingProfileKindStr[16]={0};
  9547. char recurrencyKindStr[10]={0};
  9548. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9549. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9550. int chargingSchedulePeriodCount = 0;
  9551. char comfirmstr[20]={0};
  9552. int meet= FALSE;
  9553. FILE *fptr1;
  9554. char filename[MAX]={0};
  9555. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9556. char rmFileCmd[50]={0};
  9557. char tempchargingProfilePurposeStr[30]={0};
  9558. char word[1600]={0};
  9559. int n_chargingProfile = 0;
  9560. json_object *SetChargingProfile;
  9561. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9562. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9563. SetChargingProfile = json_tokener_parse(payload);
  9564. if(!is_error(SetChargingProfile))
  9565. {
  9566. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9567. {
  9568. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9569. if(connectorIdInt == 0)
  9570. {
  9571. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9572. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9573. }
  9574. else
  9575. {
  9576. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9577. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9578. }
  9579. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9580. }
  9581. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9582. {
  9583. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9584. {
  9585. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9586. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9587. {
  9588. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9589. }
  9590. else
  9591. {
  9592. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9593. }
  9594. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9595. }
  9596. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9597. {
  9598. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9599. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9600. {
  9601. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9602. }
  9603. else
  9604. {
  9605. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9606. }
  9607. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9608. }
  9609. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9610. {
  9611. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9612. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9613. {
  9614. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9615. }
  9616. else
  9617. {
  9618. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9619. }
  9620. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9621. }
  9622. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9623. {
  9624. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9625. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9626. {
  9627. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9628. }
  9629. else
  9630. {
  9631. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9632. }
  9633. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9634. }
  9635. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9636. {
  9637. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9638. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9639. {
  9640. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9641. }
  9642. else
  9643. {
  9644. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9645. }
  9646. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9647. }
  9648. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9649. {
  9650. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9651. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9652. {
  9653. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9654. }
  9655. else
  9656. {
  9657. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9658. }
  9659. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9660. }
  9661. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9662. {
  9663. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9664. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9665. {
  9666. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9667. }
  9668. else
  9669. {
  9670. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9671. }
  9672. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9673. }
  9674. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9675. {
  9676. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9677. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9678. {
  9679. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9680. }
  9681. else
  9682. {
  9683. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9684. }
  9685. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9686. }
  9687. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9688. {
  9689. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9690. {
  9691. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9692. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9693. {
  9694. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9695. }
  9696. else
  9697. {
  9698. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9699. }
  9700. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9701. }
  9702. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9703. {
  9704. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9705. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9706. {
  9707. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9708. }
  9709. else
  9710. {
  9711. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9712. }
  9713. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9714. }
  9715. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9716. {
  9717. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9718. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9719. {
  9720. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9721. }
  9722. else
  9723. {
  9724. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9725. }
  9726. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9727. }
  9728. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9729. {
  9730. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9731. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9732. {
  9733. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9734. }
  9735. else
  9736. {
  9737. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9738. }
  9739. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9740. }
  9741. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9742. {
  9743. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9744. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9745. if(chargingSchedulePeriodCount <= 10)
  9746. {
  9747. 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++)
  9748. {
  9749. 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)
  9750. {
  9751. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  9752. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9753. {
  9754. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9755. }
  9756. else
  9757. {
  9758. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9759. }
  9760. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9761. }
  9762. 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)
  9763. {
  9764. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  9765. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9766. {
  9767. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9768. }
  9769. else
  9770. {
  9771. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9772. }
  9773. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9774. }
  9775. 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)
  9776. {
  9777. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  9778. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9779. {
  9780. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9781. }
  9782. else
  9783. {
  9784. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9785. }
  9786. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9787. }
  9788. }
  9789. }
  9790. }
  9791. }
  9792. }
  9793. }
  9794. json_object_put(SetChargingProfile);
  9795. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9796. {
  9797. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9798. goto end;
  9799. }
  9800. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9801. {
  9802. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9803. if(connectorIdInt != 0)
  9804. {
  9805. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9806. goto end;
  9807. }
  9808. strcpy(filename, ChargePointMaxProfile_JSON );
  9809. fptr1 = fopen(filename, "r");
  9810. if (!fptr1)
  9811. {
  9812. //file not exist
  9813. DEBUG_INFO("Unable to open the input file!!\n");
  9814. fptr1 = fopen(filename, "w+");
  9815. }
  9816. else
  9817. {
  9818. //Check Charging Profile Count
  9819. while(fscanf(fptr1, "%s", word) != EOF)
  9820. {
  9821. //DEBUG_INFO("word=%s\n",word);
  9822. if(strstr(word, "chargingProfileId")!= NULL)
  9823. {
  9824. //DEBUG_INFO("test chargingProfileId \n");
  9825. n_chargingProfile = n_chargingProfile + 1;
  9826. //DEBUG_INFO("chargingProfileId Found\n");
  9827. }
  9828. }
  9829. }
  9830. fclose(fptr1);
  9831. }
  9832. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9833. {
  9834. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9835. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9836. {
  9837. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9838. goto end;
  9839. }
  9840. memset(filename, 0, ARRAY_SIZE(filename));
  9841. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9842. fptr1 = fopen(filename, "r");
  9843. if (!fptr1)
  9844. {
  9845. //file not exist
  9846. //DEBUG_INFO("Unable to open the input file!!\n");
  9847. fptr1 = fopen(filename, "w+");
  9848. }
  9849. else
  9850. {
  9851. //Check Charging Profile Count
  9852. while(fscanf(fptr1, "%s", word) != EOF)
  9853. {
  9854. //DEBUG_INFO("word=%s\n",word);
  9855. if(strstr(word, "chargingProfileId")!= NULL)
  9856. {
  9857. //DEBUG_INFO("test chargingProfileId \n");
  9858. n_chargingProfile = n_chargingProfile + 1;
  9859. //DEBUG_INFO("chargingProfileId Found\n");
  9860. }
  9861. }
  9862. }
  9863. fclose(fptr1);
  9864. }
  9865. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9866. {
  9867. //printf("set chargingProfile 1-4\n");
  9868. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9869. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9870. if(connectorIdInt == 0)
  9871. {
  9872. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9873. goto end;
  9874. }
  9875. int tempIndex = 0;
  9876. //check Transaction active
  9877. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9878. {
  9879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9880. {
  9881. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9882. }
  9883. else
  9884. {
  9885. tempIndex = connectorIdInt -1;
  9886. }
  9887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9888. {
  9889. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9890. {
  9891. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9892. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9893. {
  9894. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9895. {
  9896. meet = TRUE;
  9897. break;
  9898. }
  9899. }
  9900. }
  9901. }
  9902. }
  9903. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9904. {
  9905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9906. {
  9907. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9908. }
  9909. else
  9910. {
  9911. tempIndex = connectorIdInt -1;
  9912. }
  9913. for (int index = 0; index < CCS_QUANTITY; index++)
  9914. {
  9915. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9916. {
  9917. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9918. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9919. {
  9920. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9921. {
  9922. meet = TRUE;
  9923. break;
  9924. }
  9925. }
  9926. }
  9927. }
  9928. }
  9929. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9930. {
  9931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9932. {
  9933. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9934. }
  9935. else
  9936. {
  9937. tempIndex = connectorIdInt -1;
  9938. }
  9939. for (int index = 0; index < GB_QUANTITY; index++)
  9940. {
  9941. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9942. {
  9943. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9944. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9945. {
  9946. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9947. {
  9948. meet = TRUE;
  9949. break;
  9950. }
  9951. }
  9952. }
  9953. }
  9954. }
  9955. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9956. {
  9957. tempIndex = connectorIdInt -1;
  9958. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9959. {
  9960. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9961. {
  9962. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9963. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9964. {
  9965. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9966. {
  9967. meet = TRUE;
  9968. break;
  9969. }
  9970. }
  9971. }
  9972. }
  9973. }
  9974. else
  9975. {
  9976. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9977. {
  9978. tempIndex = 2;
  9979. }
  9980. else
  9981. {
  9982. tempIndex = (connectorIdInt -1);
  9983. }
  9984. for (int index = 0; index < AC_QUANTITY; index++)
  9985. {
  9986. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9987. {
  9988. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9989. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9990. {
  9991. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9992. {
  9993. meet = TRUE;
  9994. break;
  9995. }
  9996. }
  9997. }
  9998. }
  9999. }
  10000. //check Transaction active
  10001. if(meet == FALSE)
  10002. {
  10003. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10004. goto end;
  10005. }
  10006. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10007. {
  10008. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10009. goto end;
  10010. }
  10011. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10012. fptr1 = fopen(filename, "r");
  10013. if (!fptr1)
  10014. {
  10015. //file not exist
  10016. DEBUG_INFO("Unable to open the input file!!\n");
  10017. fptr1 = fopen(filename, "w+");
  10018. }
  10019. else
  10020. {
  10021. //Check Charging Profile Count
  10022. while(fscanf(fptr1, "%s", word) != EOF)
  10023. {
  10024. //DEBUG_INFO("word=%s\n",word);
  10025. if(strstr(word, "chargingProfileId")!= NULL)
  10026. {
  10027. //DEBUG_INFO("test chargingProfileId \n");
  10028. n_chargingProfile = n_chargingProfile + 1;
  10029. //DEBUG_INFO("chargingProfileId Found\n");
  10030. }
  10031. }
  10032. }
  10033. fclose(fptr1);
  10034. }
  10035. // Check ChargeProfileMaxStackLevel
  10036. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10037. {
  10038. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10039. goto end;
  10040. }
  10041. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10042. {
  10043. int i = 0;
  10044. char fnametemp[200]={0};
  10045. n_chargingProfile = 0;
  10046. //Check ChargePointMaxProfile.json exit
  10047. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10048. {
  10049. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10050. //Check Charging Profile Count
  10051. while(fscanf(fptr1, "%s", word) != EOF)
  10052. {
  10053. //DEBUG_INFO("word=%s\n",word);
  10054. if(strstr(word, "chargingProfileId")!= NULL)
  10055. {
  10056. //DEBUG_INFO("test chargingProfileId \n");
  10057. n_chargingProfile = n_chargingProfile + 1;
  10058. i = i + 1;
  10059. //DEBUG_INFO("chargingProfileId Found\n");
  10060. }
  10061. memset(word, 0, ARRAY_SIZE(word));
  10062. }
  10063. fclose(fptr1);
  10064. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10065. }
  10066. //Check TxDefaultProfile_0.json exit
  10067. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10068. {
  10069. i = 0;
  10070. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10071. //Check Charging Profile Count
  10072. while(fscanf(fptr1, "%s", word) != EOF)
  10073. {
  10074. //DEBUG_INFO("word=%s\n",word);
  10075. if(strstr(word, "chargingProfileId")!= NULL)
  10076. {
  10077. //DEBUG_INFO("test chargingProfileId \n");
  10078. n_chargingProfile = n_chargingProfile + 1;
  10079. i = i + 1;
  10080. //DEBUG_INFO("chargingProfileId Found\n");
  10081. }
  10082. memset(word, 0, ARRAY_SIZE(word));
  10083. }
  10084. fclose(fptr1);
  10085. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10086. }
  10087. //Check TxDefaultProfile_%d.json
  10088. for(int j=1; j <= gunTotalNumber; j++)
  10089. {
  10090. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10091. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10092. if((access(fnametemp,F_OK))!=-1)
  10093. {
  10094. i = 0;
  10095. fptr1 = fopen(fnametemp, "r");
  10096. //Check Charging Profile Count
  10097. while(fscanf(fptr1, "%s", word) != EOF)
  10098. {
  10099. //DEBUG_INFO("word=%s\n",word);
  10100. if(strstr(word, "chargingProfileId")!= NULL)
  10101. {
  10102. //DEBUG_INFO("test chargingProfileId \n");
  10103. n_chargingProfile = n_chargingProfile + 1;
  10104. i = i + 1;
  10105. //DEBUG_INFO("chargingProfileId Found\n");
  10106. }
  10107. memset(word, 0, ARRAY_SIZE(word));
  10108. }
  10109. fclose(fptr1);
  10110. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10111. }
  10112. }
  10113. //Check TxProfile_%d.json
  10114. for(int j=1; j <= gunTotalNumber; j++)
  10115. {
  10116. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10117. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10118. if((access(fnametemp,F_OK))!=-1)
  10119. {
  10120. i = 0;
  10121. fptr1 = fopen(fnametemp, "r");
  10122. //Check Charging Profile Count
  10123. while(fscanf(fptr1, "%s", word) != EOF)
  10124. {
  10125. //DEBUG_INFO("word=%s\n",word);
  10126. if(strstr(word, "chargingProfileId")!= NULL)
  10127. {
  10128. //DEBUG_INFO("test chargingProfileId \n");
  10129. n_chargingProfile = n_chargingProfile + 1;
  10130. i = i + 1;
  10131. //DEBUG_INFO("chargingProfileId Found\n");
  10132. }
  10133. memset(word, 0, ARRAY_SIZE(word));
  10134. }
  10135. fclose(fptr1);
  10136. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10137. }
  10138. }
  10139. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10140. {
  10141. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10142. goto end;
  10143. }
  10144. }
  10145. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10146. //**********************************Write to File********************************************************/
  10147. FILE *infile;
  10148. FILE *outfile;
  10149. infile = fopen (filename, "r");
  10150. outfile = fopen (tempfile, "w");
  10151. int d =0;
  10152. d = fgetc(infile);
  10153. rewind(infile);
  10154. if(d == EOF)
  10155. {
  10156. // Profile is empty
  10157. fprintf(outfile,"%s\n",payload);
  10158. fclose(infile);
  10159. fclose(outfile);
  10160. sprintf(rmFileCmd,"rm -f %s",filename);
  10161. system(rmFileCmd);
  10162. rename(tempfile, filename);
  10163. }
  10164. else
  10165. {
  10166. // Profile is not empty
  10167. char buf[2048]={0};
  10168. int ChargingProfileAdded = FALSE;
  10169. while (fgets(buf, sizeof(buf), infile) != NULL)
  10170. {
  10171. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10172. json_object *tmpChargingProfile;
  10173. tmpChargingProfile = json_tokener_parse(buf);
  10174. if(!is_error(SetChargingProfile))
  10175. {
  10176. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10177. {
  10178. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10179. }
  10180. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10181. {
  10182. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10183. {
  10184. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10185. }
  10186. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10187. {
  10188. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10189. }
  10190. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10191. {
  10192. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10193. }
  10194. }
  10195. }
  10196. json_object_put(tmpChargingProfile);
  10197. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10198. {
  10199. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10200. {
  10201. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10202. if(ChargingProfileAdded == FALSE)
  10203. {
  10204. fprintf(outfile,"%s\n",payload);
  10205. ChargingProfileAdded = TRUE;
  10206. }
  10207. }
  10208. else
  10209. {
  10210. if(tempstackLevelInt < stackLevelInt)
  10211. {
  10212. if(ChargingProfileAdded == FALSE)
  10213. {
  10214. fprintf(outfile,"%s\n",buf);
  10215. fprintf(outfile,"%s\n",payload);
  10216. ChargingProfileAdded = TRUE;
  10217. }
  10218. else
  10219. {
  10220. fprintf(outfile,"%s\n",buf);
  10221. }
  10222. }
  10223. else
  10224. {
  10225. if(ChargingProfileAdded == FALSE)
  10226. {
  10227. fprintf(outfile,"%s\n",buf);
  10228. fprintf(outfile,"%s\n",payload);
  10229. ChargingProfileAdded = TRUE;
  10230. }
  10231. else
  10232. {
  10233. fprintf(outfile,"%s\n",buf);
  10234. }
  10235. }
  10236. }
  10237. }
  10238. else
  10239. {
  10240. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10241. {
  10242. if(ChargingProfileAdded == FALSE)
  10243. {
  10244. fprintf(outfile,"%s\n",buf);
  10245. fprintf(outfile,"%s\n",payload);
  10246. ChargingProfileAdded = TRUE;
  10247. }
  10248. else
  10249. {
  10250. fprintf(outfile,"%s\n",buf);
  10251. }
  10252. }
  10253. else if(tempstackLevelInt < stackLevelInt)
  10254. {
  10255. if(ChargingProfileAdded == FALSE)
  10256. {
  10257. fprintf(outfile,"%s\n",buf);
  10258. fprintf(outfile,"%s\n",payload);
  10259. ChargingProfileAdded = TRUE;
  10260. }
  10261. else
  10262. {
  10263. fprintf(outfile,"%s\n",buf);
  10264. }
  10265. }
  10266. else
  10267. {
  10268. if(ChargingProfileAdded == FALSE)
  10269. {
  10270. fprintf(outfile,"%s\n",buf);
  10271. fprintf(outfile,"%s\n",payload);
  10272. ChargingProfileAdded = TRUE;
  10273. }
  10274. else
  10275. {
  10276. fprintf(outfile,"%s\n",buf);
  10277. }
  10278. }
  10279. }
  10280. } // end of while loop
  10281. fclose(infile);
  10282. fclose(outfile);
  10283. sprintf(rmFileCmd,"rm -f %s",filename);
  10284. system(rmFileCmd);
  10285. rename(tempfile, filename);
  10286. }
  10287. sleep(1);
  10288. result = TRUE;
  10289. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10290. end:
  10291. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10292. {
  10293. if(connectorIdInt == 0)
  10294. {
  10295. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10296. {
  10297. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10298. }
  10299. }
  10300. else
  10301. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10302. }
  10303. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10304. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10305. return result;
  10306. }
  10307. int handleTriggerMessageRequest(char *uuid, char *payload)
  10308. {
  10309. mtrace();
  10310. int result = FAIL;
  10311. int connectorIdIsNULL = FALSE;
  10312. int connectorIdInt =0;
  10313. char sstr[40]={0},sstrtemp[100]={ 0 };
  10314. char requestedMessagestr[40]={0};
  10315. char comfirmstr[20]={0};
  10316. int c = 0;
  10317. char *loc;
  10318. DEBUG_INFO("handleTriggerMessageRequest\n");
  10319. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10320. strcpy(sstrtemp, stringtrimspace(payload));
  10321. c = 0;
  10322. loc = strstr(sstrtemp, "requestedMessage");
  10323. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10324. {
  10325. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10326. c++;
  10327. }
  10328. sstr[c] = '\0';
  10329. strcpy(requestedMessagestr, sstr);
  10330. c = 0;
  10331. loc = strstr(sstrtemp, "connectorId");
  10332. if(loc == NULL)
  10333. {
  10334. connectorIdIsNULL = TRUE;
  10335. }
  10336. else
  10337. {
  10338. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10339. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10340. {
  10341. sstr[c] = loc[strlen("connectorId")+2+c];
  10342. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10343. c++;
  10344. }
  10345. sstr[c] = '\0';
  10346. connectorIdInt = atoi(sstr);
  10347. }
  10348. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10349. {
  10350. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10351. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10352. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10353. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10354. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10355. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10356. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10357. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10358. {
  10359. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10360. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10361. return TRUE;
  10362. }
  10363. else
  10364. {
  10365. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10366. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10367. }
  10368. }
  10369. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10370. {
  10371. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10372. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10373. return TRUE;
  10374. }
  10375. //==========================
  10376. // Trigger message
  10377. //==========================
  10378. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10379. {
  10380. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10381. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10382. {
  10383. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10384. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10385. }
  10386. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10387. }
  10388. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10389. {
  10390. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10391. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10392. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10393. }
  10394. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10395. {
  10396. //sendBootNotificationRequest();
  10397. server_sign = FALSE;
  10398. }
  10399. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10400. {
  10401. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10402. }
  10403. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10404. {
  10405. if(connectorIdIsNULL == FALSE)
  10406. {
  10407. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10408. {
  10409. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10410. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10411. }
  10412. }
  10413. else
  10414. {
  10415. for(int idx=0;idx< gunTotalNumber;idx++)
  10416. {
  10417. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10418. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10419. }
  10420. }
  10421. }
  10422. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10423. {
  10424. if(connectorIdIsNULL == FALSE)
  10425. {
  10426. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  10427. {
  10428. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10429. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  10430. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10431. }
  10432. }
  10433. else
  10434. {
  10435. for(int idx=0;idx< gunTotalNumber;idx++)
  10436. {
  10437. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10438. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10439. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10440. }
  10441. }
  10442. }
  10443. return result;
  10444. }
  10445. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10446. {
  10447. mtrace();
  10448. int result = FAIL;
  10449. int connectorIdInt =0;
  10450. char comfirmstr[20]={0};
  10451. int tempIndex = 0;
  10452. json_object *UnlockConnector;
  10453. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10454. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10455. UnlockConnector = json_tokener_parse(payload);
  10456. if(!is_error(UnlockConnector))
  10457. {
  10458. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10459. {
  10460. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10461. }
  10462. }
  10463. json_object_put(UnlockConnector);
  10464. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10465. if(gunTotalNumber == 0)
  10466. {
  10467. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10468. goto end;
  10469. }
  10470. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10471. {
  10472. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10473. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10474. goto end;
  10475. }
  10476. else
  10477. {
  10478. //check Transaction active
  10479. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10480. {
  10481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10482. {
  10483. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10484. }
  10485. else
  10486. {
  10487. tempIndex = connectorIdInt -1;
  10488. }
  10489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10490. {
  10491. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10492. {
  10493. //stop Transaction
  10494. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10495. }
  10496. }
  10497. }
  10498. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10499. {
  10500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10501. {
  10502. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10503. }
  10504. else
  10505. {
  10506. tempIndex = connectorIdInt -1;
  10507. }
  10508. for (int index = 0; index < CCS_QUANTITY; index++)
  10509. {
  10510. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10511. {
  10512. //stop Transaction
  10513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10514. }
  10515. }
  10516. }
  10517. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10518. {
  10519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10520. {
  10521. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10522. }
  10523. else
  10524. {
  10525. tempIndex = connectorIdInt -1;
  10526. }
  10527. for (int index = 0; index < GB_QUANTITY; index++)
  10528. {
  10529. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10530. {
  10531. //stop Transaction
  10532. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10533. }
  10534. }
  10535. }
  10536. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10537. {
  10538. tempIndex = connectorIdInt -1;
  10539. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10540. {
  10541. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  10542. {
  10543. //stop Transaction
  10544. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10545. }
  10546. }
  10547. }
  10548. else
  10549. {
  10550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10551. {
  10552. tempIndex = 2;
  10553. }
  10554. else
  10555. {
  10556. tempIndex = connectorIdInt-1;
  10557. }
  10558. for (int index = 0; index < AC_QUANTITY; index++)
  10559. {
  10560. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10561. {
  10562. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10563. }
  10564. }
  10565. }
  10566. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10567. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10568. result = TRUE;
  10569. return result;
  10570. }
  10571. end:
  10572. //json_object_put(obj); --- remove temporally
  10573. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10574. return result;
  10575. }
  10576. static char UpdateFirmwarepayloadData[300]={0};
  10577. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10578. {
  10579. mtrace();
  10580. int result = FAIL;
  10581. pthread_t t;
  10582. sendUpdateFirmwareConfirmation(uuid);
  10583. memset(UpdateFirmwarepayloadData, 0, 300);
  10584. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10585. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10586. ////pthread_join(t, NULL); //
  10587. //pthread_detach(t);
  10588. //sendUpdateFirmwareConfirmation(uuid);
  10589. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10590. return result;
  10591. }
  10592. void *UpdateFirmwareProcess(void *data)
  10593. {
  10594. pthread_detach(pthread_self());
  10595. mtrace();
  10596. int retriesInt =0, retryIntervalInt=0;
  10597. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10598. int port=0;
  10599. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10600. int isSuccess = 0;
  10601. char ftpbuf[1024];
  10602. char temp[1024];
  10603. char * pch;
  10604. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10605. json_object *UpdateFirmware;
  10606. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10607. if(!is_error(UpdateFirmware))
  10608. {
  10609. // Required data
  10610. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10611. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10612. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10613. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10614. // Optional data
  10615. if(json_object_object_get(UpdateFirmware, "retries"))
  10616. {
  10617. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10618. }
  10619. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10620. {
  10621. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10622. }
  10623. }
  10624. json_object_put(UpdateFirmware);
  10625. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10626. memset(path, 0, ARRAY_SIZE(path));
  10627. // Wait retrieveData
  10628. if(strlen(retrieveDatestr) > 10)
  10629. {
  10630. do
  10631. {
  10632. sleep(1);
  10633. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10634. }
  10635. // Ready to download
  10636. system("rm -f /mnt/*");
  10637. if(strncmp(locationstr,"http", 4) == 0)
  10638. {
  10639. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10640. sprintf(ftppath,"/%s", path);
  10641. DEBUG_INFO("locationstr: %s\n", locationstr);
  10642. DEBUG_INFO("protocol: %s\n",protocol);
  10643. DEBUG_INFO("host: %s\n",host);
  10644. DEBUG_INFO("path: %s\n",path);
  10645. DEBUG_INFO("ftppath: %s\n",ftppath);
  10646. int ftppathlen=strlen(ftppath);
  10647. int i=1;
  10648. char filenametemp[50];
  10649. while(i < ftppathlen)
  10650. {
  10651. int len=ftppathlen-i;
  10652. if(ftppath[len]== 47) // '/' ascll code: 47
  10653. {
  10654. DEBUG_INFO("compare '/' all right\n");
  10655. break;
  10656. }
  10657. i=i+1;
  10658. }
  10659. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10660. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10661. filenametemp[i+1] = 0;
  10662. do
  10663. {
  10664. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10665. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10666. sleep(1);
  10667. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10668. if(!isSuccess)
  10669. {
  10670. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10671. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10672. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10673. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10674. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10675. }
  10676. else
  10677. {
  10678. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10679. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10680. }
  10681. retriesInt--;
  10682. }while((isSuccess == 0)&&(retriesInt >= 0));
  10683. }
  10684. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10685. {
  10686. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10687. memset(temp, 0, ARRAY_SIZE(temp));
  10688. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10689. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10690. int ftppathlen=strlen(ftpbuf);
  10691. int i=1;
  10692. char filenametemp[50];
  10693. while(i < ftppathlen)
  10694. {
  10695. int len=ftppathlen-i;
  10696. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10697. {
  10698. DEBUG_INFO(" compare '/' all right\n");
  10699. break;
  10700. }
  10701. i=i+1;
  10702. }
  10703. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10704. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10705. filenametemp[i+1] = 0;
  10706. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10707. pch=strchr(temp,'@');
  10708. if(pch==NULL)
  10709. {
  10710. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10711. protocol, host, &port, path);
  10712. strcpy(user,"anonymous");
  10713. strcpy(password,"");
  10714. }
  10715. else
  10716. {
  10717. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10718. protocol, user, password, host, &port, path);
  10719. }
  10720. sscanf(host,"%[^/]%s",host1, path1);
  10721. sprintf(ftppath,"%s", path1);
  10722. //DEBUG_INFO("protocol =%s\n",protocol);
  10723. //DEBUG_INFO("user =%s\n",user);
  10724. //DEBUG_INFO("password =%s\n",password);
  10725. //DEBUG_INFO("host1 =%s\n",host1);
  10726. //DEBUG_INFO("port =%d\n",port);
  10727. //DEBUG_INFO("path1 =%s\n",path1);
  10728. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10729. //ftpFile(host, user, password, port, ftppath, fname);
  10730. //download firmware pthred
  10731. if(port == 0)
  10732. {
  10733. port = 21;
  10734. }
  10735. do
  10736. {
  10737. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10738. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10739. sleep(1);
  10740. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10741. if(!isSuccess)
  10742. {
  10743. //BulldogUtil.sleepMs(interval*1000);
  10744. DEBUG_INFO("Update firmware request and download file fail.\n");
  10745. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10746. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10747. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10748. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10749. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10750. }
  10751. else
  10752. {
  10753. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10754. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10755. }
  10756. retriesInt--;
  10757. }while((!isSuccess)&&(retriesInt >= 0));
  10758. }
  10759. else
  10760. {
  10761. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10762. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10763. sleep(1);
  10764. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10765. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10766. }
  10767. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10768. pthread_exit(NULL);
  10769. }
  10770. int handleCertificateSignedRequest(char *uuid, char *payload)
  10771. {
  10772. mtrace();
  10773. int result = PASS;
  10774. json_object *CertificateSigned;
  10775. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10776. CertificateSigned = json_tokener_parse(payload);
  10777. if(!is_error(CertificateSigned))
  10778. {
  10779. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10780. }
  10781. json_object_put(CertificateSigned);
  10782. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10783. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10784. fclose(fp);
  10785. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10786. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10787. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10788. sendCertificateSignedConfirmation(uuid);
  10789. return result;
  10790. }
  10791. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10792. {
  10793. mtrace();
  10794. int result = PASS;
  10795. json_object *DeleteCertificate;
  10796. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10797. DeleteCertificate = json_tokener_parse(payload);
  10798. if(!is_error(DeleteCertificate))
  10799. {
  10800. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10801. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10802. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10803. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10804. }
  10805. json_object_put(DeleteCertificate);
  10806. /*
  10807. * TODO: Delete certificateSigned process
  10808. */
  10809. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10810. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10811. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10812. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10813. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10814. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10815. sendDeleteCertificateConfirmation(uuid);
  10816. return result;
  10817. }
  10818. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10819. {
  10820. mtrace();
  10821. int result = PASS;
  10822. json_object *ExtendedTriggerMessage;
  10823. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10824. ExtendedTriggerMessage = json_tokener_parse(payload);
  10825. if(!is_error(ExtendedTriggerMessage))
  10826. {
  10827. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10828. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10829. {
  10830. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10831. }
  10832. else
  10833. {
  10834. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10835. }
  10836. }
  10837. json_object_put(ExtendedTriggerMessage);
  10838. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10839. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10840. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10841. {
  10842. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10843. }
  10844. else
  10845. {
  10846. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10847. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10848. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10849. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10850. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10851. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10852. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10853. {
  10854. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10855. }
  10856. else
  10857. {
  10858. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10859. }
  10860. }
  10861. sendExtendedTriggerMessageConfirmation(uuid);
  10862. //==========================
  10863. // Trigger message
  10864. //==========================
  10865. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10866. {
  10867. //sendBootNotificationRequest();
  10868. server_sign = FALSE;
  10869. }
  10870. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10871. {
  10872. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10873. }
  10874. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10875. {
  10876. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10877. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10878. {
  10879. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10880. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10881. }
  10882. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10883. }
  10884. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10885. {
  10886. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10887. }
  10888. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10889. {
  10890. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10891. {
  10892. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10893. }
  10894. else
  10895. {
  10896. for(int idx=0;idx< gunTotalNumber;idx++)
  10897. {
  10898. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10899. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10900. }
  10901. }
  10902. }
  10903. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10904. {
  10905. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10906. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10907. {
  10908. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  10909. }
  10910. }
  10911. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10912. {
  10913. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10914. {
  10915. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10916. }
  10917. else
  10918. {
  10919. for(int idx=0;idx< gunTotalNumber;idx++)
  10920. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10921. }
  10922. }
  10923. return result;
  10924. }
  10925. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10926. {
  10927. mtrace();
  10928. int result = PASS;
  10929. json_object *GetInstalledCertificateIds;
  10930. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10931. GetInstalledCertificateIds = json_tokener_parse(payload);
  10932. if(!is_error(GetInstalledCertificateIds))
  10933. {
  10934. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10935. }
  10936. json_object_put(GetInstalledCertificateIds);
  10937. /*
  10938. * TODO: Return installed certificate process
  10939. */
  10940. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10941. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10942. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10943. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10944. sendGetInstalledCertificateIdsConfirmation(uuid);
  10945. return result;
  10946. }
  10947. int handleGetLogRequest(char *uuid, char *payload)
  10948. {
  10949. mtrace();
  10950. int result = PASS;
  10951. json_object *GetLog;
  10952. DEBUG_INFO("handleGetLogRequest...\n");
  10953. GetLog = json_tokener_parse(payload);
  10954. if(!is_error(GetLog))
  10955. {
  10956. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10957. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10958. if(json_object_object_get(GetLog, "retries") != NULL)
  10959. {
  10960. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10961. }
  10962. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10963. {
  10964. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10965. }
  10966. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10967. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10968. {
  10969. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10970. }
  10971. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10972. {
  10973. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10974. }
  10975. }
  10976. json_object_put(GetLog);
  10977. /*
  10978. * TODO: Upload log process
  10979. */
  10980. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10981. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10982. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10983. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10984. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10985. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10986. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10987. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10988. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10989. sendGetLogConfirmation(uuid);
  10990. return result;
  10991. }
  10992. int handleInstallCertificateRequest(char *uuid, char *payload)
  10993. {
  10994. mtrace();
  10995. int result = PASS;
  10996. json_object *InstallCertificate;
  10997. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10998. InstallCertificate = json_tokener_parse(payload);
  10999. if(!is_error(InstallCertificate))
  11000. {
  11001. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11002. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11003. /*
  11004. * TODO: Install certificate process
  11005. */
  11006. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11007. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11008. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11009. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11010. sendInstallCertificateConfirmation(uuid);
  11011. }
  11012. json_object_put(InstallCertificate);
  11013. return result;
  11014. }
  11015. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11016. {
  11017. mtrace();
  11018. int result = PASS;
  11019. json_object *SignedUpdateFirmware;
  11020. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11021. SignedUpdateFirmware = json_tokener_parse(payload);
  11022. if(!is_error(SignedUpdateFirmware))
  11023. {
  11024. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11025. {
  11026. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11027. }
  11028. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11029. {
  11030. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11031. }
  11032. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11033. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11034. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11035. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11036. {
  11037. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11038. }
  11039. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11040. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11041. }
  11042. json_object_put(SignedUpdateFirmware);
  11043. /*
  11044. * TODO: Upgrade firmware process
  11045. */
  11046. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11047. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11048. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11049. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11050. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11051. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11052. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11053. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11054. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11055. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11056. sendInstallCertificateConfirmation(uuid);
  11057. return result;
  11058. }
  11059. int handleUnknownRequest(char *uuid, char *payload)
  11060. {
  11061. mtrace();
  11062. int result = PASS;
  11063. DEBUG_INFO("handleUnknownRequest...\n");
  11064. sendUnknownConfirmation(uuid);
  11065. result = PASS;
  11066. return result;
  11067. }
  11068. //==========================================
  11069. // Handle server response routine
  11070. //==========================================
  11071. void handleAuthorizeResponse(char *payload, int gun_index)
  11072. {
  11073. mtrace();
  11074. char expiryDatestr[30]={0};
  11075. char parentIdTagstr[20]={0};
  11076. char statusstr[20]={0};
  11077. int expiryDateISNULL=FALSE;
  11078. int parentIdTagISNULL=FALSE;
  11079. DEBUG_INFO("handleAuthorizeResponse...\n");
  11080. json_object *Authorize;
  11081. Authorize = json_tokener_parse(payload);
  11082. if(!is_error(Authorize))
  11083. {
  11084. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11085. {
  11086. // Required data
  11087. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11088. // Optional data
  11089. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11090. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11091. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11092. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11093. }
  11094. }
  11095. json_object_put(Authorize);
  11096. if(expiryDateISNULL == FALSE)
  11097. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11098. if(parentIdTagISNULL == FALSE)
  11099. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11100. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11101. //Update idTag information to authorization cache if supproted
  11102. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11103. {
  11104. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11105. }
  11106. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11107. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11108. authorizeRetryTimes = 0;
  11109. }
  11110. void handleBootNotificationResponse(char *payload, int gun_index)
  11111. {
  11112. mtrace();
  11113. char statusStr[12]={0};
  11114. char currentTimeStr[30]={0};
  11115. int intervalInt = 0;
  11116. DEBUG_INFO("handleBootNotificationResponse...\n");
  11117. json_object *BootNotification;
  11118. BootNotification = json_tokener_parse(payload);
  11119. if(!is_error(BootNotification))
  11120. {
  11121. // Required data
  11122. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11123. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11124. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11125. }
  11126. json_object_put(BootNotification);
  11127. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11128. BootNotificationInterval = intervalInt;
  11129. HeartBeatWaitTime = intervalInt;
  11130. //write back to ShmOCPP16Data->BootNotification
  11131. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11132. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11133. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11134. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11135. {
  11136. server_sign = TRUE;
  11137. server_pending =FALSE;
  11138. }
  11139. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11140. {
  11141. server_pending = TRUE;
  11142. }
  11143. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11144. srand(time(NULL));
  11145. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11146. SetOcppConnStatus(TRUE);
  11147. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11148. }
  11149. void handleDataTransferResponse(char *payload, int gun_index)
  11150. {
  11151. char sstr[160]={0};//sstr[200]={ 0 };
  11152. int c = 0;
  11153. char *loc;
  11154. DEBUG_INFO("handleDataTransferResponse ...\n");
  11155. loc = strstr(payload, "status");
  11156. c = 0;
  11157. while (loc[3+strlen("status")+c] != '\"')
  11158. {
  11159. sstr[c] = loc[3+strlen("status")+c];
  11160. c++;
  11161. }
  11162. sstr[c] = '\0';
  11163. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11164. }
  11165. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11166. {
  11167. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11168. //struct json_object *obj;
  11169. // obj = json_tokener_parse(payload);
  11170. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11171. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11172. //No fields are defined.
  11173. }
  11174. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11175. {
  11176. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11177. //struct json_object *obj;
  11178. // obj = json_tokener_parse(payload);
  11179. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11180. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11181. //No fields are defined.
  11182. }
  11183. void handleHeartbeatResponse(char *payload, int gun_index)
  11184. {
  11185. mtrace();
  11186. DEBUG_INFO("handleHeartbeatResponse...\n");
  11187. json_object *Heartbeat;
  11188. Heartbeat = json_tokener_parse(payload);
  11189. if(!is_error(Heartbeat))
  11190. {
  11191. // Required data
  11192. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11193. }
  11194. json_object_put(Heartbeat);
  11195. if(FirstHeartBeat == 0)
  11196. {
  11197. FirstHeartBeat = 1;
  11198. DEBUG_INFO("FirstHeartBeat \n");
  11199. }
  11200. HeartBeatWithNOResponse = 0;
  11201. clientTime.Heartbeat=time((time_t*)NULL);
  11202. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11203. }
  11204. void handleMeterValuesResponse(char *payload, int gun_index)
  11205. {
  11206. mtrace();
  11207. DEBUG_INFO("handleMeterValuesResponse...\n");
  11208. }
  11209. void handleStartTransactionResponse(char *payload, int gun_index)
  11210. {
  11211. mtrace();
  11212. //int transactionIdInt = 0;
  11213. FILE *outfile;
  11214. char data[100]={0};
  11215. DEBUG_INFO("handleStartTransactionResponse...\n");
  11216. json_object *StartTransaction;
  11217. StartTransaction = json_tokener_parse(payload);
  11218. if(!is_error(StartTransaction))
  11219. {
  11220. // Required data
  11221. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11222. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11223. // Optional data
  11224. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11225. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11226. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11227. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11228. }
  11229. json_object_put(StartTransaction);
  11230. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11231. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11232. //-----------Start : write to the Queue TransactionId file -----------------//
  11233. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11234. {}
  11235. else
  11236. {
  11237. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11238. if(log == NULL)
  11239. {
  11240. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11241. return ;
  11242. }
  11243. else
  11244. {
  11245. fclose(log);
  11246. }
  11247. }
  11248. // open file for writing
  11249. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11250. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11251. {
  11252. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11253. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11254. fputs(data, outfile);
  11255. fclose (outfile);
  11256. }
  11257. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11258. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11259. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11260. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11261. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11262. }
  11263. void handleStatusNotificationResponse(char *payload, int gun_index)
  11264. {
  11265. mtrace();
  11266. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11267. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11268. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11269. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11270. }
  11271. void handleStopTransactionnResponse(char *payload, int gun_index)
  11272. {
  11273. mtrace();
  11274. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11275. json_object *StopTransaction;
  11276. StopTransaction = json_tokener_parse(payload);
  11277. if(!is_error(StopTransaction))
  11278. {
  11279. // Optional data
  11280. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11281. {
  11282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11283. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11285. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11287. }
  11288. }
  11289. json_object_put(StopTransaction);
  11290. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11291. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11292. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11293. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11294. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11295. }
  11296. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11297. {
  11298. mtrace();
  11299. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11300. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11301. }
  11302. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11303. {
  11304. mtrace();
  11305. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11306. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11307. }
  11308. void handleSignCertificateResponse(char *payload, int gun_index)
  11309. {
  11310. mtrace();
  11311. DEBUG_INFO("handleSignCertificateResponse...\n");
  11312. json_object *SignCertificate;
  11313. SignCertificate = json_tokener_parse(payload);
  11314. if(!is_error(SignCertificate))
  11315. {
  11316. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11317. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11318. }
  11319. json_object_put(SignCertificate);
  11320. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11321. }
  11322. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11323. {
  11324. mtrace();
  11325. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11326. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11327. }
  11328. //==========================================
  11329. // Handle Error routine
  11330. //==========================================
  11331. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11332. {
  11333. mtrace();
  11334. #ifdef SystemLogMessage
  11335. DEBUG_INFO("errorCode: %s\n", errorCode);
  11336. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11337. DEBUG_INFO("errorDetails: %s\n", payload);
  11338. #endif
  11339. }
  11340. //===============================================
  11341. // Common routine
  11342. //===============================================
  11343. int initialConfigurationTable(void)
  11344. {
  11345. //clock_t start_t, end_t, total_t;
  11346. FILE *fp;
  11347. FILE *outfile;
  11348. char str[512]={0};
  11349. char sstr[256]={0};
  11350. int c = 0;
  11351. char *loc;
  11352. int confVersion = 5;
  11353. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11354. //start_t = clock();
  11355. //printf("Starting of the program, start_t = %ld\n", start_t);
  11356. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11357. // Check configuration file size is correct
  11358. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11359. {
  11360. struct stat st;
  11361. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11362. if(st.st_size < 3100)
  11363. {
  11364. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11365. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11366. }
  11367. }
  11368. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11369. {
  11370. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11371. if(outfile == NULL)
  11372. {
  11373. DEBUG_INFO("Error opening file\n");
  11374. return FALSE;
  11375. }
  11376. /*Core Profile*/
  11377. //AllowOfflineTxForUnknownId
  11378. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11382. //AuthorizationCacheEnabled
  11383. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11387. //AuthorizeRemoteTxRequests
  11388. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11392. //BlinkRepeat
  11393. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11397. //ClockAlignedDataInterval
  11398. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11402. //ConnectionTimeOut
  11403. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11407. //GetConfigurationMaxKeys
  11408. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11412. // HeartbeatInterval
  11413. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11417. // LightIntensity
  11418. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11422. // LocalAuthorizeOffline
  11423. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11427. // LocalPreAuthorize
  11428. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11432. // MaxEnergyOnInvalidId
  11433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11437. // MeterValuesAlignedData
  11438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11442. else
  11443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11445. // MeterValuesAlignedDataMaxLength
  11446. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11450. else
  11451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11453. // MeterValuesSampledData
  11454. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11458. else
  11459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11461. // MeterValuesSampledDataMaxLength
  11462. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11466. else
  11467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11469. // MeterValueSampleInterval
  11470. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11474. // MinimumStatusDuration
  11475. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11478. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11480. // NumberOfConnectors
  11481. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11484. {
  11485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11486. }
  11487. else
  11488. {
  11489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11490. }
  11491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11492. // ResetRetries
  11493. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11497. // ConnectorPhaseRotation
  11498. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11502. // ConnectorPhaseRotationMaxLength
  11503. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11507. // StopTransactionOnEVSideDisconnect
  11508. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11512. // StopTransactionOnInvalidId
  11513. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11517. // StopTxnAlignedData
  11518. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11522. // StopTxnAlignedDataMaxLength
  11523. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11527. // StopTxnSampledData
  11528. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11532. else
  11533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11535. // StopTxnSampledDataMaxLength
  11536. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11538. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11539. {
  11540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11541. }
  11542. else
  11543. {
  11544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11545. }
  11546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11547. // SupportedFeatureProfiles
  11548. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11552. // SupportedFeatureProfilesMaxLength
  11553. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11557. // TransactionMessageAttempts
  11558. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11561. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11563. // TransactionMessageRetryInterval
  11564. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11567. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11569. // UnlockConnectorOnEVSideDisconnect
  11570. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11574. // WebSocketPingInterval
  11575. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11579. // QueueOffLineStartTransactionMessage
  11580. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11584. // AuthorizationKey
  11585. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11589. // SecurityProfile
  11590. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11594. // DefaultPrice
  11595. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11599. // CustomDisplayCostAndPrice
  11600. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11604. // CustomIdleFeeAfterStop
  11605. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11609. // TimeOffset
  11610. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  11611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  11612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  11613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  11614. // NextTimeOffsetTransitionDateTime
  11615. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  11616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  11617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  11618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  11619. // TimeOffsetNextTransition
  11620. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  11621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  11622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  11623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  11624. // Configuration Version
  11625. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11629. //* Local Auth List Management Profile*/
  11630. #if 0
  11631. //For OCTT Test Case
  11632. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11635. #endif
  11636. #if 1
  11637. //LocalAuthListEnabled
  11638. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11642. #endif
  11643. //LocalAuthListMaxLength
  11644. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11648. //SendLocalListMaxLength
  11649. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11653. //ReserveConnectorZeroSupported
  11654. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11658. //* Smart Charging Profile */
  11659. //ChargeProfileMaxStackLevel
  11660. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11664. // ChargingScheduleAllowedChargingRateUnit
  11665. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11669. // ChargingScheduleMaxPeriods
  11670. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11674. // ConnectorSwitch3to1PhaseSupported
  11675. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11679. // MaxChargingProfilesInstalled
  11680. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11684. fclose(outfile);
  11685. }
  11686. else
  11687. {
  11688. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11689. char keystr[60]={0};
  11690. char readonlystr[10]={0};
  11691. char valuestr[256]={0};
  11692. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11693. if(fp == NULL) {
  11694. DEBUG_INFO("Error opening file");
  11695. return FALSE;
  11696. }
  11697. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11698. {
  11699. //DEBUG_INFO("Get Configuration \n");
  11700. if(strlen(str) > 0)
  11701. {
  11702. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11703. //*************************key*********************************/
  11704. if(strstr(str, "key") != NULL)
  11705. {
  11706. loc = strstr(str, "key");
  11707. c = 0;
  11708. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11709. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11710. {
  11711. sstr[c] = loc[strlen("key")+3+c];
  11712. c++;
  11713. }
  11714. sstr[c] = '\0';
  11715. strcpy(keystr,sstr);
  11716. }
  11717. //*************************readonly*********************************/
  11718. if(strstr(str, "readonly") != NULL)
  11719. {
  11720. loc = strstr(str, "readonly");
  11721. c = 0;
  11722. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11723. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11724. {
  11725. sstr[c] = loc[strlen("readonly")+2+c];
  11726. c++;
  11727. }
  11728. sstr[c] = '\0';
  11729. strcpy(readonlystr,sstr);
  11730. }
  11731. //*************************value*********************************/
  11732. if(strstr(str, "value") != NULL)
  11733. {
  11734. loc = strstr(str, "value");
  11735. c = 0;
  11736. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11737. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11738. {
  11739. sstr[c] = loc[strlen("value")+3+c];
  11740. c++;
  11741. }
  11742. sstr[c] = '\0';
  11743. strcpy(valuestr,sstr);
  11744. }
  11745. // DEBUG_INFO("keystr=%s\n",keystr);
  11746. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11747. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11748. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11749. {
  11750. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11751. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11753. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11754. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11755. }
  11756. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11757. {
  11758. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11759. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11761. }
  11762. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11763. {
  11764. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11766. }
  11767. if(strcmp(keystr, "BlinkRepeat") == 0)
  11768. {
  11769. //Charger.BlinkRepeat = Integer.parseInt(value);
  11770. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11772. }
  11773. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11774. {
  11775. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11777. }
  11778. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11779. {
  11780. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11782. }
  11783. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11784. {
  11785. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11787. }
  11788. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11789. {
  11790. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11792. HeartBeatWaitTime = atoi(valuestr);
  11793. }
  11794. if(strcmp(keystr, "LightIntensity") == 0)
  11795. {
  11796. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11798. }
  11799. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11800. {
  11801. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11803. }
  11804. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11805. {
  11806. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11808. }
  11809. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11810. {
  11811. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11813. }
  11814. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11815. {
  11816. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11818. }
  11819. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11820. {
  11821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11823. }
  11824. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11825. {
  11826. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11828. }
  11829. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11830. {
  11831. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11833. }
  11834. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11835. {
  11836. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11838. }
  11839. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11840. {
  11841. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11843. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11844. }
  11845. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11846. {
  11847. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11849. }
  11850. if(strcmp(keystr, "ResetRetries") == 0)
  11851. {
  11852. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11854. }
  11855. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11856. {
  11857. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11859. }
  11860. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11861. {
  11862. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11864. }
  11865. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11866. {
  11867. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11869. }
  11870. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11871. {
  11872. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11874. }
  11875. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11876. {
  11877. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11879. }
  11880. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11881. {
  11882. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11884. }
  11885. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11886. {
  11887. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11889. }
  11890. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11891. {
  11892. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11894. }
  11895. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11896. {
  11897. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11899. }
  11900. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11901. {
  11902. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11904. }
  11905. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11906. {
  11907. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11909. TransactionMessageAttemptsValue = atoi(valuestr);
  11910. }
  11911. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11912. {
  11913. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11915. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11916. }
  11917. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11918. {
  11919. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11921. }
  11922. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11923. {
  11924. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11926. }
  11927. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11928. {
  11929. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11931. }
  11932. if(strcmp(keystr, "AuthorizationKey") == 0)
  11933. {
  11934. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11935. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11937. }
  11938. if(strcmp(keystr, "SecurityProfile") == 0)
  11939. {
  11940. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11942. }
  11943. if(strcmp(keystr, "DefaultPrice") == 0)
  11944. {
  11945. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11947. }
  11948. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11949. {
  11950. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11952. }
  11953. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11954. {
  11955. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11957. }
  11958. if(strcmp(keystr, "TimeOffset") == 0)
  11959. {
  11960. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  11962. }
  11963. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  11964. {
  11965. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  11967. }
  11968. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  11969. {
  11970. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  11972. }
  11973. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11974. {
  11975. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11977. }
  11978. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11979. {
  11980. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11982. }
  11983. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11984. {
  11985. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11987. }
  11988. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11989. {
  11990. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11992. }
  11993. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11994. {
  11995. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11997. }
  11998. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11999. {
  12000. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12002. }
  12003. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12004. {
  12005. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12007. }
  12008. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12009. {
  12010. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12012. }
  12013. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12014. {
  12015. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12017. }
  12018. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12019. {
  12020. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12022. }
  12023. }
  12024. }
  12025. fclose(fp);
  12026. }
  12027. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12028. {
  12029. return PASS;
  12030. }
  12031. else
  12032. {
  12033. return FAIL;
  12034. }
  12035. }
  12036. void StoreConfigurationTable(void)
  12037. {
  12038. FILE *outfile;
  12039. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12040. if(outfile == NULL)
  12041. {
  12042. DEBUG_INFO("Error opening file");
  12043. return ;
  12044. }
  12045. /*Core Profile*/
  12046. //AllowOfflineTxForUnknownId
  12047. /*
  12048. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12049. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12052. */
  12053. //DEBUG_INFO("data=%s\n",data);
  12054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12055. //AuthorizationCacheEnabled
  12056. /*
  12057. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12060. */
  12061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12062. //AuthorizeRemoteTxRequests
  12063. /*
  12064. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12067. */
  12068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12069. //BlinkRepeat
  12070. /*
  12071. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12074. */
  12075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12076. //ClockAlignedDataInterval
  12077. /*
  12078. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12081. */
  12082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12083. //ConnectionTimeOut
  12084. /*
  12085. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12088. */
  12089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12090. //GetConfigurationMaxKeys
  12091. /*
  12092. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12095. */
  12096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12097. // HeartbeatInterval
  12098. /*
  12099. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12102. */
  12103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12104. // LightIntensity
  12105. /*
  12106. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12109. */
  12110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12111. // LocalAuthorizeOffline
  12112. /*
  12113. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12116. */
  12117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12118. // LocalPreAuthorize
  12119. /*
  12120. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12123. */
  12124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12125. // MaxEnergyOnInvalidId
  12126. /*
  12127. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12130. */
  12131. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12133. // MeterValuesAlignedData
  12134. /*
  12135. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12138. */
  12139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12140. // MeterValuesAlignedDataMaxLength
  12141. /*
  12142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12145. */
  12146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12147. // MeterValuesSampledData
  12148. /*
  12149. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12152. */
  12153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12154. // MeterValuesSampledDataMaxLength
  12155. /*
  12156. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12159. */
  12160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12161. // MeterValueSampleInterval
  12162. /*
  12163. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12166. */
  12167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12168. // MinimumStatusDuration
  12169. /*
  12170. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12173. */
  12174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12175. // NumberOfConnectors
  12176. /*
  12177. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12180. {
  12181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12182. }
  12183. else
  12184. {
  12185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12186. }
  12187. */
  12188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12189. // ResetRetries
  12190. /*
  12191. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12194. */
  12195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12196. // ConnectorPhaseRotation
  12197. /*
  12198. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12201. */
  12202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12203. // ConnectorPhaseRotationMaxLength
  12204. /*
  12205. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12208. */
  12209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12210. // StopTransactionOnEVSideDisconnect
  12211. /*
  12212. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12215. */
  12216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12217. // StopTransactionOnInvalidId
  12218. /*
  12219. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12222. */
  12223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12224. // StopTxnAlignedData
  12225. /*
  12226. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12229. */
  12230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12231. // StopTxnAlignedDataMaxLength
  12232. /*
  12233. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12236. */
  12237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12238. // StopTxnSampledData
  12239. /*
  12240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12243. */
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12245. // StopTxnSampledDataMaxLength
  12246. /*
  12247. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12250. */
  12251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12252. // SupportedFeatureProfiles
  12253. /*
  12254. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12257. */
  12258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12259. // SupportedFeatureProfilesMaxLength
  12260. /*
  12261. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12264. */
  12265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12266. // TransactionMessageAttempts
  12267. /*
  12268. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12271. */
  12272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12273. // TransactionMessageRetryInterval
  12274. /*
  12275. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12278. */
  12279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12280. // UnlockConnectorOnEVSideDisconnect
  12281. /*
  12282. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12285. */
  12286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12287. // WebSocketPingInterval
  12288. /*
  12289. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12292. */
  12293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12294. // QueueOffLineStartTransactionMessage
  12295. /*
  12296. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12299. */
  12300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12301. // AuthorizationKey
  12302. /*
  12303. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12306. */
  12307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12308. // SecurityProfile
  12309. /*
  12310. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12313. */
  12314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12315. // DefaultPrice
  12316. /*
  12317. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12320. */
  12321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12322. // CustomDisplayCostAndPrice
  12323. /*
  12324. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12327. */
  12328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12329. // CustomIdleFeeAfterStop
  12330. /*
  12331. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12334. */
  12335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12336. // TimeOffset
  12337. /*
  12338. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  12341. */
  12342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12343. // NextTimeOffsetTransitionDateTime
  12344. /*
  12345. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  12348. */
  12349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12350. // TimeOffsetNextTransition
  12351. /*
  12352. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  12355. */
  12356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12357. // ConfigurationVersion
  12358. /*
  12359. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12362. */
  12363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12364. //* Local Auth List Management Profile*/
  12365. //LocalAuthListEnabled
  12366. /*
  12367. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12370. */
  12371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12372. //LocalAuthListMaxLength
  12373. /*
  12374. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12377. */
  12378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12379. //SendLocalListMaxLength
  12380. /*
  12381. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12384. */
  12385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12386. //ReserveConnectorZeroSupported
  12387. /*
  12388. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12391. */
  12392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12393. //* Smart Charging Profile */
  12394. //ChargeProfileMaxStackLevel
  12395. /*
  12396. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12399. */
  12400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12401. // ChargingScheduleAllowedChargingRateUnit
  12402. /*
  12403. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12406. */
  12407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12408. // ChargingScheduleMaxPeriods
  12409. /*
  12410. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12413. */
  12414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12415. // ConnectorSwitch3to1PhaseSupported
  12416. /*
  12417. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12420. */
  12421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12422. // MaxChargingProfilesInstalled
  12423. /*
  12424. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12427. */
  12428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12429. fclose(outfile);
  12430. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12431. }
  12432. void getKeyValue(char *keyReq)
  12433. {
  12434. int isEmpty = FALSE;
  12435. int isKnowKey = FALSE;
  12436. DEBUG_INFO("keyReq = %s\n", keyReq);
  12437. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12438. isEmpty = TRUE;
  12439. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12440. {
  12441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12444. {
  12445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12446. }
  12447. else
  12448. {
  12449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12450. }
  12451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12452. isKnowKey = TRUE;
  12453. }
  12454. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12455. {
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12459. {
  12460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12461. }
  12462. else
  12463. {
  12464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12465. }
  12466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12467. isKnowKey = TRUE;
  12468. }
  12469. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12470. {
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12474. {
  12475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12476. }
  12477. else
  12478. {
  12479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12480. }
  12481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12482. isKnowKey = TRUE;
  12483. }
  12484. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12485. {
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12489. {
  12490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12491. }
  12492. else
  12493. {
  12494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12495. }
  12496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12497. isKnowKey = TRUE;
  12498. }
  12499. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12500. {
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12504. {
  12505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12506. }
  12507. else
  12508. {
  12509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12510. }
  12511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12512. isKnowKey = TRUE;
  12513. }
  12514. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12515. {
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12519. {
  12520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12521. }
  12522. else
  12523. {
  12524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12525. }
  12526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12527. isKnowKey = TRUE;
  12528. }
  12529. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12530. {
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12533. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12534. {
  12535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12536. }
  12537. else
  12538. {
  12539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12540. }
  12541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12542. isKnowKey = TRUE;
  12543. }
  12544. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12545. {
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12549. {
  12550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12551. }
  12552. else
  12553. {
  12554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12555. }
  12556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12557. isKnowKey = TRUE;
  12558. }
  12559. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12560. {
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12564. {
  12565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12566. }
  12567. else
  12568. {
  12569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12570. }
  12571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12572. isKnowKey = TRUE;
  12573. }
  12574. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12575. {
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12579. {
  12580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12581. }
  12582. else
  12583. {
  12584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12585. }
  12586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12587. isKnowKey = TRUE;
  12588. }
  12589. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12590. {
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12594. {
  12595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12596. }
  12597. else
  12598. {
  12599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12600. }
  12601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12602. isKnowKey = TRUE;
  12603. }
  12604. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12605. {
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12609. {
  12610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12611. }
  12612. else
  12613. {
  12614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12615. }
  12616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12617. isKnowKey = TRUE;
  12618. }
  12619. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12620. {
  12621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12624. {
  12625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12626. }
  12627. else
  12628. {
  12629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12630. }
  12631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12632. isKnowKey = TRUE;
  12633. }
  12634. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12635. {
  12636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12639. {
  12640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12641. }
  12642. else
  12643. {
  12644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12645. }
  12646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12647. isKnowKey = TRUE;
  12648. }
  12649. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12650. {
  12651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12654. {
  12655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12656. }
  12657. else
  12658. {
  12659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12660. }
  12661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12662. isKnowKey = TRUE;
  12663. }
  12664. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12665. {
  12666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12669. {
  12670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12671. }
  12672. else
  12673. {
  12674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12675. }
  12676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12677. isKnowKey = TRUE;
  12678. }
  12679. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12680. {
  12681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12684. {
  12685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12686. }
  12687. else
  12688. {
  12689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12690. }
  12691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12692. isKnowKey = TRUE;
  12693. }
  12694. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12695. {
  12696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12699. {
  12700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12701. }
  12702. else
  12703. {
  12704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12705. }
  12706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12707. isKnowKey = TRUE;
  12708. }
  12709. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12710. {
  12711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12714. {
  12715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12716. }
  12717. else
  12718. {
  12719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12720. }
  12721. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12723. isKnowKey = TRUE;
  12724. }
  12725. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12726. {
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12730. {
  12731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12732. }
  12733. else
  12734. {
  12735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12736. }
  12737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12738. isKnowKey = TRUE;
  12739. }
  12740. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12741. {
  12742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12745. {
  12746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12747. }
  12748. else
  12749. {
  12750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12751. }
  12752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12753. isKnowKey = TRUE;
  12754. }
  12755. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12756. {
  12757. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12760. {
  12761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12762. }
  12763. else
  12764. {
  12765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12766. }
  12767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12768. isKnowKey = TRUE;
  12769. }
  12770. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12771. {
  12772. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12775. {
  12776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12777. }
  12778. else
  12779. {
  12780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12781. }
  12782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12783. isKnowKey = TRUE;
  12784. }
  12785. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12786. {
  12787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12790. {
  12791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12792. }
  12793. else
  12794. {
  12795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12796. }
  12797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12798. isKnowKey = TRUE;
  12799. }
  12800. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12801. {
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12805. {
  12806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12807. }
  12808. else
  12809. {
  12810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12811. }
  12812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12813. isKnowKey = TRUE;
  12814. }
  12815. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12816. {
  12817. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12819. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12820. {
  12821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12822. }
  12823. else
  12824. {
  12825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12826. }
  12827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12828. isKnowKey = TRUE;
  12829. }
  12830. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12831. {
  12832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12835. {
  12836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12837. }
  12838. else
  12839. {
  12840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12841. }
  12842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12843. isKnowKey = TRUE;
  12844. }
  12845. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12846. {
  12847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12850. {
  12851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12852. }
  12853. else
  12854. {
  12855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12856. }
  12857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12858. isKnowKey = TRUE;
  12859. }
  12860. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12861. {
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12865. {
  12866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12867. }
  12868. else
  12869. {
  12870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12871. }
  12872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12873. isKnowKey = TRUE;
  12874. }
  12875. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12876. {
  12877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12880. {
  12881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12882. }
  12883. else
  12884. {
  12885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12886. }
  12887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12888. isKnowKey = TRUE;
  12889. }
  12890. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12891. {
  12892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12895. {
  12896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12897. }
  12898. else
  12899. {
  12900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12901. }
  12902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12903. isKnowKey = TRUE;
  12904. }
  12905. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12906. {
  12907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12910. {
  12911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12912. }
  12913. else
  12914. {
  12915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12916. }
  12917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12918. isKnowKey = TRUE;
  12919. }
  12920. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12921. {
  12922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12925. {
  12926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12927. }
  12928. else
  12929. {
  12930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12931. }
  12932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12933. isKnowKey = TRUE;
  12934. }
  12935. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12936. {
  12937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12940. {
  12941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12942. }
  12943. else
  12944. {
  12945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12946. }
  12947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12948. isKnowKey = TRUE;
  12949. }
  12950. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12951. {
  12952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12955. {
  12956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12957. }
  12958. else
  12959. {
  12960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12961. }
  12962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12963. isKnowKey = TRUE;
  12964. }
  12965. /*
  12966. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12967. {
  12968. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12971. {
  12972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12973. }
  12974. else
  12975. {
  12976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12977. }
  12978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12979. isKnowKey = TRUE;
  12980. }*/
  12981. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12982. {
  12983. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12986. {
  12987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12988. }
  12989. else
  12990. {
  12991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12992. }
  12993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12994. isKnowKey = TRUE;
  12995. }
  12996. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12997. {
  12998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13001. {
  13002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13003. }
  13004. else
  13005. {
  13006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13007. }
  13008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13009. isKnowKey = TRUE;
  13010. }
  13011. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13012. {
  13013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13016. {
  13017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13018. }
  13019. else
  13020. {
  13021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13022. }
  13023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13024. isKnowKey = TRUE;
  13025. }
  13026. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13027. {
  13028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13031. {
  13032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13033. }
  13034. else
  13035. {
  13036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13037. }
  13038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13039. isKnowKey = TRUE;
  13040. }
  13041. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13042. {
  13043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13046. {
  13047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13048. }
  13049. else
  13050. {
  13051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13052. }
  13053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13054. isKnowKey = TRUE;
  13055. }
  13056. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13057. {
  13058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13061. {
  13062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13063. }
  13064. else
  13065. {
  13066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13067. }
  13068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13069. isKnowKey = TRUE;
  13070. }
  13071. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13072. {
  13073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13076. {
  13077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13078. }
  13079. else
  13080. {
  13081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13082. }
  13083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13084. isKnowKey = TRUE;
  13085. }
  13086. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13087. {
  13088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13091. {
  13092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13093. }
  13094. else
  13095. {
  13096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13097. }
  13098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13099. isKnowKey = TRUE;
  13100. }
  13101. #if 1
  13102. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13103. {
  13104. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13106. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13107. {
  13108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13109. }
  13110. else
  13111. {
  13112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13113. }
  13114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13115. isKnowKey = TRUE;
  13116. }
  13117. #endif
  13118. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13119. {
  13120. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13122. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13123. {
  13124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13125. }
  13126. else
  13127. {
  13128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13129. }
  13130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13131. isKnowKey = TRUE;
  13132. }
  13133. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13134. {
  13135. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13137. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13138. {
  13139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13140. }
  13141. else
  13142. {
  13143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13144. }
  13145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13146. isKnowKey = TRUE;
  13147. }
  13148. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13149. {
  13150. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13152. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13153. {
  13154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13155. }
  13156. else
  13157. {
  13158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13159. }
  13160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13161. isKnowKey = TRUE;
  13162. }
  13163. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13164. {
  13165. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13167. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13168. {
  13169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13170. }
  13171. else
  13172. {
  13173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13174. }
  13175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13176. isKnowKey = TRUE;
  13177. }
  13178. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13179. {
  13180. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13182. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13183. {
  13184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13185. }
  13186. else
  13187. {
  13188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13189. }
  13190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13191. isKnowKey = TRUE;
  13192. }
  13193. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13194. {
  13195. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13197. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13198. {
  13199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13200. }
  13201. else
  13202. {
  13203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13204. }
  13205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13206. isKnowKey = TRUE;
  13207. }
  13208. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13209. {
  13210. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13212. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13213. {
  13214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13215. }
  13216. else
  13217. {
  13218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13219. }
  13220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13221. isKnowKey = TRUE;
  13222. }
  13223. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13224. {
  13225. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13227. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13228. {
  13229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13230. }
  13231. else
  13232. {
  13233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13234. }
  13235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13236. isKnowKey = TRUE;
  13237. }
  13238. //=========================================================
  13239. if(!isEmpty && !isKnowKey)
  13240. {
  13241. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13242. strcpy(unknownkey[UnknownKeynum], keyReq);
  13243. UnknownKeynum = UnknownKeynum + 1;
  13244. }
  13245. }
  13246. void processUnkownKey(void)
  13247. {
  13248. DEBUG_INFO("processUnkownKey...\n");
  13249. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13250. for(int index=0; index < UnknownKeynum; index++)
  13251. {
  13252. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13253. {
  13254. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13255. }
  13256. }
  13257. }
  13258. int setKeyValue(char *key, char *value)
  13259. {
  13260. int isSuccess = NotSupported;
  13261. int check_ascii=0;
  13262. char str[256]={0};
  13263. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13264. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13265. {
  13266. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13268. {
  13269. strcpy(str, (const char*)value);
  13270. for(int i = 0; str[i]; i++){
  13271. str[i] = tolower(str[i]);
  13272. }
  13273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13274. isSuccess = ConfigurationStatus_Accepted;
  13275. }
  13276. else
  13277. {
  13278. isSuccess = ConfigurationStatus_Rejected;
  13279. }
  13280. }
  13281. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13282. {
  13283. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13285. {
  13286. strcpy(str, (const char*)value);
  13287. for(int i = 0; str[i]; i++){
  13288. str[i] = tolower(str[i]);
  13289. }
  13290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13291. isSuccess = ConfigurationStatus_Accepted;
  13292. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13293. }
  13294. else
  13295. {
  13296. isSuccess = ConfigurationStatus_Rejected;
  13297. }
  13298. }
  13299. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13300. {
  13301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13302. {
  13303. strcpy(str, (const char*)value);
  13304. for(int i = 0; str[i]; i++)
  13305. {
  13306. str[i] = tolower(str[i]);
  13307. }
  13308. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13310. isSuccess = ConfigurationStatus_Accepted;
  13311. }
  13312. else
  13313. {
  13314. isSuccess = ConfigurationStatus_Rejected;
  13315. }
  13316. }
  13317. if(strcmp(key, "BlinkRepeat") == 0)
  13318. {
  13319. //Charger.BlinkRepeat = Integer.parseInt(value);
  13320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13321. {
  13322. check_ascii = value[0];
  13323. if( (check_ascii < 48) || (check_ascii > 57) )
  13324. {
  13325. isSuccess = ConfigurationStatus_Rejected;
  13326. }
  13327. else
  13328. {
  13329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13330. isSuccess = ConfigurationStatus_Accepted;
  13331. }
  13332. }
  13333. else
  13334. {
  13335. isSuccess = ConfigurationStatus_Rejected;
  13336. }
  13337. }
  13338. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13339. {
  13340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13341. {
  13342. check_ascii = value[0];
  13343. if( (check_ascii < 48) || (check_ascii > 57) )
  13344. {
  13345. isSuccess = ConfigurationStatus_Rejected;
  13346. }
  13347. else
  13348. {
  13349. if((atoi(value) == 0) || (atoi(value) >= 10))
  13350. {
  13351. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13353. isSuccess = ConfigurationStatus_Accepted;
  13354. }
  13355. else
  13356. isSuccess = ConfigurationStatus_Rejected;
  13357. }
  13358. }
  13359. else
  13360. {
  13361. isSuccess = ConfigurationStatus_Rejected;
  13362. }
  13363. }
  13364. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13365. {
  13366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13367. {
  13368. check_ascii = value[0];
  13369. if( (check_ascii < 48) || (check_ascii > 57) )
  13370. {
  13371. isSuccess = ConfigurationStatus_Rejected;
  13372. }
  13373. else
  13374. {
  13375. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13377. isSuccess = ConfigurationStatus_Accepted;
  13378. }
  13379. }
  13380. else
  13381. {
  13382. isSuccess = ConfigurationStatus_Rejected;
  13383. }
  13384. }
  13385. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13386. {
  13387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13388. {
  13389. check_ascii = value[0];
  13390. if( (check_ascii < 48) || (check_ascii > 57) )
  13391. {
  13392. isSuccess = ConfigurationStatus_Rejected;
  13393. }
  13394. else
  13395. {
  13396. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13398. isSuccess = ConfigurationStatus_Accepted;
  13399. }
  13400. }
  13401. else
  13402. {
  13403. isSuccess = ConfigurationStatus_Rejected;
  13404. }
  13405. }
  13406. if(strcmp(key, "HeartbeatInterval") == 0)
  13407. {
  13408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13409. {
  13410. check_ascii = value[0];
  13411. if( (check_ascii < 48) || (check_ascii > 57) )
  13412. {
  13413. isSuccess = ConfigurationStatus_Rejected;
  13414. }
  13415. else
  13416. {
  13417. if((atoi(value) == 0) || (atoi(value) >= 10))
  13418. {
  13419. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13421. HeartBeatWaitTime = atoi(value);
  13422. isSuccess = ConfigurationStatus_Accepted;
  13423. }
  13424. else
  13425. {
  13426. isSuccess = ConfigurationStatus_Rejected;
  13427. }
  13428. }
  13429. }
  13430. else
  13431. {
  13432. isSuccess = ConfigurationStatus_Rejected;
  13433. }
  13434. }
  13435. if(strcmp(key, "LightIntensity") == 0)
  13436. {
  13437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13438. {
  13439. check_ascii = value[0];
  13440. if( (check_ascii < 48) || (check_ascii > 57) )
  13441. {
  13442. isSuccess = ConfigurationStatus_Rejected;
  13443. }
  13444. else
  13445. {
  13446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13447. isSuccess = ConfigurationStatus_Accepted;
  13448. }
  13449. }
  13450. else
  13451. {
  13452. isSuccess = ConfigurationStatus_Rejected;
  13453. }
  13454. }
  13455. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13456. {
  13457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13458. {
  13459. strcpy(str, (const char*)value);
  13460. for(int i = 0; str[i]; i++)
  13461. {
  13462. str[i] = tolower(str[i]);
  13463. }
  13464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13465. isSuccess = ConfigurationStatus_Accepted;
  13466. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13467. }
  13468. else
  13469. {
  13470. isSuccess = ConfigurationStatus_Rejected;
  13471. }
  13472. }
  13473. if(strcmp(key, "LocalPreAuthorize") == 0)
  13474. {
  13475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13476. {
  13477. strcpy(str, (const char*)value);
  13478. for(int i = 0; str[i]; i++)
  13479. {
  13480. str[i] = tolower(str[i]);
  13481. }
  13482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13483. isSuccess = ConfigurationStatus_Accepted;
  13484. }
  13485. else
  13486. {
  13487. isSuccess = ConfigurationStatus_Rejected;
  13488. }
  13489. }
  13490. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13491. {
  13492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13493. {
  13494. check_ascii = value[0];
  13495. if( (check_ascii < 48) || (check_ascii > 57) )
  13496. {
  13497. isSuccess = ConfigurationStatus_Rejected;
  13498. }
  13499. else
  13500. {
  13501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13502. isSuccess = ConfigurationStatus_Accepted;
  13503. }
  13504. }
  13505. else
  13506. {
  13507. isSuccess = ConfigurationStatus_Rejected;
  13508. }
  13509. }
  13510. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13511. {
  13512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13513. {
  13514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13515. isSuccess = ConfigurationStatus_Accepted;
  13516. }
  13517. else
  13518. {
  13519. isSuccess = ConfigurationStatus_Rejected;
  13520. }
  13521. }
  13522. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13523. {
  13524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13525. {
  13526. check_ascii = value[0];
  13527. if( (check_ascii < 48) || (check_ascii > 57) )
  13528. {
  13529. isSuccess = ConfigurationStatus_Rejected;
  13530. }
  13531. else
  13532. {
  13533. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13535. isSuccess = ConfigurationStatus_Accepted;
  13536. }
  13537. }
  13538. else
  13539. {
  13540. isSuccess = ConfigurationStatus_Rejected;
  13541. }
  13542. }
  13543. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13544. {
  13545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13546. {
  13547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13548. isSuccess = ConfigurationStatus_Accepted;
  13549. }
  13550. else
  13551. {
  13552. isSuccess = ConfigurationStatus_Rejected;
  13553. }
  13554. }
  13555. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13556. {
  13557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13558. {
  13559. check_ascii = value[0];
  13560. if( (check_ascii < 48) || (check_ascii > 57) )
  13561. {
  13562. isSuccess = ConfigurationStatus_Rejected;
  13563. }
  13564. else
  13565. {
  13566. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13568. isSuccess = ConfigurationStatus_Accepted;
  13569. }
  13570. }
  13571. else
  13572. {
  13573. isSuccess = ConfigurationStatus_Rejected;
  13574. }
  13575. }
  13576. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13577. {
  13578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13579. {
  13580. check_ascii = value[0];
  13581. if( (check_ascii < 48) || (check_ascii > 57) )
  13582. {
  13583. isSuccess = ConfigurationStatus_Rejected;
  13584. }
  13585. else
  13586. {
  13587. if((atoi(value) == 0) || (atoi(value) >= 10))
  13588. {
  13589. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13591. isSuccess = ConfigurationStatus_Accepted;
  13592. }
  13593. else
  13594. {
  13595. isSuccess = ConfigurationStatus_Rejected;
  13596. }
  13597. }
  13598. }
  13599. else
  13600. {
  13601. isSuccess = ConfigurationStatus_Rejected;
  13602. }
  13603. }
  13604. if(strcmp(key, "MinimumStatusDuration") == 0)
  13605. {
  13606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13607. {
  13608. check_ascii = value[0];
  13609. if( (check_ascii < 48) || (check_ascii > 57) )
  13610. {
  13611. isSuccess = ConfigurationStatus_Rejected;
  13612. }
  13613. else
  13614. {
  13615. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13616. {
  13617. isSuccess = ConfigurationStatus_Rejected;
  13618. }
  13619. else
  13620. {
  13621. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13623. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13624. isSuccess = ConfigurationStatus_Accepted;
  13625. }
  13626. }
  13627. }
  13628. else
  13629. {
  13630. isSuccess = ConfigurationStatus_Rejected;
  13631. }
  13632. }
  13633. if(strcmp(key, "NumberOfConnectors") == 0)
  13634. {
  13635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13636. {
  13637. check_ascii = value[0];
  13638. if( (check_ascii < 48) || (check_ascii > 57) )
  13639. {
  13640. isSuccess = ConfigurationStatus_Rejected;
  13641. }
  13642. else
  13643. {
  13644. //Charger.ResetRetries = Integer.parseInt(value);
  13645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13646. isSuccess = ConfigurationStatus_Accepted;
  13647. }
  13648. }
  13649. else
  13650. {
  13651. isSuccess = ConfigurationStatus_Rejected;
  13652. }
  13653. }
  13654. if(strcmp(key, "ResetRetries") == 0)
  13655. {
  13656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13657. {
  13658. check_ascii = value[0];
  13659. if( (check_ascii < 48) || (check_ascii > 57) )
  13660. {
  13661. isSuccess = ConfigurationStatus_Rejected;
  13662. }
  13663. else
  13664. {
  13665. //Charger.ResetRetries = Integer.parseInt(value);
  13666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13667. isSuccess = ConfigurationStatus_Accepted;
  13668. }
  13669. }
  13670. else
  13671. {
  13672. isSuccess = ConfigurationStatus_Rejected;
  13673. }
  13674. }
  13675. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13676. {
  13677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13678. {
  13679. strcpy(str, (const char*)value);
  13680. for(int i = 0; str[i]; i++)
  13681. {
  13682. str[i] = tolower(str[i]);
  13683. }
  13684. if(strcmp(str, "notapplicable")== 0)
  13685. {
  13686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13687. isSuccess = ConfigurationStatus_Accepted;
  13688. }
  13689. else if(strcmp(str, "unknown")== 0)
  13690. {
  13691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13692. isSuccess = ConfigurationStatus_Accepted;
  13693. }
  13694. else if(strcmp(str, "rst")== 0)
  13695. {
  13696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13697. isSuccess = ConfigurationStatus_Accepted;
  13698. }
  13699. else if(strcmp(str, "rts")== 0)
  13700. {
  13701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13702. isSuccess = ConfigurationStatus_Accepted;
  13703. }
  13704. else if(strcmp(str, "srt")== 0)
  13705. {
  13706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13707. isSuccess = ConfigurationStatus_Accepted;
  13708. }
  13709. else if(strcmp(str, "str")== 0)
  13710. {
  13711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13712. isSuccess = ConfigurationStatus_Accepted;
  13713. }
  13714. else if(strcmp(str, "trs")== 0)
  13715. {
  13716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13717. isSuccess = ConfigurationStatus_Accepted;
  13718. }
  13719. else if(strcmp(str, "tsr")== 0)
  13720. {
  13721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13722. isSuccess = ConfigurationStatus_Accepted;
  13723. }
  13724. else
  13725. {
  13726. isSuccess = ConfigurationStatus_Rejected;
  13727. }
  13728. }
  13729. else
  13730. {
  13731. isSuccess = ConfigurationStatus_Rejected;
  13732. }
  13733. }
  13734. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13735. {
  13736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13737. {
  13738. check_ascii = value[0];
  13739. if( (check_ascii < 48) || (check_ascii > 57) )
  13740. {
  13741. isSuccess = ConfigurationStatus_Rejected;
  13742. }
  13743. else
  13744. {
  13745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13746. isSuccess = ConfigurationStatus_Accepted;
  13747. }
  13748. }
  13749. else
  13750. {
  13751. isSuccess = ConfigurationStatus_Rejected;
  13752. }
  13753. }
  13754. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13755. {
  13756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13757. {
  13758. strcpy(str, (const char*)value);
  13759. for(int i = 0; str[i]; i++)
  13760. {
  13761. str[i] = tolower(str[i]);
  13762. }
  13763. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13765. isSuccess = ConfigurationStatus_Accepted;
  13766. }
  13767. else
  13768. {
  13769. isSuccess = ConfigurationStatus_Rejected;
  13770. }
  13771. }
  13772. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13773. {
  13774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13775. {
  13776. strcpy(str, (const char*)value);
  13777. for(int i = 0; str[i]; i++)
  13778. {
  13779. str[i] = tolower(str[i]);
  13780. }
  13781. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13783. isSuccess = ConfigurationStatus_Accepted;
  13784. }
  13785. else
  13786. {
  13787. isSuccess = ConfigurationStatus_Rejected;
  13788. }
  13789. }
  13790. if(strcmp(key, "StopTxnAlignedData") == 0)
  13791. {
  13792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13793. {
  13794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13795. isSuccess = ConfigurationStatus_Accepted;
  13796. }
  13797. else
  13798. {
  13799. isSuccess = ConfigurationStatus_Rejected;
  13800. }
  13801. }
  13802. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13803. {
  13804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13805. {
  13806. check_ascii = value[0];
  13807. if( (check_ascii < 48) || (check_ascii > 57) )
  13808. {
  13809. isSuccess = ConfigurationStatus_Rejected;
  13810. }
  13811. else
  13812. {
  13813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13814. isSuccess = ConfigurationStatus_Accepted;
  13815. }
  13816. }
  13817. else
  13818. {
  13819. isSuccess = ConfigurationStatus_Rejected;
  13820. }
  13821. }
  13822. if(strcmp(key, "StopTxnSampledData") == 0)
  13823. {
  13824. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13825. {
  13826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13827. isSuccess = ConfigurationStatus_Accepted;
  13828. }
  13829. else
  13830. {
  13831. isSuccess = ConfigurationStatus_Rejected;
  13832. }
  13833. }
  13834. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13835. {
  13836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13837. {
  13838. check_ascii = value[0];
  13839. if( (check_ascii < 48) || (check_ascii > 57) )
  13840. {
  13841. isSuccess = ConfigurationStatus_Rejected;
  13842. }
  13843. else
  13844. {
  13845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13846. isSuccess = ConfigurationStatus_Accepted;
  13847. }
  13848. }
  13849. else
  13850. {
  13851. isSuccess = ConfigurationStatus_Rejected;
  13852. }
  13853. }
  13854. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13855. {
  13856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13857. {
  13858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13859. isSuccess = ConfigurationStatus_Accepted;
  13860. }
  13861. else
  13862. {
  13863. isSuccess = ConfigurationStatus_Rejected;
  13864. }
  13865. }
  13866. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13867. {
  13868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13869. {
  13870. check_ascii = value[0];
  13871. if( (check_ascii < 48) || (check_ascii > 57) )
  13872. {
  13873. isSuccess = ConfigurationStatus_Rejected;
  13874. }
  13875. else
  13876. {
  13877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13878. isSuccess = ConfigurationStatus_Accepted;
  13879. }
  13880. }
  13881. else
  13882. {
  13883. isSuccess = ConfigurationStatus_Rejected;
  13884. }
  13885. }
  13886. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13887. {
  13888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13889. {
  13890. check_ascii = value[0];
  13891. if( (check_ascii < 48) || (check_ascii > 57) )
  13892. {
  13893. isSuccess = ConfigurationStatus_Rejected;
  13894. }
  13895. else
  13896. {
  13897. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13899. TransactionMessageAttemptsValue = atoi(value);
  13900. isSuccess = ConfigurationStatus_Accepted;
  13901. }
  13902. }
  13903. else
  13904. {
  13905. isSuccess = ConfigurationStatus_Rejected;
  13906. }
  13907. }
  13908. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13909. {
  13910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13911. {
  13912. check_ascii = value[0];
  13913. if( (check_ascii < 48) || (check_ascii > 57) )
  13914. {
  13915. isSuccess = ConfigurationStatus_Rejected;
  13916. }
  13917. else
  13918. {
  13919. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13921. TransactionMessageRetryIntervalValue = atoi(value);
  13922. isSuccess = ConfigurationStatus_Accepted;
  13923. }
  13924. }
  13925. else
  13926. {
  13927. isSuccess = ConfigurationStatus_Rejected;
  13928. }
  13929. }
  13930. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13931. {
  13932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13933. {
  13934. strcpy(str, (const char*)value);
  13935. for(int i = 0; str[i]; i++)
  13936. {
  13937. str[i] = tolower(str[i]);
  13938. }
  13939. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13941. isSuccess = ConfigurationStatus_Accepted;
  13942. }
  13943. else
  13944. {
  13945. isSuccess = ConfigurationStatus_Rejected;
  13946. }
  13947. }
  13948. if(strcmp(key, "WebSocketPingInterval") == 0)
  13949. {
  13950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13951. {
  13952. check_ascii = value[0];
  13953. if( (check_ascii < 48) || (check_ascii > 57) )
  13954. {
  13955. isSuccess = ConfigurationStatus_Rejected;
  13956. }
  13957. else
  13958. {
  13959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13960. isSuccess = ConfigurationStatus_Accepted;
  13961. }
  13962. }
  13963. else
  13964. {
  13965. isSuccess = ConfigurationStatus_Rejected;
  13966. }
  13967. }
  13968. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13969. {
  13970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13971. {
  13972. strcpy(str, (const char*)value);
  13973. for(int i = 0; str[i]; i++)
  13974. {
  13975. str[i] = tolower(str[i]);
  13976. }
  13977. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13979. isSuccess = ConfigurationStatus_Accepted;
  13980. }
  13981. else
  13982. {
  13983. isSuccess = ConfigurationStatus_Rejected;
  13984. }
  13985. }
  13986. if(strcmp(key, "AuthorizationKey") == 0)
  13987. {
  13988. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13989. {
  13990. strcpy(str, (const char*)value);
  13991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13992. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13993. isSuccess = ConfigurationStatus_Accepted;
  13994. }
  13995. else
  13996. {
  13997. isSuccess = ConfigurationStatus_Rejected;
  13998. }
  13999. }
  14000. if(strcmp(key, "SecurityProfile") == 0)
  14001. {
  14002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14003. {
  14004. check_ascii = value[0];
  14005. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14006. {
  14007. isSuccess = ConfigurationStatus_Rejected;
  14008. }
  14009. else if(check_ascii == 0x33)
  14010. {
  14011. isSuccess = NotSupported;
  14012. }
  14013. else
  14014. {
  14015. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14016. {
  14017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14018. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14019. isSuccess = ConfigurationStatus_Accepted;
  14020. }
  14021. else
  14022. isSuccess = ConfigurationStatus_Rejected;
  14023. }
  14024. }
  14025. else
  14026. {
  14027. isSuccess = ConfigurationStatus_Rejected;
  14028. }
  14029. }
  14030. if(strcmp(key, "DefaultPrice") == 0)
  14031. {
  14032. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14033. {
  14034. strcpy(str, (const char*)value);
  14035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14036. isSuccess = ConfigurationStatus_Accepted;
  14037. }
  14038. else
  14039. {
  14040. isSuccess = ConfigurationStatus_Rejected;
  14041. }
  14042. }
  14043. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14044. {
  14045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14046. {
  14047. strcpy(str, (const char*)value);
  14048. for(int i = 0; str[i]; i++)
  14049. {
  14050. str[i] = tolower(str[i]);
  14051. }
  14052. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14054. isSuccess = ConfigurationStatus_Accepted;
  14055. }
  14056. else
  14057. {
  14058. isSuccess = ConfigurationStatus_Rejected;
  14059. }
  14060. }
  14061. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14062. {
  14063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14064. {
  14065. strcpy(str, (const char*)value);
  14066. for(int i = 0; str[i]; i++)
  14067. {
  14068. str[i] = tolower(str[i]);
  14069. }
  14070. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14072. isSuccess = ConfigurationStatus_Accepted;
  14073. }
  14074. else
  14075. {
  14076. isSuccess = ConfigurationStatus_Rejected;
  14077. }
  14078. }
  14079. if(strcmp(key, "TimeOffset") == 0)
  14080. {
  14081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14082. {
  14083. strcpy(str, (const char*)value);
  14084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14085. isSuccess = ConfigurationStatus_Accepted;
  14086. }
  14087. else
  14088. {
  14089. isSuccess = ConfigurationStatus_Rejected;
  14090. }
  14091. }
  14092. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14093. {
  14094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14095. {
  14096. strcpy(str, (const char*)value);
  14097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14098. isSuccess = ConfigurationStatus_Accepted;
  14099. }
  14100. else
  14101. {
  14102. isSuccess = ConfigurationStatus_Rejected;
  14103. }
  14104. }
  14105. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14106. {
  14107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14108. {
  14109. strcpy(str, (const char*)value);
  14110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14111. isSuccess = ConfigurationStatus_Accepted;
  14112. }
  14113. else
  14114. {
  14115. isSuccess = ConfigurationStatus_Rejected;
  14116. }
  14117. }
  14118. #if 0
  14119. //For OCPP Test Case
  14120. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14121. {
  14122. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14123. {
  14124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14125. isSuccess = ConfigurationStatus_Accepted;
  14126. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14127. }
  14128. else
  14129. {
  14130. isSuccess = ConfigurationStatus_Rejected;
  14131. }
  14132. }
  14133. #endif
  14134. #if 1
  14135. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14136. {
  14137. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14138. {
  14139. strcpy(str, (const char*)value);
  14140. for(int i = 0; str[i]; i++)
  14141. {
  14142. str[i] = tolower(str[i]);
  14143. }
  14144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14145. isSuccess = ConfigurationStatus_Accepted;
  14146. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14147. }
  14148. else
  14149. {
  14150. isSuccess = ConfigurationStatus_Rejected;
  14151. }
  14152. }
  14153. #endif
  14154. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14155. {
  14156. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14157. {
  14158. check_ascii = value[0];
  14159. if( (check_ascii < 48) || (check_ascii > 57) )
  14160. {
  14161. isSuccess = ConfigurationStatus_Rejected;
  14162. }
  14163. else
  14164. {
  14165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14166. isSuccess = ConfigurationStatus_Accepted;
  14167. }
  14168. }
  14169. else
  14170. {
  14171. isSuccess = ConfigurationStatus_Rejected;
  14172. }
  14173. }
  14174. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14175. {
  14176. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14177. {
  14178. check_ascii = value[0];
  14179. if( (check_ascii < 48) || (check_ascii > 57) )
  14180. {
  14181. isSuccess = ConfigurationStatus_Rejected;
  14182. }
  14183. else
  14184. {
  14185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14186. isSuccess = ConfigurationStatus_Accepted;
  14187. }
  14188. }
  14189. else
  14190. {
  14191. isSuccess = ConfigurationStatus_Rejected;
  14192. }
  14193. }
  14194. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14195. {
  14196. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14197. {
  14198. strcpy(str, (const char*)value);
  14199. for(int i = 0; str[i]; i++)
  14200. {
  14201. str[i] = tolower(str[i]);
  14202. }
  14203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14204. isSuccess = ConfigurationStatus_Accepted;
  14205. }
  14206. else
  14207. {
  14208. isSuccess = ConfigurationStatus_Rejected;
  14209. }
  14210. }
  14211. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14212. {
  14213. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14214. {
  14215. check_ascii = value[0];
  14216. if( (check_ascii < 48) || (check_ascii > 57) )
  14217. {
  14218. isSuccess = ConfigurationStatus_Rejected;
  14219. }
  14220. else
  14221. {
  14222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14223. isSuccess = ConfigurationStatus_Accepted;
  14224. }
  14225. }
  14226. else
  14227. {
  14228. isSuccess = ConfigurationStatus_Rejected;
  14229. }
  14230. }
  14231. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14232. {
  14233. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14234. {
  14235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14236. isSuccess = ConfigurationStatus_Accepted;
  14237. }
  14238. else
  14239. {
  14240. isSuccess = ConfigurationStatus_Rejected;
  14241. }
  14242. }
  14243. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14244. {
  14245. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14246. {
  14247. check_ascii = value[0];
  14248. if( (check_ascii < 48) || (check_ascii > 57) )
  14249. {
  14250. isSuccess = ConfigurationStatus_Rejected;
  14251. }
  14252. else
  14253. {
  14254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14255. isSuccess = ConfigurationStatus_Accepted;
  14256. }
  14257. }
  14258. else
  14259. {
  14260. isSuccess = ConfigurationStatus_Rejected;
  14261. }
  14262. }
  14263. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14264. {
  14265. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14266. {
  14267. strcpy(str, (const char*)value);
  14268. for(int i = 0; str[i]; i++)
  14269. {
  14270. str[i] = tolower(str[i]);
  14271. }
  14272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14273. isSuccess = ConfigurationStatus_Accepted;
  14274. }
  14275. else
  14276. {
  14277. isSuccess = ConfigurationStatus_Rejected;
  14278. }
  14279. }
  14280. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14281. {
  14282. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14283. {
  14284. check_ascii = value[0];
  14285. if( (check_ascii < 48) || (check_ascii > 57) )
  14286. {
  14287. isSuccess = ConfigurationStatus_Rejected;
  14288. }
  14289. else
  14290. {
  14291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14292. isSuccess = ConfigurationStatus_Accepted;
  14293. }
  14294. }
  14295. else
  14296. {
  14297. isSuccess = ConfigurationStatus_Rejected;
  14298. }
  14299. }
  14300. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14301. return isSuccess;
  14302. }
  14303. int TransactionMessageAttemptsGet(void)
  14304. {
  14305. return TransactionMessageAttemptsValue;
  14306. }
  14307. int FirstHeartBeatResponse(void)
  14308. {
  14309. return FirstHeartBeat;
  14310. }
  14311. int TransactionMessageRetryIntervalGet(void)
  14312. {
  14313. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14314. }
  14315. int ReadHttpStatus(int sock)
  14316. {
  14317. //char c;
  14318. char buff[1024]="",*ptr=buff+1;
  14319. int bytes_received, status;
  14320. DEBUG_INFO("Begin Response ..\n");
  14321. while((bytes_received = recv(sock, ptr, 1, 0))){
  14322. if(bytes_received==-1){
  14323. perror("ReadHttpStatus");
  14324. exit(1);
  14325. }
  14326. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14327. ptr++;
  14328. }
  14329. *ptr=0;
  14330. ptr=buff+1;
  14331. sscanf(ptr,"%*s %d ", &status);
  14332. DEBUG_INFO("%s\n",ptr);
  14333. DEBUG_INFO("status=%d\n",status);
  14334. DEBUG_INFO("End Response ..\n");
  14335. return (bytes_received>0)?status:0;
  14336. }
  14337. //the only filed that it parsed is 'Content-Length'
  14338. int ParseHeader(int sock)
  14339. {
  14340. //char c;
  14341. char buff[1024]="",*ptr=buff+4;
  14342. int bytes_received;
  14343. DEBUG_INFO("Begin HEADER ..\n");
  14344. while((bytes_received = recv(sock, ptr, 1, 0))){
  14345. if(bytes_received==-1){
  14346. perror("Parse Header");
  14347. exit(1);
  14348. }
  14349. if(
  14350. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14351. (ptr[-1]=='\r') && (*ptr=='\n' )
  14352. ) break;
  14353. ptr++;
  14354. }
  14355. *ptr=0;
  14356. ptr=buff+4;
  14357. //printf("%s",ptr);
  14358. if(bytes_received){
  14359. ptr=strstr(ptr,"Content-Length:");
  14360. if(ptr){
  14361. sscanf(ptr,"%*s %d",&bytes_received);
  14362. }else
  14363. bytes_received=-1; //unknown size
  14364. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14365. }
  14366. DEBUG_INFO("End HEADER ..\n");
  14367. return bytes_received ;
  14368. }
  14369. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14370. {
  14371. int result = TRUE;
  14372. char rmFileCmd[100]={0};
  14373. char FilePath[100]={0};
  14374. char ftpbuf[200];
  14375. int systemresult;
  14376. //DEBUG_INFO("filename=%s\n",filename);
  14377. //DEBUG_INFO("url=%s\n",url);
  14378. sprintf(FilePath,"/mnt/%s",filename);
  14379. system("ping 8.8.8.8 &");
  14380. if((access(FilePath,F_OK))!=-1)
  14381. {
  14382. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14383. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14384. system(rmFileCmd);
  14385. }
  14386. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14387. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14388. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14389. systemresult = system(ftpbuf);
  14390. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14391. if(systemresult != 0)
  14392. {
  14393. DEBUG_INFO("http DownLoad error!\n");
  14394. result = FALSE;
  14395. }
  14396. system("pkill ping");
  14397. return result;
  14398. }
  14399. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14400. {
  14401. int result = TRUE;
  14402. char rmFileCmd[100]={0};
  14403. char FilePath[100]={0};
  14404. char ftpbuf[200];
  14405. int systemresult;
  14406. //char temp[100];
  14407. sprintf(FilePath,"/mnt/%s",filename);
  14408. system("ping 8.8.8.8 &");
  14409. if((access(FilePath,F_OK))!=-1)
  14410. {
  14411. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14412. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14413. system(rmFileCmd);
  14414. }
  14415. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14416. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14417. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14418. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14419. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14420. systemresult = system(ftpbuf);
  14421. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14422. if(systemresult != 0)
  14423. {
  14424. DEBUG_WARN("wget error!\n");
  14425. result = FALSE;
  14426. }
  14427. system("pkill ping");
  14428. return result;
  14429. }
  14430. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14431. {
  14432. char rmFileCmd[100]={0};
  14433. char FilePath[100]={0};
  14434. char buf[512];
  14435. int systemresult = 0;
  14436. //DEBUG_INFO("filename=%s\n",filename);
  14437. //DEBUG_INFO("url=%s\n",url);
  14438. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14439. if((access(FilePath,F_OK))!=-1)
  14440. {
  14441. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14442. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14443. system(rmFileCmd);
  14444. }
  14445. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14446. if(fp == NULL)
  14447. {
  14448. DEBUG_INFO("log is NULL\n");
  14449. return FALSE;
  14450. }
  14451. else
  14452. {
  14453. fprintf(fp, "%s\n", url);
  14454. fprintf(fp, "%s\n", filename);
  14455. fclose(fp);
  14456. }
  14457. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14458. if(phpFP == NULL)
  14459. {
  14460. DEBUG_INFO("PHP upload fail.\n");
  14461. return FALSE;
  14462. }
  14463. else
  14464. {
  14465. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14466. {
  14467. if(strstr(buf, "result") != NULL)
  14468. {
  14469. sscanf(buf, "result: %d", &systemresult);
  14470. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14471. }
  14472. }
  14473. pclose(phpFP);
  14474. }
  14475. if(systemresult != 1)
  14476. {
  14477. DEBUG_INFO("HTTP upload error!\n");
  14478. return FALSE;
  14479. }
  14480. return TRUE;
  14481. }
  14482. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14483. {
  14484. struct hostent* server;
  14485. char *IPbuffer;
  14486. char ftpbuf[200];
  14487. int systemresult;
  14488. // To retrieve host information
  14489. server = gethostbyname(location);
  14490. // To convert an Internet network
  14491. // address into ASCII string
  14492. IPbuffer = inet_ntoa(*((struct in_addr*)
  14493. server->h_addr_list[0]));
  14494. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14495. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14496. /* format : ftpput -u username -p passwd IP target source*/
  14497. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14498. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14499. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14500. systemresult = system(ftpbuf);
  14501. DEBUG_INFO("systemresult=%d\n",systemresult);
  14502. if(systemresult != 0)
  14503. {
  14504. DEBUG_INFO("ftpput error!\n");
  14505. return FALSE;
  14506. }
  14507. return TRUE;
  14508. }
  14509. int GetOcppServerURL()
  14510. {
  14511. int result = FALSE;
  14512. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14513. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14514. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14515. struct yuarel url;
  14516. char urlStr[512];
  14517. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14518. {
  14519. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14520. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14521. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14522. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14523. if(yuarel_parse(&url, urlStr) != -1)
  14524. {
  14525. sprintf(OcppProtocol, "%s", url.scheme);
  14526. sprintf(OcppHost, "%s", url.host);
  14527. if(url.path == NULL)
  14528. OcppTempPath[0] = '\0';
  14529. else
  14530. {
  14531. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14532. {
  14533. sprintf(OcppTempPath, "%s/", url.path);
  14534. }
  14535. else
  14536. {
  14537. sprintf(OcppTempPath, "%s", url.path);
  14538. }
  14539. }
  14540. if(url.port == 0)
  14541. {
  14542. if(strcmp(OcppProtocol, "wss") == 0)
  14543. OcppPort = 443;
  14544. else
  14545. OcppPort = 80;
  14546. }
  14547. else
  14548. OcppPort = url.port;
  14549. result = TRUE;
  14550. }
  14551. }
  14552. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14553. {
  14554. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14555. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14556. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14557. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14558. if(yuarel_parse(&url, urlStr) != -1)
  14559. {
  14560. sprintf(OcppProtocol, "%s", url.scheme);
  14561. sprintf(OcppHost, "%s", url.host);
  14562. if(url.path == NULL)
  14563. OcppTempPath[0] = '\0';
  14564. else
  14565. sprintf(OcppTempPath, "%s", url.path);
  14566. if(url.port == 0)
  14567. {
  14568. if(strcmp(OcppProtocol, "wss") == 0)
  14569. OcppPort = 443;
  14570. else
  14571. OcppPort = 80;
  14572. }
  14573. else
  14574. OcppPort = url.port;
  14575. result = TRUE;
  14576. }
  14577. }
  14578. else
  14579. {
  14580. strcpy(OcppHost,"");
  14581. }
  14582. return result;
  14583. }
  14584. int GetOcppPath()
  14585. {
  14586. int result = FALSE;
  14587. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14588. {
  14589. if(OcppTempPath == NULL)
  14590. {
  14591. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14592. }
  14593. else
  14594. {
  14595. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14596. }
  14597. result = TRUE;
  14598. goto End;
  14599. }
  14600. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14601. {
  14602. if(OcppTempPath == NULL)
  14603. {
  14604. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14605. }
  14606. else
  14607. {
  14608. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14609. }
  14610. result = TRUE;
  14611. goto End;
  14612. }
  14613. else
  14614. {
  14615. strcpy(OcppPath,"");
  14616. }
  14617. End:
  14618. return result;
  14619. }
  14620. int GetOcppPort()
  14621. {
  14622. return OcppPort;
  14623. }
  14624. int GetOcppConnStatus(void)
  14625. {
  14626. return ShmOCPP16Data->OcppConnStatus;
  14627. }
  14628. void SetOcppConnStatus(uint8_t status)
  14629. {
  14630. ShmOCPP16Data->OcppConnStatus = status;
  14631. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14632. }
  14633. int GetHeartBeatWithNOResponse(void)
  14634. {
  14635. return HeartBeatWithNOResponse;
  14636. }
  14637. void SetHeartBeatWithNOResponse(void)
  14638. {
  14639. HeartBeatWithNOResponse = 0;
  14640. }
  14641. void GetStartTransactionIdTag(int gun_index)
  14642. {
  14643. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14644. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14645. }
  14646. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14647. {
  14648. char ch;
  14649. FILE *fptr1;
  14650. int temptransactionId;
  14651. char str[100]={0};
  14652. temptransactionId = 0;
  14653. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14654. {
  14655. DEBUG_INFO("IdTag is empty.\n");
  14656. return temptransactionId;
  14657. }
  14658. /*------ Read the file ----------------*/
  14659. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14660. if (!fptr1)
  14661. {
  14662. DEBUG_INFO("QueueTransactionId file open error.\n");
  14663. //printf(" File not found or unable to open the input file!!\n");
  14664. return temptransactionId;
  14665. }
  14666. ch=fgetc(fptr1);
  14667. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14668. rewind(fptr1);
  14669. if(ch!=EOF)
  14670. {
  14671. // printf("%c",ch);
  14672. while (fgets(str, 100, fptr1) != NULL)
  14673. {
  14674. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14675. if(str[0]=='\0')
  14676. {
  14677. break;
  14678. }
  14679. char *revbuf[8] = {0}; // Variable store string split
  14680. int num = 0;// Quantity after string split
  14681. DEBUG_INFO("Transaction queue data= %s\n", str);
  14682. splitstring(str,",",revbuf,&num); // String split
  14683. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14684. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14685. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14686. DEBUG_INFO("------------------------------\n");
  14687. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14688. {
  14689. if(isStopTransaction)
  14690. {
  14691. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14692. {
  14693. temptransactionId = atoi(revbuf[2]);
  14694. //break;
  14695. }
  14696. }
  14697. else
  14698. {
  14699. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14700. {
  14701. temptransactionId = atoi(revbuf[2]);
  14702. //break;
  14703. }
  14704. }
  14705. }
  14706. }
  14707. }
  14708. else
  14709. DEBUG_INFO("EOF\n");
  14710. fclose(fptr1);
  14711. /*------- End of reading ---------------*/
  14712. return temptransactionId;
  14713. }
  14714. void SetTransactionIdZero(int transactionId)
  14715. {
  14716. char ch;
  14717. FILE *fptr1, *fptr2;
  14718. int temptransactionId = 0;
  14719. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14720. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14721. if (!fptr1)
  14722. {
  14723. //printf(" File not found or unable to open the input file!!\n");
  14724. return ;
  14725. }
  14726. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14727. if (!fptr2)
  14728. {
  14729. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14730. fclose(fptr1);
  14731. return ;
  14732. }
  14733. ch=fgetc(fptr1);
  14734. rewind(fptr1);
  14735. if(ch!=EOF)
  14736. {
  14737. // copy all contents to the temporary file except the specific line
  14738. while (fgets(str, 100, fptr1) != NULL)
  14739. {
  14740. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14741. if(str[0]=='\0')
  14742. {
  14743. break;
  14744. }
  14745. char *revbuf[8] = {0};
  14746. int num = 0;
  14747. strcpy(strtemp, str);
  14748. splitstring(str,",",revbuf,&num);
  14749. if(revbuf[2][0] != '\0')
  14750. {
  14751. temptransactionId = atoi(revbuf[2]);
  14752. if(transactionId != temptransactionId)
  14753. {
  14754. fprintf(fptr2, "%s\n", strtemp);
  14755. }
  14756. }
  14757. }
  14758. }
  14759. fclose(fptr1);
  14760. fclose(fptr2);
  14761. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14762. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14763. /*------ Read the file ----------------*/
  14764. }
  14765. int InternetDisconnect(void)
  14766. {
  14767. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14768. }
  14769. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14770. void storeTempStopTransaction(int gun_index)
  14771. {
  14772. char guid[37]={0};
  14773. int tempIndex = 0;
  14774. char TempStopTransaction[256];
  14775. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14776. DEBUG_INFO("storeTempStopTransaction...\n");
  14777. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14778. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14779. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14780. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14781. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14782. {
  14783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14784. {
  14785. tempIndex = ((gun_index==2) ? 1: 0);
  14786. }
  14787. else
  14788. {
  14789. tempIndex = gun_index;
  14790. }
  14791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14792. {
  14793. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14794. {
  14795. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14796. }
  14797. }// END OF CHAdeMO_QUANTITY
  14798. }
  14799. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14800. {
  14801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14802. {
  14803. tempIndex = ((gun_index==2) ? 1: 0);
  14804. }
  14805. else
  14806. {
  14807. tempIndex = gun_index;
  14808. }
  14809. for (int index = 0; index < CCS_QUANTITY; index++)
  14810. {
  14811. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14812. {
  14813. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14814. }
  14815. }// END OF CCS_QUANTITY
  14816. }
  14817. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14818. {
  14819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14820. {
  14821. tempIndex = ((gun_index==2) ? 1: 0);
  14822. }
  14823. else
  14824. {
  14825. tempIndex = gun_index;
  14826. }
  14827. for (int index = 0; index < GB_QUANTITY; index++)
  14828. {
  14829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14830. {
  14831. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14832. }
  14833. }// END OF GB_QUANTITY
  14834. }
  14835. else if(gunType[gun_index] == GUN_TYPE_DO)
  14836. {
  14837. tempIndex = gun_index;
  14838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14839. {
  14840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14841. {
  14842. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14843. }
  14844. }
  14845. }
  14846. else
  14847. {
  14848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14849. {
  14850. tempIndex = 2;
  14851. }
  14852. else
  14853. {
  14854. tempIndex = gun_index;
  14855. }
  14856. for (int index = 0; index < AC_QUANTITY; index++)
  14857. {
  14858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14859. {
  14860. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14861. }
  14862. }// END OF AC_QUANTITY
  14863. }
  14864. //Stop Transaction Time
  14865. struct timeval tmnow;
  14866. struct tm *tm;
  14867. char buf[28];//, usec_buf[6];
  14868. gettimeofday(&tmnow, NULL);
  14869. time_t t;
  14870. t = time(NULL);
  14871. /*UTC time and date*/
  14872. tm = gmtime(&t);
  14873. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14875. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14877. random_uuid(guid);
  14878. /***********************************transactionData******************************************************/
  14879. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14881. //=================================
  14882. //1. Transaction_Begin
  14883. //=================================
  14884. //============================== Energy.Active.Import.Interval ===========================================
  14885. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14886. {
  14887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  14891. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14892. 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))
  14893. {
  14894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14895. }
  14896. else
  14897. {
  14898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14899. }
  14900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14902. }
  14903. //=================================
  14904. //2. Transaction_End
  14905. //=================================
  14906. //2.1====================================== Current.Import L1 ==============================================
  14907. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14908. {
  14909. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14910. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14911. {
  14912. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14913. {
  14914. tempIndex = ((gun_index==2) ? 1: 0);
  14915. }
  14916. else
  14917. {
  14918. tempIndex = gun_index;
  14919. }
  14920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14921. {
  14922. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14923. {
  14924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14925. }
  14926. }// End of for CHAdeMO_QUANTITY
  14927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14928. }
  14929. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14930. {
  14931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14932. {
  14933. tempIndex = ((gun_index==2) ? 1: 0);
  14934. }
  14935. else
  14936. {
  14937. tempIndex = gun_index;
  14938. }
  14939. for (int index = 0; index < CCS_QUANTITY; index++)
  14940. {
  14941. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14942. {
  14943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14944. }
  14945. }// End of for CCS_QUANTITY
  14946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14947. }
  14948. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14949. {
  14950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14951. {
  14952. tempIndex = ((gun_index==2) ? 1: 0);
  14953. }
  14954. else
  14955. {
  14956. tempIndex = gun_index;
  14957. }
  14958. for (int index = 0; index < GB_QUANTITY; index++)
  14959. {
  14960. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14961. {
  14962. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14963. }
  14964. }// End of for GB_QUANTITY
  14965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14966. }
  14967. else if(gunType[gun_index] == GUN_TYPE_DO)
  14968. {
  14969. tempIndex = gun_index;
  14970. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14971. {
  14972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14973. {
  14974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14975. }
  14976. }
  14977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14978. }
  14979. else
  14980. {
  14981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14982. {
  14983. tempIndex = 2;
  14984. }
  14985. else
  14986. {
  14987. tempIndex = gun_index;
  14988. }
  14989. for (int index = 0; index < AC_QUANTITY; index++)
  14990. {
  14991. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14992. {
  14993. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14994. }
  14995. }// End of for AC_QUANTITY
  14996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14997. }
  14998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15001. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15004. }
  15005. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15006. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15007. {
  15008. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15009. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15010. {
  15011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15012. {
  15013. tempIndex = ((gun_index==2) ? 1: 0);
  15014. }
  15015. else
  15016. {
  15017. tempIndex = gun_index;
  15018. }
  15019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15020. {
  15021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15022. {
  15023. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15024. }
  15025. }// END OF CHAdeMO_QUANTITY
  15026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15027. }
  15028. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15029. {
  15030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15031. {
  15032. tempIndex = ((gun_index==2) ? 1: 0);
  15033. }
  15034. else
  15035. {
  15036. tempIndex = gun_index;
  15037. }
  15038. for (int index = 0; index < CCS_QUANTITY; index++)
  15039. {
  15040. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15041. {
  15042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15043. }
  15044. }// END OF CCS_QUANTITY
  15045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15046. }
  15047. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15048. {
  15049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15050. {
  15051. tempIndex = ((gun_index==2) ? 1: 0);
  15052. }
  15053. else
  15054. {
  15055. tempIndex = gun_index;
  15056. }
  15057. for (int index = 0; index < GB_QUANTITY; index++)
  15058. {
  15059. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15060. {
  15061. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15062. }
  15063. }// END OF GB_QUANTITY
  15064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15065. }
  15066. else if(gunType[gun_index] == GUN_TYPE_DO)
  15067. {
  15068. tempIndex = gun_index;
  15069. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15070. {
  15071. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15072. {
  15073. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15074. }
  15075. }
  15076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15077. }
  15078. else
  15079. {
  15080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15081. {
  15082. tempIndex = 2;
  15083. }
  15084. else
  15085. {
  15086. tempIndex = gun_index;
  15087. }
  15088. for (int index = 0; index < AC_QUANTITY; index++)
  15089. {
  15090. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15091. {
  15092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15093. }
  15094. }// END OF AC_QUANTITY
  15095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15096. }
  15097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15100. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15103. }
  15104. //2.3====================================== Power.Active.Import =========================================
  15105. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15106. {
  15107. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15108. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15109. {
  15110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15111. {
  15112. tempIndex = ((gun_index==2) ? 1: 0);
  15113. }
  15114. else
  15115. {
  15116. tempIndex = gun_index;
  15117. }
  15118. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15119. {
  15120. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15121. {
  15122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15123. }
  15124. } // End for CHAdeMO_QUANTITY
  15125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15126. }
  15127. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15128. {
  15129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15130. {
  15131. tempIndex = ((gun_index==2) ? 1: 0);
  15132. }
  15133. else
  15134. {
  15135. tempIndex = gun_index;
  15136. }
  15137. for (int index = 0; index < CCS_QUANTITY; index++)
  15138. {
  15139. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15140. {
  15141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15142. }
  15143. } // END for CCS_QUANTITY
  15144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15145. }
  15146. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15147. {
  15148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15149. {
  15150. tempIndex = ((gun_index==2) ? 1: 0);
  15151. }
  15152. else
  15153. {
  15154. tempIndex = gun_index;
  15155. }
  15156. for (int index = 0; index < GB_QUANTITY; index++)
  15157. {
  15158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15159. {
  15160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15161. }
  15162. }// END for GB_QUANTITY
  15163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15164. }
  15165. else if(gunType[gun_index] == GUN_TYPE_DO)
  15166. {
  15167. tempIndex = gun_index;
  15168. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15169. {
  15170. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15171. {
  15172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15173. }
  15174. }
  15175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15176. }
  15177. else
  15178. {
  15179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15180. {
  15181. tempIndex = 2;
  15182. }
  15183. else
  15184. {
  15185. tempIndex = gun_index;
  15186. }
  15187. for (int index = 0; index < AC_QUANTITY; index++)
  15188. {
  15189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15190. {
  15191. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15192. }
  15193. } // END for AC_QUANTITY
  15194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15195. }
  15196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15199. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15202. }
  15203. //2.4====================================== Voltage L1 ====================================================
  15204. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15205. {
  15206. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15207. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15208. {
  15209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15210. {
  15211. tempIndex = ((gun_index==2) ? 1: 0);
  15212. }
  15213. else
  15214. {
  15215. tempIndex = gun_index;
  15216. }
  15217. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15218. {
  15219. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15220. {
  15221. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15222. }
  15223. } // END OF FOR CHAdeMO_QUANTITY
  15224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15225. }
  15226. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15227. {
  15228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15229. {
  15230. tempIndex = ((gun_index==2) ? 1: 0);
  15231. }
  15232. else
  15233. {
  15234. tempIndex = gun_index;
  15235. }
  15236. for (int index = 0; index < CCS_QUANTITY; index++)
  15237. {
  15238. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15239. {
  15240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15241. }
  15242. } // END OF FOR CCS_QUANTITY
  15243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15244. }
  15245. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15246. {
  15247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15248. {
  15249. tempIndex = ((gun_index==2) ? 1: 0);
  15250. }
  15251. else
  15252. {
  15253. tempIndex = gun_index;
  15254. }
  15255. for (int index = 0; index < GB_QUANTITY; index++)
  15256. {
  15257. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15258. {
  15259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15260. }
  15261. } // END OF FOR GB_QUANTITY
  15262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15263. }
  15264. else if(gunType[gun_index] == GUN_TYPE_DO)
  15265. {
  15266. tempIndex = gun_index;
  15267. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15268. {
  15269. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15270. {
  15271. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15272. }
  15273. }
  15274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15275. }
  15276. else
  15277. {
  15278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15279. {
  15280. tempIndex = 2;
  15281. }
  15282. else
  15283. {
  15284. tempIndex = gun_index;
  15285. }
  15286. for (int index = 0; index < AC_QUANTITY; index++)
  15287. {
  15288. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15289. {
  15290. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15291. }
  15292. } // END OF FOR AC_QUANTITY
  15293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15294. }
  15295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15298. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15301. }
  15302. //2.5============================================== End SoC =========================================================
  15303. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15304. {
  15305. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15306. 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))
  15307. {
  15308. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15309. {
  15310. tempIndex = ((gun_index==2) ? 1: 0);
  15311. }
  15312. else
  15313. {
  15314. tempIndex = gun_index;
  15315. }
  15316. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15317. {
  15318. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15319. {
  15320. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15321. {
  15322. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15323. }
  15324. }
  15325. }
  15326. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15327. {
  15328. for (int index = 0; index < CCS_QUANTITY; index++)
  15329. {
  15330. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15331. {
  15332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15333. }
  15334. }
  15335. }
  15336. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15337. {
  15338. for (int index = 0; index < GB_QUANTITY; index++)
  15339. {
  15340. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15341. {
  15342. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15343. }
  15344. }
  15345. }
  15346. else if(gunType[gun_index] == GUN_TYPE_DO)
  15347. {
  15348. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15349. {
  15350. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15351. {
  15352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15353. }
  15354. }
  15355. }
  15356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15362. } // END FOR DC CASE
  15363. }
  15364. //2.6====================================== Current.Import L2 ==============================================
  15365. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15366. {
  15367. // AC 3 phase L2 current
  15368. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15369. {
  15370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15371. {
  15372. tempIndex = 2;
  15373. }
  15374. else
  15375. {
  15376. tempIndex = gun_index;
  15377. }
  15378. for (int index = 0; index < AC_QUANTITY; index++)
  15379. {
  15380. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15381. {
  15382. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15383. }
  15384. }// End of for AC_QUANTITY
  15385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15386. }
  15387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15392. }
  15393. //2.7====================================== Current.Import L3 ==============================================
  15394. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15395. {
  15396. // AC 3 phase L3 current
  15397. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15398. {
  15399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15400. {
  15401. tempIndex = 2;
  15402. }
  15403. else
  15404. {
  15405. tempIndex = gun_index;
  15406. }
  15407. for (int index = 0; index < AC_QUANTITY; index++)
  15408. {
  15409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15410. {
  15411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15412. }
  15413. }// End of for AC_QUANTITY
  15414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15415. }
  15416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15421. }
  15422. //2.9====================================== Voltage L2 ====================================================
  15423. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15424. {
  15425. // AC 3 phase L2 volatge
  15426. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15427. {
  15428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15429. {
  15430. tempIndex = 2;
  15431. }
  15432. else
  15433. {
  15434. tempIndex = gun_index;
  15435. }
  15436. for (int index = 0; index < AC_QUANTITY; index++)
  15437. {
  15438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15439. {
  15440. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15441. }
  15442. } // END OF FOR AC_QUANTITY
  15443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15444. }
  15445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15450. }
  15451. //2.10====================================== Voltage L3 ====================================================
  15452. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15453. {
  15454. // AC 3 phase L3 volatge
  15455. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15456. {
  15457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15458. {
  15459. tempIndex = 2;
  15460. }
  15461. else
  15462. {
  15463. tempIndex = gun_index;
  15464. }
  15465. for (int index = 0; index < AC_QUANTITY; index++)
  15466. {
  15467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15468. {
  15469. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15470. }
  15471. } // END OF FOR AC_QUANTITY
  15472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15473. }
  15474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15479. }
  15480. //====================== Start SoC ================================
  15481. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15482. {
  15483. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15484. 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))
  15485. {
  15486. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15487. {
  15488. tempIndex = ((gun_index==2) ? 1: 0);
  15489. }
  15490. else
  15491. {
  15492. tempIndex = gun_index;
  15493. }
  15494. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15495. {
  15496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15497. {
  15498. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15499. {
  15500. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15501. }
  15502. }
  15503. }
  15504. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15505. {
  15506. for (int index = 0; index < CCS_QUANTITY; index++)
  15507. {
  15508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15509. {
  15510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15511. }
  15512. }
  15513. }
  15514. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15515. {
  15516. for (int index = 0; index < GB_QUANTITY; index++)
  15517. {
  15518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15519. {
  15520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15521. }
  15522. }
  15523. }
  15524. else if(gunType[gun_index] == GUN_TYPE_DO)
  15525. {
  15526. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15527. {
  15528. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15529. {
  15530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15531. }
  15532. }
  15533. }
  15534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15540. } // END FOR DC CASE
  15541. }
  15542. //======================================== Message create ==============================================
  15543. json_object *StopTransaction = json_object_new_object();
  15544. json_object *transactionDatas = json_object_new_array();
  15545. json_object *sampledValues = json_object_new_array();
  15546. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15547. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15548. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15549. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15550. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15551. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15552. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15553. {
  15554. json_object *transactionData = json_object_new_object();
  15555. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15556. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15557. {
  15558. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15559. {
  15560. json_object *sampledValue = json_object_new_object();
  15561. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15562. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15563. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15564. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15565. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15566. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15567. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15568. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15569. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15570. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15571. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15572. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15573. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15574. json_object_array_add(sampledValues, sampledValue);
  15575. }
  15576. }
  15577. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15578. json_object_array_add(transactionDatas, transactionData);
  15579. }
  15580. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15581. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15582. ,MESSAGE_TYPE_CALL
  15583. ,guid
  15584. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15585. json_object_put(StopTransaction);
  15586. // Check File "TempStopTransaction" Exist
  15587. if((access(TempStopTransaction,F_OK))!=-1)
  15588. {
  15589. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15590. fclose(fopen(TempStopTransaction, "w"));
  15591. }
  15592. else
  15593. {
  15594. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15595. FILE *log = fopen(TempStopTransaction, "w+");
  15596. if(log == NULL)
  15597. {
  15598. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15599. return ;
  15600. }
  15601. else
  15602. {
  15603. fclose(log);
  15604. }
  15605. }
  15606. //Add TempStopTransaction | Update TempStopTransaction
  15607. // open file for writing
  15608. FILE *outfile;
  15609. outfile = fopen (TempStopTransaction, "a");
  15610. //DEBUG_INFO("data = %s\n", queuedata);
  15611. fputs(queuedata, outfile);
  15612. fputs("\n", outfile);
  15613. fclose (outfile);
  15614. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15615. }
  15616. void checkTempStopTransaction(int gun_index)
  15617. {
  15618. FILE *fptr1;
  15619. char ch;
  15620. char str[QUEUE_MESSAGE_LENGTH]={0};
  15621. char guid[37]={0};
  15622. char tempdata[65]={0};
  15623. char connectorStr[2]={0};
  15624. char TempStopTransaction[256];
  15625. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15626. fptr1 = fopen(TempStopTransaction, "r");
  15627. //TempStopTransaction格式: 槍號,StopTransaction封包
  15628. if (!fptr1)
  15629. {
  15630. //printf(" File not found or unable to open the input file!!\n");
  15631. return ;
  15632. }
  15633. ch=fgetc(fptr1);
  15634. //printf(" Now the content of the file %s is : \n",fname);
  15635. rewind(fptr1);
  15636. if(ch!=EOF)
  15637. {
  15638. // copy all contents to the temporary file except the specific line
  15639. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15640. {
  15641. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15642. if(str[0]=='\0')
  15643. {
  15644. break;
  15645. }
  15646. //TempStopTransaction格式: 槍號,StopTransaction封包
  15647. strncpy(connectorStr, str, 1);
  15648. if(atoi(connectorStr) != (gun_index+1))
  15649. {
  15650. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15651. fclose(fptr1);
  15652. return ;
  15653. }
  15654. //random_uuid(guid);
  15655. strncpy(guid, str+6, 36); //copy guid
  15656. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15657. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15658. {
  15659. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15660. }
  15661. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15662. OCPP_insert_transaction_msg(NO, str);
  15663. memset(str,0,ARRAY_SIZE(str));
  15664. }
  15665. }
  15666. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15667. fclose(fptr1);
  15668. remove(TempStopTransaction); // remove the original file
  15669. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15670. }
  15671. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15672. {
  15673. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15674. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15675. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15676. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15677. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15678. }
  15679. int GetWebSocketPingInterval(void)
  15680. {
  15681. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15682. }
  15683. int GetServerSign(void)
  15684. {
  15685. return server_sign;
  15686. }
  15687. uint8_t GetOcppSecurityProfile()
  15688. {
  15689. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15690. }
  15691. void GetOcppChargerBoxId(uint8_t *data)
  15692. {
  15693. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15694. }
  15695. void GetOcppSecurityPassword(uint8_t *data)
  15696. {
  15697. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15698. }
  15699. void SetOcppVersion(uint8_t *version)
  15700. {
  15701. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15702. DEBUG_INFO("ocpp version: %s\n", version);
  15703. if(strstr((char*)version, "ocpp1.6") != NULL)
  15704. {
  15705. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15706. }
  15707. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15708. {
  15709. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15710. system("pkill OcppBackend");
  15711. }
  15712. }
  15713. void SetServerSign(int value)
  15714. {
  15715. server_sign = value;
  15716. }
  15717. int GetBootNotificationInterval(void)
  15718. {
  15719. return BootNotificationInterval;
  15720. }
  15721. int GetInternetConn(void)
  15722. {
  15723. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15724. }
  15725. int GetBackendConnectionTimeout(void)
  15726. {
  15727. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15728. }
  15729. int isConnectorInitMode(int gun_index)
  15730. {
  15731. int tempIndex = 0;
  15732. int result = TRUE;
  15733. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15734. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15735. {
  15736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15737. {
  15738. tempIndex = ((gun_index==2) ? 1: 0);
  15739. }
  15740. else
  15741. {
  15742. tempIndex = gun_index;
  15743. }
  15744. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15745. {
  15746. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15747. {
  15748. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15749. } //end of the same index
  15750. }//end of for CHAdeMO_QUANTITY
  15751. }
  15752. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15753. {
  15754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15755. {
  15756. tempIndex = ((gun_index==2) ? 1: 0);
  15757. }
  15758. else
  15759. {
  15760. tempIndex = gun_index;
  15761. }
  15762. for (int index = 0; index < CCS_QUANTITY; index++)
  15763. {
  15764. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15765. {
  15766. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15767. } //end of the same index
  15768. } // end of for CCS_QUANTITY
  15769. }
  15770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15771. {
  15772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15773. {
  15774. tempIndex = ((gun_index==2) ? 1: 0);
  15775. }
  15776. else
  15777. {
  15778. tempIndex = gun_index;
  15779. }
  15780. for (int index = 0; index < GB_QUANTITY; index++)
  15781. {
  15782. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15783. {
  15784. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15785. } //end of the same index
  15786. } // end of for GB_QUANTITY
  15787. }
  15788. else if(gunType[gun_index] == GUN_TYPE_DO)
  15789. {
  15790. tempIndex = gun_index;
  15791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15792. {
  15793. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15794. {
  15795. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15796. } //end of the same index
  15797. }
  15798. }
  15799. else
  15800. {
  15801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15802. {
  15803. tempIndex = 2;
  15804. }
  15805. else
  15806. {
  15807. tempIndex = gun_index;
  15808. }
  15809. for (int index = 0; index < AC_QUANTITY; index++)
  15810. {
  15811. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15812. {
  15813. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15814. }//end of the same index
  15815. }//end of for AC_QUANTITY
  15816. }
  15817. return result;
  15818. }
  15819. void refreshProcDogTimer()
  15820. {
  15821. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15822. }
  15823. void InitialSystemValue(void)
  15824. {
  15825. int connectorIndex = 0;
  15826. //int valueASCII = 0;
  15827. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15828. gunTotalNumber=0;
  15829. SystemInitial = 0;
  15830. locallistVersion=0;
  15831. BootNotificationInterval = 0;
  15832. authorizeRetryTimes = 0;
  15833. GunStatusInterval = 10;
  15834. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15835. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15836. //Hear Beat
  15837. HeartBeatWithNOResponse = 0;
  15838. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15839. FirstHeartBeat = 0;
  15840. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15841. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15842. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15843. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15844. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15845. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15846. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15847. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15848. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15849. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15850. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15851. memset(gunType, 0, ARRAY_SIZE(gunType));
  15852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15853. {
  15854. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15855. {
  15856. // DO series
  15857. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15858. {
  15859. SystemInitial = SystemInitial + 1;
  15860. gunTotalNumber = gunTotalNumber + 1;
  15861. gunType[connectorIndex] = GUN_TYPE_DO;
  15862. connectorIndex = connectorIndex + 1;
  15863. }
  15864. }
  15865. else
  15866. {
  15867. // DM, DW, DS series
  15868. //check connector / socket type (index: 8, 9, 10)
  15869. for(int index=7; index <10 ; index++)
  15870. {
  15871. if(index != 8)
  15872. {
  15873. // DC Connector
  15874. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15875. {
  15876. SystemInitial = SystemInitial + 1;
  15877. gunTotalNumber = gunTotalNumber + 1;
  15878. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15879. connectorIndex = connectorIndex + 1;
  15880. }
  15881. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15882. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15883. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15884. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15885. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15886. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15887. {
  15888. SystemInitial = SystemInitial + 1;
  15889. gunTotalNumber = gunTotalNumber + 1;
  15890. gunType[connectorIndex] = GUN_TYPE_CCS;
  15891. connectorIndex = connectorIndex + 1;
  15892. }
  15893. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15894. {
  15895. SystemInitial = SystemInitial + 1;
  15896. gunTotalNumber = gunTotalNumber + 1;
  15897. gunType[connectorIndex] = GUN_TYPE_GBT;
  15898. connectorIndex = connectorIndex + 1;
  15899. }
  15900. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15901. {
  15902. SystemInitial = SystemInitial + 1;
  15903. gunTotalNumber = gunTotalNumber + 1;
  15904. gunType[connectorIndex] = GUN_TYPE_DO;
  15905. connectorIndex = connectorIndex + 1;
  15906. }
  15907. }
  15908. else
  15909. {
  15910. // AC Connector
  15911. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15912. {
  15913. SystemInitial = SystemInitial + 1;
  15914. gunTotalNumber = gunTotalNumber + 1;
  15915. gunType[connectorIndex] = GUN_TYPE_AC;
  15916. connectorIndex = connectorIndex + 1;
  15917. }
  15918. }
  15919. }
  15920. }
  15921. //DEBUG_INFO("DC ...\n");
  15922. }
  15923. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15924. {
  15925. //check connector / socket type (index: 8, 9, 10)
  15926. for(int index=7; index <10 ; index++)
  15927. {
  15928. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15929. {
  15930. SystemInitial = SystemInitial + 1;
  15931. gunTotalNumber = gunTotalNumber + 1;
  15932. gunType[connectorIndex] = GUN_TYPE_AC;
  15933. connectorIndex = connectorIndex + 1;
  15934. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15935. }
  15936. }
  15937. }
  15938. //Status && ConnectorPlugIn Setting
  15939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15940. {
  15941. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15942. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15943. }
  15944. for (int index = 0; index < CCS_QUANTITY; index++)
  15945. {
  15946. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15947. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15948. }
  15949. for (int index = 0; index < GB_QUANTITY; index++)
  15950. {
  15951. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15952. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15953. }
  15954. for (int index = 0; index < AC_QUANTITY; index++)
  15955. {
  15956. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15957. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15958. }
  15959. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15960. {
  15961. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15962. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15963. }
  15964. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15965. {
  15966. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15967. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15968. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15969. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15970. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15971. }
  15972. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15973. clientTime.Heartbeat=time((time_t*)NULL);
  15974. sleep(1);
  15975. }
  15976. void LWS_Send(char *str)
  15977. {
  15978. //=====================================================
  15979. // Check InternetConn 0: disconnected, 1: connected
  15980. //====================================================
  15981. if(GetOcppConnStatus() == 0)
  15982. {
  15983. DEBUG_INFO("offline now !!!\n");
  15984. return;
  15985. }
  15986. // Only disable isWebsocketSendable operation initiated by charger
  15987. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15988. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15989. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15990. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15991. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15992. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15993. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15994. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15995. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15996. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15997. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15998. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15999. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16000. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16001. {
  16002. isWebsocketSendable = 0;
  16003. }
  16004. pthread_mutex_lock(&lock_send);
  16005. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16006. sprintf((char *)SendBuffer, "%s", str);
  16007. SendBufLen = strlen(str);
  16008. pthread_mutex_unlock(&lock_send);
  16009. lws_callback_on_writable(wsi_client);
  16010. //lws_service(context, 0);
  16011. //sleep(1);
  16012. }
  16013. void LWS_SendNow(char *str)
  16014. {
  16015. //=====================================================
  16016. // Check InternetConn 0: disconnected, 1: connected
  16017. //====================================================
  16018. if(GetOcppConnStatus() == 0)
  16019. {
  16020. DEBUG_INFO("offline now !!!\n");
  16021. return;
  16022. }
  16023. // Only disable isWebsocketSendable operation initiated by charger
  16024. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16025. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16026. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16027. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16028. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16029. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16030. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16031. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16032. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16033. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16034. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16035. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16036. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16037. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16038. {
  16039. isWebsocketSendable = 0;
  16040. }
  16041. pthread_mutex_lock(&lock_send);
  16042. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16043. sprintf((char *)SendBuffer, "%s", str);
  16044. SendBufLen = strlen(str);
  16045. pthread_mutex_unlock(&lock_send);
  16046. lws_callback_on_writable(wsi_client);
  16047. lws_service(context, 0);
  16048. //sleep(1);
  16049. }