MessageHandler.c 795 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458
  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 version desc, idx desc limit 1");
  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[0]=='D'))
  7365. {
  7366. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  7367. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  7368. (gunType[3] != GUN_TYPE_UNKNOWN))
  7369. {
  7370. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7371. }
  7372. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  7373. {
  7374. // DS DM DW
  7375. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7376. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7377. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7378. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7379. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7380. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7381. }
  7382. else
  7383. {
  7384. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7387. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7390. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7391. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7392. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7393. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7394. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7395. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7396. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7397. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7398. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7399. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7400. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7401. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7402. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7403. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7404. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7405. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7406. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7407. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7408. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7409. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7410. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7411. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7412. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7413. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7414. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7415. }
  7416. }
  7417. // 4G model
  7418. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7419. {
  7420. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7421. }
  7422. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7423. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7424. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7425. json_object_put(FirmwareDataTransfer);
  7426. }
  7427. int handleDataTransferRequest(char *uuid, char *payload)
  7428. {
  7429. mtrace();
  7430. json_object *response = json_object_new_object();
  7431. int result = FAIL;
  7432. char tempvendorId[255]={0};
  7433. char tempmessageId[50]={0};
  7434. char tempdata[512]={0};
  7435. char message[2048]={0};
  7436. DEBUG_INFO("handleDataTransferRequest...\n");
  7437. if((uuid != NULL) && (payload != NULL))
  7438. {
  7439. json_object *DataTransfer;
  7440. DataTransfer = json_tokener_parse(payload);
  7441. if(!is_error(DataTransfer))
  7442. {
  7443. // Required data
  7444. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7445. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7446. // Optional data
  7447. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7448. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7449. if(json_object_object_get(DataTransfer, "data") != NULL)
  7450. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7451. result = PASS;
  7452. }
  7453. json_object_put(DataTransfer);
  7454. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7455. {
  7456. // Send all moudle firmware version on EVSE
  7457. createFirmwareVersionByDataTransfer();
  7458. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7459. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7460. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7461. json_object_put(response);
  7462. }
  7463. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7464. {
  7465. system("/usr/bin/run_tmate_restart.sh &");
  7466. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7467. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7468. json_object_put(response);
  7469. }
  7470. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7471. {
  7472. json_object *data;
  7473. data = json_tokener_parse(tempdata);
  7474. if(!is_error(data))
  7475. {
  7476. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7477. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7478. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7479. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7480. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7481. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7482. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7483. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7484. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7485. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7486. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7487. }
  7488. else
  7489. {
  7490. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7491. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7492. }
  7493. json_object_put(data);
  7494. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7495. json_object_put(response);
  7496. }
  7497. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7498. {
  7499. json_object *data;
  7500. data = json_tokener_parse(tempdata);
  7501. if(!is_error(data))
  7502. {
  7503. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7504. if(json_object_object_get(data, "idToken") != NULL)
  7505. {
  7506. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7507. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7508. }
  7509. if(json_object_object_get(data, "price") != NULL)
  7510. {
  7511. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7512. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7513. }
  7514. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7515. }
  7516. else
  7517. {
  7518. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7519. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7520. }
  7521. json_object_put(data);
  7522. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7523. json_object_put(response);
  7524. }
  7525. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7526. {
  7527. json_object *data;
  7528. data = json_tokener_parse(tempdata);
  7529. if(!is_error(data))
  7530. {
  7531. if(json_object_object_get(data, "txId") != NULL)
  7532. {
  7533. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7534. for(int idx = 0;idx<gunTotalNumber;idx++)
  7535. {
  7536. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7537. {
  7538. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  7539. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7540. if(json_object_object_get(data, "description") != NULL)
  7541. {
  7542. // California pricing V1.0
  7543. DEBUG_INFO("California pricing V1.0\n");
  7544. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7545. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7546. }
  7547. else
  7548. {
  7549. // California pricing V1.1
  7550. DEBUG_INFO("California pricing V1.1\n");
  7551. if(json_object_object_get(data, "timestamp") != NULL)
  7552. {
  7553. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  7554. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  7555. }
  7556. if(json_object_object_get(data, "meterValue") != NULL)
  7557. {
  7558. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  7559. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  7560. }
  7561. if(json_object_object_get(data, "cost") != NULL)
  7562. {
  7563. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  7564. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  7565. }
  7566. if(json_object_object_get(data, "state") != NULL)
  7567. {
  7568. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  7569. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  7570. }
  7571. if(json_object_object_get(data, "chargingPrice") != NULL)
  7572. {
  7573. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  7574. {
  7575. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  7576. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  7577. }
  7578. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  7579. {
  7580. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  7581. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  7582. }
  7583. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  7584. {
  7585. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  7586. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  7587. }
  7588. }
  7589. if(json_object_object_get(data, "idlePrice") != NULL)
  7590. {
  7591. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  7592. {
  7593. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  7594. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  7595. }
  7596. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  7597. {
  7598. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  7599. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  7600. }
  7601. }
  7602. if(json_object_object_get(data, "nextPeriod") != NULL)
  7603. {
  7604. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  7605. {
  7606. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  7607. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  7608. }
  7609. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  7610. {
  7611. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  7612. {
  7613. 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")));
  7614. 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"));
  7615. }
  7616. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  7617. {
  7618. 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")));
  7619. 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"));
  7620. }
  7621. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  7622. {
  7623. 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")));
  7624. 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"));
  7625. }
  7626. }
  7627. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  7628. {
  7629. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  7630. {
  7631. 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")));
  7632. 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"));
  7633. }
  7634. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  7635. {
  7636. 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")));
  7637. 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"));
  7638. }
  7639. }
  7640. }
  7641. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  7642. {
  7643. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  7644. {
  7645. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  7646. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  7647. }
  7648. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  7649. {
  7650. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  7651. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  7652. }
  7653. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  7654. {
  7655. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  7656. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  7657. }
  7658. }
  7659. }
  7660. }
  7661. }
  7662. }
  7663. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7664. }
  7665. else
  7666. {
  7667. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7668. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7669. }
  7670. json_object_put(data);
  7671. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7672. json_object_put(response);
  7673. }
  7674. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7675. {
  7676. json_object *data;
  7677. data = json_tokener_parse(tempdata);
  7678. if(!is_error(data))
  7679. {
  7680. if(json_object_object_get(data, "txId") != NULL)
  7681. {
  7682. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7683. for(int idx = 0;idx<gunTotalNumber;idx++)
  7684. {
  7685. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7686. {
  7687. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  7688. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7689. if(json_object_object_get(data, "description") != NULL)
  7690. {
  7691. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7692. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7693. }
  7694. }
  7695. }
  7696. }
  7697. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7698. }
  7699. else
  7700. {
  7701. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7702. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7703. }
  7704. json_object_put(data);
  7705. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7706. json_object_put(response);
  7707. }
  7708. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7709. {
  7710. json_object *data;
  7711. data = json_tokener_parse(tempdata);
  7712. if(!is_error(data))
  7713. {
  7714. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7715. if(json_object_object_get(data, "Content_Type") != NULL)
  7716. {
  7717. 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))
  7718. {
  7719. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7720. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7721. {
  7722. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7723. }
  7724. }
  7725. else
  7726. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7727. }
  7728. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7729. }
  7730. else
  7731. {
  7732. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7733. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7734. }
  7735. json_object_put(data);
  7736. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7737. json_object_put(response);
  7738. }
  7739. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7740. {
  7741. json_object *data;
  7742. data = json_tokener_parse(tempdata);
  7743. if(!is_error(data))
  7744. {
  7745. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7746. if(json_object_object_get(data, "Page_Index") != NULL)
  7747. {
  7748. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7749. }
  7750. if(json_object_object_get(data, "Duration") != NULL)
  7751. {
  7752. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7753. }
  7754. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7755. }
  7756. else
  7757. {
  7758. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7759. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7760. }
  7761. json_object_put(data);
  7762. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7763. json_object_put(response);
  7764. }
  7765. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7766. {
  7767. json_object *data;
  7768. data = json_tokener_parse(tempdata);
  7769. if(!is_error(data))
  7770. {
  7771. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7772. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7773. {
  7774. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7775. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7776. else
  7777. {
  7778. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7779. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7780. }
  7781. }
  7782. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7783. {
  7784. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7785. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7786. else
  7787. {
  7788. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7789. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7790. }
  7791. }
  7792. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7793. {
  7794. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7795. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7796. else
  7797. {
  7798. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7799. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7800. }
  7801. }
  7802. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7803. {
  7804. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7805. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7806. else
  7807. {
  7808. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7809. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7810. }
  7811. }
  7812. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7813. {
  7814. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7815. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7816. else
  7817. {
  7818. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7819. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7820. }
  7821. }
  7822. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7823. {
  7824. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7825. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7826. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7827. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7828. else
  7829. {
  7830. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7831. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7832. }
  7833. }
  7834. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7835. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7836. }
  7837. else
  7838. {
  7839. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7840. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7841. }
  7842. json_object_put(data);
  7843. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7844. json_object_put(response);
  7845. }
  7846. else
  7847. {
  7848. // Can not find valid message id
  7849. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7850. }
  7851. }
  7852. else
  7853. {
  7854. // Payload is null
  7855. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7856. }
  7857. LWS_Send(message);
  7858. return result;
  7859. }
  7860. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7861. {
  7862. mtrace();
  7863. int result = FAIL;
  7864. int connectorIdInt, durationInt;
  7865. char chargingRateUnitStr[4]={0};
  7866. char comfirmstr[20];
  7867. int confirmPeriods = 0;
  7868. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7869. json_object *GetCompositeSchedule;
  7870. GetCompositeSchedule = json_tokener_parse(payload);
  7871. if(!is_error(GetCompositeSchedule))
  7872. {
  7873. // Required data
  7874. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7875. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7876. else
  7877. connectorIdInt = -1;
  7878. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7879. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7880. else
  7881. durationInt = 86400;
  7882. // Optional data
  7883. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7884. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7885. }
  7886. json_object_put(GetCompositeSchedule);
  7887. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7888. if((connectorIdInt == 0) ||
  7889. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7890. {
  7891. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7892. struct StructChargingProfile tmpProfile[1];
  7893. if(strstr(chargingRateUnitStr, "W") != NULL)
  7894. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7895. else
  7896. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7897. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7898. {
  7899. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7900. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7901. }
  7902. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7903. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7904. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7905. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7906. {
  7907. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7908. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7909. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7910. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7911. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7912. {
  7913. confirmPeriods = idx;
  7914. break;
  7915. }
  7916. }
  7917. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7918. {
  7919. confirmPeriods += 1;
  7920. }
  7921. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7922. }
  7923. else
  7924. {
  7925. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7926. }
  7927. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7928. return result;
  7929. }
  7930. int handleGetConfigurationRequest(char *uuid, char *payload)
  7931. {
  7932. mtrace();
  7933. int result = FAIL;
  7934. int MaxKeySupported = 0;
  7935. int n_keys = 0;
  7936. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7937. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7938. json_object *GetConfiguration;
  7939. GetConfiguration = json_tokener_parse(payload);
  7940. if(!is_error(GetConfiguration))
  7941. {
  7942. // Optional data
  7943. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7944. {
  7945. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7946. {
  7947. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7948. n_keys = idx + 1;
  7949. }
  7950. }
  7951. }
  7952. json_object_put(GetConfiguration);
  7953. UnknownKeynum = 0;
  7954. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7955. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7956. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7957. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7958. if(n_keys != 0)
  7959. {
  7960. for(int i=0;i<n_keys;i++)
  7961. {
  7962. getKeyValue(requestKey[i]);
  7963. }
  7964. }
  7965. else
  7966. {
  7967. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7968. getKeyValue("");
  7969. }
  7970. processUnkownKey();
  7971. sendGetConfigurationConfirmation(uuid);
  7972. return result;
  7973. }
  7974. static char fnamePlusPath[100]={0};
  7975. static char fnamePWithNoPath[60]={0};
  7976. void checkUploadLog(void)
  7977. {
  7978. FILE *fp;
  7979. /* Open the command for reading. */
  7980. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7981. if (fp == NULL) {
  7982. DEBUG_WARN("Failed to run command\n" );
  7983. exit(1);
  7984. }
  7985. int ftppathlen = 0;
  7986. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7987. int i = 0;
  7988. /* Read the output a line at a time - output it. */
  7989. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7990. if(i==0)
  7991. {
  7992. ftppathlen = strlen(fnamePlusPath);
  7993. DEBUG_INFO("%s\n", fnamePlusPath);
  7994. fnamePlusPath[ftppathlen]='\0';
  7995. break;
  7996. }
  7997. i= i+1;
  7998. }
  7999. /* close */
  8000. pclose(fp);
  8001. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8002. {
  8003. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8004. {
  8005. fnamePlusPath[k]='\0';
  8006. }
  8007. }
  8008. i=1;
  8009. //char fname[60]={0};
  8010. while(i < ftppathlen)
  8011. {
  8012. int len=ftppathlen-i;
  8013. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8014. {
  8015. DEBUG_INFO("compare '/' all right\n");
  8016. break;
  8017. }
  8018. i=i+1;
  8019. }
  8020. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8021. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8022. fnamePWithNoPath[i+1] = '\0';
  8023. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8024. {
  8025. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8026. {
  8027. fnamePWithNoPath[j]='\0';
  8028. }
  8029. }
  8030. FILE* fp1 = fopen(fnamePlusPath, "r");
  8031. if (fp1)
  8032. {
  8033. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8034. // file exists
  8035. fclose(fp1);
  8036. }
  8037. else
  8038. {
  8039. // file doesn't exist
  8040. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8041. }
  8042. }
  8043. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8044. {
  8045. mtrace();
  8046. int result = FAIL;
  8047. time_t CurrentTime;
  8048. struct tm *tm;
  8049. pthread_t th_Status;
  8050. CurrentTime = time(NULL);
  8051. tm = localtime(&CurrentTime);
  8052. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8053. 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);
  8054. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8055. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8056. return result;
  8057. }
  8058. void* GetDiagnosticsProcess(void* data)
  8059. {
  8060. pthread_detach(pthread_self());
  8061. mtrace();
  8062. int retriesInt=0, retryIntervalInt=0;
  8063. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8064. 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};
  8065. int port=0;
  8066. int isSuccess = FALSE;
  8067. char cmdBuf[2048];
  8068. struct tm *tmNow;
  8069. time_t CurrentTime;
  8070. struct tm tmStart;
  8071. struct tm tmStop;
  8072. CurrentTime = time(NULL);
  8073. tmNow=localtime(&CurrentTime);
  8074. uint16_t targetYear, targetMonth;
  8075. json_object *GetDiagnostics;
  8076. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8077. GetDiagnostics = json_tokener_parse(data);
  8078. if(!is_error(GetDiagnostics))
  8079. {
  8080. // Required data
  8081. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8082. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8083. // Optional data
  8084. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8085. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8086. else
  8087. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8088. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8089. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8090. else
  8091. retryIntervalInt = 30;
  8092. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8093. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8094. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8095. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8096. }
  8097. json_object_put(GetDiagnostics);
  8098. // Pack log to compress file
  8099. 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) &&
  8100. (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))
  8101. {
  8102. // Pack system log
  8103. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8104. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8105. targetYear = tmStart.tm_year;
  8106. targetMonth = tmStart.tm_mon;
  8107. do
  8108. {
  8109. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8110. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8111. if(targetMonth+1>=13)
  8112. {
  8113. targetYear += 1;
  8114. targetMonth = 1;
  8115. }
  8116. else
  8117. {
  8118. targetMonth += 1;
  8119. }
  8120. }while((targetYear < (tmNow->tm_year+1900)) ||
  8121. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8122. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8123. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8124. system(cmdBuf);
  8125. // Pack charging & event log
  8126. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8127. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8128. targetYear = tmStart.tm_year;
  8129. targetMonth = tmStart.tm_mon;
  8130. do
  8131. {
  8132. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8133. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8134. if(targetMonth+1>=13)
  8135. {
  8136. targetYear += 1;
  8137. targetMonth = 1;
  8138. }
  8139. else
  8140. {
  8141. targetMonth += 1;
  8142. }
  8143. }while((targetYear < (tmNow->tm_year+1900)) ||
  8144. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8145. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8146. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8147. system(cmdBuf);
  8148. // Combine log file
  8149. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8150. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8151. }
  8152. else
  8153. {
  8154. system("exec /root/logPackTools 'log' 6");
  8155. }
  8156. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8157. system(cmdBuf);
  8158. checkUploadLog();
  8159. //****************location*******************/
  8160. if(strcmp(locationstr,"")==0)
  8161. {
  8162. DEBUG_INFO("location is <Empty>!\n");
  8163. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8164. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8165. goto end;
  8166. }
  8167. memset(protocol, 0, ARRAY_SIZE(protocol));
  8168. memset(user, 0, ARRAY_SIZE(user) );
  8169. memset(password, 0, ARRAY_SIZE(password));
  8170. memset(host, 0, ARRAY_SIZE(host));
  8171. memset(path, 0, ARRAY_SIZE(path));
  8172. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8173. memset(host1, 0, ARRAY_SIZE(host1));
  8174. memset(path1, 0, ARRAY_SIZE(path1));
  8175. /*location: ftp://user:password@host:port/path*/
  8176. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8177. if((access(fnamePlusPath,F_OK))!=-1)
  8178. {
  8179. DEBUG_INFO("fnamePlusPath exist.\n");
  8180. }
  8181. else
  8182. {
  8183. DEBUG_INFO("fnamePlusPath not exist!\n");
  8184. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8185. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8186. goto end;
  8187. }
  8188. if(strchr(locationstr,'@')==NULL)
  8189. {
  8190. sscanf(locationstr,
  8191. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8192. protocol, host, &port, path);
  8193. strcpy(user,"anonymous");
  8194. strcpy(password,"");
  8195. }
  8196. else
  8197. {
  8198. //DEBUG_INFO("pch=%s\n", pch);
  8199. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8200. protocol, user, password, host, &port, path);
  8201. }
  8202. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8203. {
  8204. DEBUG_INFO("protocol is not ftp/http ! \n");
  8205. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8206. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8207. goto end;
  8208. }
  8209. if(strncmp(locationstr,"http", 4) == 0)
  8210. {
  8211. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8212. sprintf(ftppath,"/%s", path);
  8213. do
  8214. {
  8215. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8216. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8217. sleep(3);
  8218. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8219. if(!isSuccess)
  8220. {
  8221. DEBUG_INFO("Diagnostics fail.\n");
  8222. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8223. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8224. sleep(retryIntervalInt);
  8225. }
  8226. else
  8227. {
  8228. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8229. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8230. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8231. }
  8232. retriesInt--;
  8233. }while((isSuccess == 0)&&(retriesInt >= 0));
  8234. }
  8235. else
  8236. {
  8237. sscanf(host,"%[^/]%s",host1, path1);
  8238. if(strlen(path) > 0)
  8239. sprintf(ftppath,"/%s", path);
  8240. else
  8241. sprintf(ftppath,"/%s", path1);
  8242. int ftppathlen=strlen(ftppath);
  8243. int i=1;
  8244. char filenametemp[50];
  8245. while(i < ftppathlen)
  8246. {
  8247. int len=ftppathlen-i;
  8248. if(ftppath[len]== 47) // '/' ascll code: 47
  8249. {
  8250. DEBUG_INFO("find '/' all right\n");
  8251. break;
  8252. }
  8253. i=i+1;
  8254. }
  8255. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8256. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8257. filenametemp[i+1] = 0;
  8258. if(port == 0)
  8259. port = 21;
  8260. do
  8261. {
  8262. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8263. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8264. sleep(3);
  8265. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8266. if(!isSuccess)
  8267. {
  8268. DEBUG_INFO("Diagnostics fail.\n");
  8269. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8270. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8271. sleep(retryIntervalInt);
  8272. }
  8273. else
  8274. {
  8275. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8276. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8277. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8278. }
  8279. retriesInt--;
  8280. }while((!isSuccess)&&(retriesInt >= 0));
  8281. }
  8282. end:
  8283. system("rm -f /mnt/*");
  8284. sleep(5);
  8285. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8286. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8287. pthread_exit(NULL);
  8288. }
  8289. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8290. {
  8291. mtrace();
  8292. int result = FAIL;
  8293. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8294. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8295. {
  8296. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8297. locallistVersion = -1;
  8298. }
  8299. else
  8300. {
  8301. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8302. OCPP_getListVerion();
  8303. }
  8304. //from db.OCPP_getListVerion
  8305. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8306. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8307. sendGetLocalListVersionConfirmation(uuid,"");
  8308. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8309. return result;
  8310. }
  8311. int handleRemoteStartRequest(char *uuid, char *payload)
  8312. {
  8313. mtrace();
  8314. int result = FAIL;
  8315. int connectorIdInt=0;
  8316. int tempIndex = 0;
  8317. int connectorIdIsNULL, chargingProfileIsNULL;
  8318. char comfirmstr[20]={0};
  8319. char cmdBuf[512];
  8320. json_object *RemoteStartTransaction;
  8321. FILE *fp;
  8322. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8323. if(server_pending == TRUE)
  8324. {
  8325. return 0;
  8326. }
  8327. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8328. RemoteStartTransaction = json_tokener_parse(payload);
  8329. if(!is_error(RemoteStartTransaction))
  8330. {
  8331. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8332. {
  8333. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8334. if(connectorIdInt <= gunTotalNumber)
  8335. {
  8336. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8337. // Required data
  8338. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8339. // Optional data
  8340. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8341. {
  8342. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8343. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8344. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8345. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8346. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8347. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8348. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8349. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8350. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8351. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8352. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8353. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8354. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8355. {
  8356. 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")));
  8357. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8358. 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"));
  8359. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8360. 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"));
  8361. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8362. 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")));
  8363. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8364. {
  8365. 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++)
  8366. {
  8367. 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"));
  8368. 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"));
  8369. 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)
  8370. 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"));
  8371. }
  8372. }
  8373. }
  8374. }
  8375. else
  8376. chargingProfileIsNULL = TRUE;
  8377. }
  8378. }
  8379. else
  8380. connectorIdIsNULL = TRUE;
  8381. }
  8382. else
  8383. connectorIdIsNULL = TRUE;
  8384. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8385. {
  8386. DEBUG_WARN("Connector id is NULL\n.");
  8387. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8388. goto end;
  8389. }
  8390. /*
  8391. enum _SYSTEM_STATUS
  8392. {
  8393. S_BOOTING = 0,
  8394. S_IDLE, = 1
  8395. S_AUTHORIZING, = 2
  8396. S_REASSIGN_CHECK, = 3
  8397. S_REASSIGN, = 4
  8398. S_PRECHARGE, = 5
  8399. S_PREPARING_FOR_EV, = 6
  8400. S_PREPARING_FOR_EVSE, = 7
  8401. S_CHARGING, = 8
  8402. S_TERMINATING, = 9
  8403. S_COMPLETE, = 10
  8404. S_ALARM, = 11
  8405. S_FAULT = 12
  8406. }
  8407. */
  8408. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8409. {
  8410. //check Transaction active
  8411. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8412. {
  8413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8414. {
  8415. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8416. }
  8417. else
  8418. {
  8419. tempIndex = connectorIdInt -1;
  8420. }
  8421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8422. {
  8423. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8424. {
  8425. 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))
  8426. {
  8427. //Reserved
  8428. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8429. }
  8430. 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))
  8431. {
  8432. //Reserved
  8433. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8434. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8435. goto end;
  8436. }
  8437. else
  8438. {
  8439. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8440. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8441. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8442. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8443. {
  8444. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8445. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8446. goto end;
  8447. }
  8448. }//END FOR ELSE
  8449. }
  8450. }// END FOR CHAdeMO_QUANTITY
  8451. }
  8452. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8453. {
  8454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8455. {
  8456. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8457. }
  8458. else
  8459. {
  8460. tempIndex = connectorIdInt -1;
  8461. }
  8462. for (int index = 0; index < CCS_QUANTITY; index++)
  8463. {
  8464. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8465. {
  8466. 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))
  8467. {
  8468. //Reserved
  8469. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8470. }
  8471. 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))
  8472. {
  8473. //Reserved
  8474. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8475. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8476. goto end;
  8477. }
  8478. else
  8479. {
  8480. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8481. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8482. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8483. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8484. {
  8485. DEBUG_WARN("CCS connector not allow start\n.");
  8486. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8487. goto end;
  8488. }
  8489. }// END FOR ELSE
  8490. }
  8491. }// END FOR CCS_QUANTITY
  8492. }
  8493. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8494. {
  8495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8496. {
  8497. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8498. }
  8499. else
  8500. {
  8501. tempIndex = connectorIdInt -1;
  8502. }
  8503. for (int index = 0; index < GB_QUANTITY; index++)
  8504. {
  8505. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8506. {
  8507. 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))
  8508. {
  8509. //Reserved
  8510. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8511. }
  8512. 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))
  8513. {
  8514. //Reserved
  8515. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8516. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8517. goto end;
  8518. }
  8519. else
  8520. {
  8521. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8522. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8523. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8524. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8525. {
  8526. DEBUG_WARN("GB connector not allow start\n.");
  8527. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8528. goto end;
  8529. }
  8530. }// END FOR ELSE
  8531. }
  8532. } // END FOR GB_QUANTITY
  8533. }
  8534. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8535. {
  8536. tempIndex = connectorIdInt -1;
  8537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8538. {
  8539. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8540. {
  8541. 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))
  8542. {
  8543. //Reserved
  8544. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8545. }
  8546. 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))
  8547. {
  8548. //Reserved
  8549. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8550. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8551. goto end;
  8552. }
  8553. else
  8554. {
  8555. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8556. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8557. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8558. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8559. {
  8560. DEBUG_WARN("GB connector not allow start\n.");
  8561. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8562. goto end;
  8563. }
  8564. }// END FOR ELSE
  8565. }
  8566. } // END FOR GB_QUANTITY
  8567. }
  8568. else
  8569. {
  8570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8571. {
  8572. tempIndex = 2;
  8573. }
  8574. else
  8575. {
  8576. tempIndex = connectorIdInt -1;
  8577. }
  8578. for (int index = 0; index < AC_QUANTITY; index++)
  8579. {
  8580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8581. {
  8582. 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))
  8583. {
  8584. //Reserved
  8585. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8586. }
  8587. 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))
  8588. {
  8589. //Reserved
  8590. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8591. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8592. goto end;
  8593. }
  8594. else
  8595. {
  8596. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8597. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8598. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8599. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8600. {
  8601. DEBUG_WARN("AC connector not allow start\n.");
  8602. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8603. goto end;
  8604. }
  8605. }//END FOR ELSE
  8606. }
  8607. }// END FOR AC_QUANTITY
  8608. }
  8609. if(chargingProfileIsNULL == FALSE)
  8610. {
  8611. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8612. {
  8613. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8614. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8615. //memset idTag
  8616. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8617. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8618. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8619. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8620. // Save profile to file
  8621. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8622. system(cmdBuf);
  8623. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8624. fp = fopen(cmdBuf, "w");
  8625. 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));
  8626. fclose(fp);
  8627. }
  8628. else
  8629. {
  8630. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8632. }
  8633. }
  8634. else
  8635. {
  8636. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8637. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8638. //memset idTag
  8639. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8640. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8641. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8642. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8643. }
  8644. }
  8645. else
  8646. {
  8647. DEBUG_WARN("Connector id over\n.");
  8648. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8649. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8650. }
  8651. end:
  8652. json_object_put(RemoteStartTransaction);
  8653. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8654. {
  8655. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8656. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8657. }
  8658. //OCPP send RemoteStartConfirmation by first.
  8659. sendRemoteStartConfirmation(uuid, comfirmstr);
  8660. return result;
  8661. }
  8662. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8663. {
  8664. mtrace();
  8665. int result = FAIL;
  8666. int match = FALSE;
  8667. int GunNO = 0;
  8668. int tempIndex = 0;
  8669. int transactionIdInt=0;
  8670. int transactionIdIsNULL= TRUE;
  8671. char comfirmstr[20];
  8672. json_object *RemoteStopTransaction;
  8673. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8674. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8675. if(server_pending == TRUE)
  8676. {
  8677. return 0;
  8678. }
  8679. RemoteStopTransaction = json_tokener_parse(payload);
  8680. if(!is_error(RemoteStopTransaction))
  8681. {
  8682. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8683. {
  8684. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8685. transactionIdIsNULL = FALSE;
  8686. }
  8687. }
  8688. json_object_put(RemoteStopTransaction);
  8689. if(transactionIdIsNULL == FALSE)
  8690. {
  8691. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8692. {
  8693. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8694. {
  8695. //check Transaction active
  8696. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8697. {
  8698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8699. {
  8700. tempIndex = ((gun_index==2) ? 1: 0);
  8701. }
  8702. else
  8703. {
  8704. tempIndex = gun_index;
  8705. }
  8706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8707. {
  8708. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8709. {
  8710. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8711. {
  8712. match = TRUE;
  8713. GunNO = gun_index;
  8714. }
  8715. }
  8716. }// END FOR CHAdeMO_QUANTITY
  8717. }
  8718. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8719. {
  8720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8721. {
  8722. tempIndex = ((gun_index==2) ? 1: 0);
  8723. }
  8724. else
  8725. {
  8726. tempIndex = gun_index;
  8727. }
  8728. for (int index = 0; index < CCS_QUANTITY; index++)
  8729. {
  8730. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8731. {
  8732. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8733. {
  8734. match = TRUE;
  8735. GunNO = gun_index;
  8736. }
  8737. }
  8738. }// END FOR CCS_QUANTITY
  8739. }
  8740. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8741. {
  8742. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8743. {
  8744. tempIndex = ((gun_index==2) ? 1: 0);
  8745. }
  8746. else
  8747. {
  8748. tempIndex = gun_index;
  8749. }
  8750. for (int index = 0; index < GB_QUANTITY; index++)
  8751. {
  8752. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8753. {
  8754. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8755. {
  8756. match = TRUE;
  8757. GunNO = gun_index;
  8758. }
  8759. }
  8760. }// END FOR GB_QUANTITY
  8761. }
  8762. else if(gunType[gun_index] == GUN_TYPE_DO)
  8763. {
  8764. tempIndex = gun_index;
  8765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8766. {
  8767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8768. {
  8769. 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
  8770. {
  8771. match = TRUE;
  8772. GunNO = gun_index;
  8773. }
  8774. }
  8775. }// END FOR GB_QUANTITY
  8776. }
  8777. else
  8778. {
  8779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8780. {
  8781. tempIndex = 2;
  8782. }
  8783. else
  8784. {
  8785. tempIndex = gun_index;
  8786. }
  8787. for (int index = 0; index < AC_QUANTITY; index++)
  8788. {
  8789. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8790. {
  8791. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8792. {
  8793. match = TRUE;
  8794. GunNO = gun_index;
  8795. }
  8796. }
  8797. }// END FOR CHAdeMO_QUANTITY
  8798. } // END FOR AC ELSE
  8799. }// CHECK IF ResponseTransactionId == transactionIdInt
  8800. }//END FOR
  8801. if( match == TRUE)
  8802. {
  8803. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8804. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8805. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8806. }
  8807. else
  8808. {
  8809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8810. }
  8811. }
  8812. else
  8813. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8814. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8815. return result;
  8816. }
  8817. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8818. {
  8819. mtrace();
  8820. int result = FAIL;
  8821. int connectorIdInt=0, reservationIdInt=0;
  8822. int tempIndex = 0;
  8823. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8824. char comfirmstr[20]={0};
  8825. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8826. int c = 0;
  8827. char *loc;
  8828. //char *ptr;
  8829. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8830. strcpy(sstrtemp, stringtrimspace(payload));
  8831. //***(1)connectorId ****/
  8832. c=0;
  8833. loc = strstr(sstrtemp, "connectorId");
  8834. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8835. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8836. {
  8837. sstr[c] = loc[strlen("connectorId")+2+c];
  8838. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8839. c++;
  8840. }
  8841. sstr[c] = '\0';
  8842. connectorIdInt = atoi(sstr);
  8843. //***(2)expiryDate ****/
  8844. loc = strstr(sstrtemp, "expiryDate");
  8845. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8846. c = 0;
  8847. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8848. {
  8849. sstr[c] = loc[3+strlen("expiryDate")+c];
  8850. c++;
  8851. }
  8852. sstr[c] = '\0';
  8853. strcpy(expiryDatestr, sstr);
  8854. //***(3)idTag ****/
  8855. loc = strstr(sstrtemp, "idTag");
  8856. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8857. c = 0;
  8858. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8859. {
  8860. sstr[c] = loc[3+strlen("idTag")+c];
  8861. c++;
  8862. }
  8863. sstr[c] = '\0';
  8864. strcpy(idTagstr, sstr);
  8865. //***(4)parentIdTag ****/
  8866. loc = strstr(sstrtemp, "parentIdTag");
  8867. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8868. c = 0;
  8869. if(loc == NULL)
  8870. {
  8871. strcpy(parentIdTagstr, "");
  8872. }
  8873. else
  8874. {
  8875. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8876. {
  8877. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8878. c++;
  8879. }
  8880. sstr[c] = '\0';
  8881. strcpy(parentIdTagstr, sstr);
  8882. }
  8883. //***(5)reservationId ****/
  8884. c=0;
  8885. loc = strstr(sstrtemp, "reservationId");
  8886. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8887. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8888. {
  8889. sstr[c] = loc[strlen("reservationId")+2+c];
  8890. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8891. c++;
  8892. }
  8893. sstr[c] = '\0';
  8894. reservationIdInt = atoi(sstr);
  8895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8896. /*
  8897. enum SYSTEM_STATUS
  8898. {
  8899. SYS_MODE_BOOTING = 0,
  8900. SYS_MODE_IDLE = 1,
  8901. SYS_MODE_AUTHORIZING = 2,
  8902. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8903. SYS_MODE_REASSIGN = 4,
  8904. SYS_MODE_PREPARING = 5,
  8905. SYS_MODE_PREPARE_FOR_EV = 6,
  8906. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8907. SYS_MODE_CHARGING = 8,
  8908. SYS_MODE_TERMINATING = 9,
  8909. SYS_MODE_COMPLETE = 10,
  8910. SYS_MODE_ALARM = 11,
  8911. SYS_MODE_FAULT = 12,
  8912. SYS_MODE_RESERVATION = 13,
  8913. SYS_MODE_BOOKING = 14,
  8914. SYS_MODE_MAINTAIN = 15,
  8915. SYS_MODE_DEBUG = 16,
  8916. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8917. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8918. SYS_MODE_UPDATE = 19
  8919. };
  8920. */
  8921. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8922. {
  8923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8924. goto end;
  8925. }
  8926. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8927. {
  8928. //check Transaction active
  8929. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8930. {
  8931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8932. {
  8933. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8934. }
  8935. else
  8936. {
  8937. tempIndex = connectorIdInt -1;
  8938. }
  8939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8940. {
  8941. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8942. {
  8943. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8944. {
  8945. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8946. {
  8947. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8948. {
  8949. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8951. }
  8952. 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'))
  8953. {
  8954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8955. }
  8956. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8957. {
  8958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8959. }
  8960. else
  8961. {
  8962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8963. }
  8964. }
  8965. 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
  8966. {
  8967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8968. }
  8969. }
  8970. else
  8971. {
  8972. //replace reservation
  8973. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8975. }
  8976. }
  8977. } // END FOR CHAdeMO_QUANTITY
  8978. }
  8979. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8980. {
  8981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8982. {
  8983. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8984. }
  8985. else
  8986. {
  8987. tempIndex = connectorIdInt -1;
  8988. }
  8989. for (int index = 0; index < CCS_QUANTITY; index++)
  8990. {
  8991. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8992. {
  8993. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8994. {
  8995. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8996. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8997. {
  8998. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8999. {
  9000. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9002. }
  9003. 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'))
  9004. {
  9005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9006. }
  9007. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9008. {
  9009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9010. }
  9011. else
  9012. {
  9013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9014. }
  9015. }
  9016. 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
  9017. {
  9018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9019. }
  9020. }
  9021. else
  9022. {
  9023. //replace reservation
  9024. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9026. }
  9027. }
  9028. } // END FOR CCS_QUANTITY
  9029. }
  9030. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9031. {
  9032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9033. {
  9034. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9035. }
  9036. else
  9037. {
  9038. tempIndex = connectorIdInt -1;
  9039. }
  9040. for (int index = 0; index < GB_QUANTITY; index++)
  9041. {
  9042. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9043. {
  9044. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9045. {
  9046. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9047. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9048. {
  9049. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9050. {
  9051. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9053. }
  9054. 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'))
  9055. {
  9056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9057. }
  9058. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9059. {
  9060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9061. }
  9062. else
  9063. {
  9064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9065. }
  9066. }
  9067. 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
  9068. {
  9069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9070. }
  9071. }
  9072. else
  9073. {
  9074. //replace reservation
  9075. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9077. }
  9078. }
  9079. }// END FOR GB_QUANTITY
  9080. }
  9081. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9082. {
  9083. tempIndex = connectorIdInt -1;
  9084. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9085. {
  9086. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9087. {
  9088. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9089. {
  9090. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9091. 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
  9092. {
  9093. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9094. {
  9095. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9097. }
  9098. 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'))
  9099. {
  9100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9101. }
  9102. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9103. {
  9104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9105. }
  9106. else
  9107. {
  9108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9109. }
  9110. }
  9111. 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
  9112. {
  9113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9114. }
  9115. }
  9116. else
  9117. {
  9118. //replace reservation
  9119. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9121. }
  9122. }
  9123. }// END FOR GB_QUANTITY
  9124. }
  9125. else
  9126. {
  9127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9128. {
  9129. tempIndex = 2;
  9130. }
  9131. else
  9132. {
  9133. tempIndex = (connectorIdInt -1);
  9134. }
  9135. for (int index = 0; index < AC_QUANTITY; index++)
  9136. {
  9137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9138. {
  9139. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9140. {
  9141. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9142. {
  9143. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9144. {
  9145. 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))
  9146. {
  9147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9148. }
  9149. else
  9150. {
  9151. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9153. }
  9154. }
  9155. 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'))
  9156. {
  9157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9158. }
  9159. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9160. {
  9161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9162. }
  9163. else
  9164. {
  9165. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9166. }
  9167. }
  9168. 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
  9169. {
  9170. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9171. }
  9172. }
  9173. else
  9174. {
  9175. //replace reservation
  9176. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9178. }
  9179. }
  9180. } // END FOR AC_QUANTITY
  9181. }
  9182. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9183. }
  9184. else if(connectorIdInt == 0)
  9185. {
  9186. //check Transaction active
  9187. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9188. {
  9189. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9190. {
  9191. 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'))
  9192. {
  9193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9194. goto end;
  9195. }
  9196. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9197. {
  9198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9199. goto end;
  9200. }
  9201. 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
  9202. {
  9203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9204. goto end;
  9205. }
  9206. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9207. {
  9208. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9209. goto end;
  9210. }
  9211. }
  9212. }// END FOR CHAdeMO_QUANTITY
  9213. for (int index = 0; index < CCS_QUANTITY; index++)
  9214. {
  9215. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9216. {
  9217. 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'))
  9218. {
  9219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9220. goto end;
  9221. }
  9222. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9223. {
  9224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9225. goto end;
  9226. }
  9227. 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
  9228. {
  9229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9230. goto end;
  9231. }
  9232. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9233. {
  9234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9235. goto end;
  9236. }
  9237. }
  9238. } // END FOR CCS_QUANTITY
  9239. for (int index = 0; index < GB_QUANTITY; index++)
  9240. {
  9241. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9242. {
  9243. 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'))
  9244. {
  9245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9246. goto end;
  9247. }
  9248. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9249. {
  9250. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9251. goto end;
  9252. }
  9253. 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
  9254. {
  9255. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9256. goto end;
  9257. }
  9258. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9259. {
  9260. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9261. goto end;
  9262. }
  9263. }
  9264. } // END FOR GB_QUANTITY
  9265. for (int index = 0; index < AC_QUANTITY; index++)
  9266. {
  9267. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9268. {
  9269. 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'))
  9270. {
  9271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9272. goto end;
  9273. }
  9274. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9275. {
  9276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9277. goto end;
  9278. }
  9279. 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
  9280. {
  9281. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9282. goto end;
  9283. }
  9284. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9285. {
  9286. 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))
  9287. {
  9288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9289. goto end;
  9290. }
  9291. }
  9292. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9293. {
  9294. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9295. goto end;
  9296. }
  9297. }
  9298. }// END FOR AC_QUANTITY
  9299. //The connectorId is 0
  9300. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9301. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9302. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9303. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9304. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9305. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9306. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9307. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9308. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9309. result = TRUE;
  9310. return result;
  9311. }
  9312. else
  9313. {
  9314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9315. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9316. }
  9317. if(strcmp(comfirmstr,"Accepted") == 0)
  9318. {
  9319. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9320. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9321. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9322. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9323. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9324. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9325. result = TRUE;
  9326. return result;
  9327. }
  9328. end:
  9329. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9330. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9331. return result;
  9332. }
  9333. int handleResetRequest(char *uuid, char *payload)
  9334. {
  9335. mtrace();
  9336. int result = FAIL;
  9337. char sstr[10]={0},sstrtemp[30]={ 0 };
  9338. char typestr[10]={0};
  9339. char comfirmstr[20]={0};
  9340. int c = 0;
  9341. char *loc;
  9342. DEBUG_INFO("handleResetRequest...\n");
  9343. strcpy(sstrtemp, stringtrimspace(payload));
  9344. loc = strstr(sstrtemp, "type");
  9345. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9346. c = 0;
  9347. while (loc[3+strlen("type")+c] != '\"')
  9348. {
  9349. sstr[c] = loc[3+strlen("type")+c];
  9350. c++;
  9351. }
  9352. sstr[c] = '\0';
  9353. strcpy(typestr,sstr);
  9354. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9355. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9356. {
  9357. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9358. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9359. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9360. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9361. }
  9362. else
  9363. {
  9364. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9365. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9366. result = PASS;
  9367. }
  9368. sendResetConfirmation(uuid, comfirmstr);
  9369. return result;
  9370. }
  9371. int handleSendLocalListRequest(char *uuid, char *payload)
  9372. {
  9373. mtrace();
  9374. int result = FAIL;
  9375. char comfirmstr[20];
  9376. int checkState_Faulted = FALSE;
  9377. json_object *SendLocalList;
  9378. DEBUG_INFO("handleSendLocalListRequest...\n");
  9379. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9380. {
  9381. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9382. goto end;
  9383. }
  9384. //check Charge Point state
  9385. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9386. {
  9387. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9388. {
  9389. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9390. }
  9391. }
  9392. for (int index = 0; index < CCS_QUANTITY; index++)
  9393. {
  9394. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9395. {
  9396. checkState_Faulted = TRUE; //OCPP Status
  9397. }
  9398. }
  9399. for (int index = 0; index < GB_QUANTITY; index++)
  9400. {
  9401. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9402. {
  9403. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9404. }
  9405. }
  9406. //check Charge Point state
  9407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9408. {
  9409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9410. {
  9411. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9412. }
  9413. }
  9414. //check Charge Point state
  9415. for (int index = 0; index < AC_QUANTITY; index++)
  9416. {
  9417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9418. {
  9419. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9420. }
  9421. }
  9422. if(checkState_Faulted == TRUE)
  9423. {
  9424. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9425. goto end;
  9426. }
  9427. // Parsing payload
  9428. SendLocalList = json_tokener_parse(payload);
  9429. if(!is_error(SendLocalList))
  9430. {
  9431. // Required data
  9432. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9433. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9434. // Optional data
  9435. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9436. {
  9437. //Check UpdateType
  9438. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9439. {
  9440. //Local list full update
  9441. DEBUG_INFO("Local list full update.\n");
  9442. OCPP_getListVerion();
  9443. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9444. {
  9445. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9446. goto end;
  9447. }
  9448. OCPP_cleanLocalList();
  9449. }
  9450. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9451. {
  9452. //Local list different update
  9453. DEBUG_INFO("Local list different update.\n");
  9454. OCPP_getListVerion();
  9455. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9456. {
  9457. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9458. goto end;
  9459. }
  9460. }
  9461. else
  9462. {
  9463. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9464. goto end;
  9465. }
  9466. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9467. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9468. {
  9469. 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")));
  9470. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9471. {
  9472. 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")));
  9473. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9474. 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")));
  9475. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9476. 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")));
  9477. }
  9478. // Add to db
  9479. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9480. {
  9481. //Local list full update
  9482. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9483. idx,
  9484. ShmOCPP16Data->SendLocalList.ListVersion,
  9485. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9486. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9487. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9488. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9489. // update list
  9490. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9491. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9492. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9493. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9494. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9495. }
  9496. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9497. {
  9498. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9499. idx,
  9500. ShmOCPP16Data->SendLocalList.ListVersion,
  9501. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9502. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9503. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9504. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9505. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9506. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9507. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9508. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9509. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9510. }
  9511. }
  9512. }
  9513. else
  9514. {
  9515. //Check UpdateType
  9516. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9517. {
  9518. //Local list full update
  9519. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9520. OCPP_cleanLocalList();
  9521. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9522. goto end;
  9523. }
  9524. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9525. {
  9526. //Local list different update
  9527. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9528. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9529. goto end;
  9530. }
  9531. }
  9532. result = PASS;
  9533. }
  9534. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9535. end:
  9536. json_object_put(SendLocalList);
  9537. sendSendLocalListConfirmation(uuid, comfirmstr);
  9538. return result;
  9539. }
  9540. #define MAX 200
  9541. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9542. {
  9543. mtrace();
  9544. int result = FAIL;
  9545. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9546. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9547. char chargingProfilePurposeStr[30]={0};
  9548. char chargingProfileKindStr[16]={0};
  9549. char recurrencyKindStr[10]={0};
  9550. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9551. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9552. int chargingSchedulePeriodCount = 0;
  9553. char comfirmstr[20]={0};
  9554. int meet= FALSE;
  9555. FILE *fptr1;
  9556. char filename[MAX]={0};
  9557. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9558. char rmFileCmd[50]={0};
  9559. char tempchargingProfilePurposeStr[30]={0};
  9560. char word[1600]={0};
  9561. int n_chargingProfile = 0;
  9562. json_object *SetChargingProfile;
  9563. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9564. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9565. SetChargingProfile = json_tokener_parse(payload);
  9566. if(!is_error(SetChargingProfile))
  9567. {
  9568. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9569. {
  9570. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9571. if(connectorIdInt == 0)
  9572. {
  9573. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9574. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9575. }
  9576. else
  9577. {
  9578. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9579. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9580. }
  9581. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9582. }
  9583. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9584. {
  9585. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9586. {
  9587. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9588. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9589. {
  9590. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9591. }
  9592. else
  9593. {
  9594. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9595. }
  9596. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9597. }
  9598. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9599. {
  9600. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9601. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9602. {
  9603. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9604. }
  9605. else
  9606. {
  9607. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9608. }
  9609. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9610. }
  9611. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9612. {
  9613. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9614. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9615. {
  9616. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9617. }
  9618. else
  9619. {
  9620. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9621. }
  9622. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9623. }
  9624. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9625. {
  9626. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9627. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9628. {
  9629. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9630. }
  9631. else
  9632. {
  9633. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9634. }
  9635. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9636. }
  9637. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9638. {
  9639. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9640. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9641. {
  9642. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9643. }
  9644. else
  9645. {
  9646. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9647. }
  9648. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9649. }
  9650. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9651. {
  9652. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9653. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9654. {
  9655. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9656. }
  9657. else
  9658. {
  9659. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9660. }
  9661. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9662. }
  9663. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9664. {
  9665. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9666. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9667. {
  9668. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9669. }
  9670. else
  9671. {
  9672. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9673. }
  9674. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9675. }
  9676. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9677. {
  9678. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9679. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9680. {
  9681. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9682. }
  9683. else
  9684. {
  9685. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9686. }
  9687. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9688. }
  9689. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9690. {
  9691. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9692. {
  9693. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9694. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9695. {
  9696. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9697. }
  9698. else
  9699. {
  9700. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9701. }
  9702. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9703. }
  9704. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9705. {
  9706. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9707. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9708. {
  9709. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9710. }
  9711. else
  9712. {
  9713. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9714. }
  9715. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9716. }
  9717. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9718. {
  9719. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9720. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9721. {
  9722. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9723. }
  9724. else
  9725. {
  9726. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9727. }
  9728. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9729. }
  9730. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9731. {
  9732. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9733. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9734. {
  9735. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9736. }
  9737. else
  9738. {
  9739. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9740. }
  9741. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9742. }
  9743. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9744. {
  9745. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9746. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9747. if(chargingSchedulePeriodCount <= 10)
  9748. {
  9749. 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++)
  9750. {
  9751. 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)
  9752. {
  9753. 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"));
  9754. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9755. {
  9756. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9757. }
  9758. else
  9759. {
  9760. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9761. }
  9762. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9763. }
  9764. 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)
  9765. {
  9766. 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"));
  9767. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9768. {
  9769. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9770. }
  9771. else
  9772. {
  9773. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9774. }
  9775. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9776. }
  9777. 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)
  9778. {
  9779. 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"));
  9780. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9781. {
  9782. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9783. }
  9784. else
  9785. {
  9786. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9787. }
  9788. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9789. }
  9790. }
  9791. }
  9792. }
  9793. }
  9794. }
  9795. }
  9796. json_object_put(SetChargingProfile);
  9797. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9798. {
  9799. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9800. goto end;
  9801. }
  9802. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9803. {
  9804. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9805. if(connectorIdInt != 0)
  9806. {
  9807. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9808. goto end;
  9809. }
  9810. strcpy(filename, ChargePointMaxProfile_JSON );
  9811. fptr1 = fopen(filename, "r");
  9812. if (!fptr1)
  9813. {
  9814. //file not exist
  9815. DEBUG_INFO("Unable to open the input file!!\n");
  9816. fptr1 = fopen(filename, "w+");
  9817. }
  9818. else
  9819. {
  9820. //Check Charging Profile Count
  9821. while(fscanf(fptr1, "%s", word) != EOF)
  9822. {
  9823. //DEBUG_INFO("word=%s\n",word);
  9824. if(strstr(word, "chargingProfileId")!= NULL)
  9825. {
  9826. //DEBUG_INFO("test chargingProfileId \n");
  9827. n_chargingProfile = n_chargingProfile + 1;
  9828. //DEBUG_INFO("chargingProfileId Found\n");
  9829. }
  9830. }
  9831. }
  9832. fclose(fptr1);
  9833. }
  9834. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9835. {
  9836. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9837. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9838. {
  9839. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9840. goto end;
  9841. }
  9842. memset(filename, 0, ARRAY_SIZE(filename));
  9843. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9844. fptr1 = fopen(filename, "r");
  9845. if (!fptr1)
  9846. {
  9847. //file not exist
  9848. //DEBUG_INFO("Unable to open the input file!!\n");
  9849. fptr1 = fopen(filename, "w+");
  9850. }
  9851. else
  9852. {
  9853. //Check Charging Profile Count
  9854. while(fscanf(fptr1, "%s", word) != EOF)
  9855. {
  9856. //DEBUG_INFO("word=%s\n",word);
  9857. if(strstr(word, "chargingProfileId")!= NULL)
  9858. {
  9859. //DEBUG_INFO("test chargingProfileId \n");
  9860. n_chargingProfile = n_chargingProfile + 1;
  9861. //DEBUG_INFO("chargingProfileId Found\n");
  9862. }
  9863. }
  9864. }
  9865. fclose(fptr1);
  9866. }
  9867. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9868. {
  9869. //printf("set chargingProfile 1-4\n");
  9870. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9871. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9872. if(connectorIdInt == 0)
  9873. {
  9874. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9875. goto end;
  9876. }
  9877. int tempIndex = 0;
  9878. //check Transaction active
  9879. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9880. {
  9881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9882. {
  9883. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9884. }
  9885. else
  9886. {
  9887. tempIndex = connectorIdInt -1;
  9888. }
  9889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9890. {
  9891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9892. {
  9893. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9894. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9895. {
  9896. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9897. {
  9898. meet = TRUE;
  9899. break;
  9900. }
  9901. }
  9902. }
  9903. }
  9904. }
  9905. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9906. {
  9907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9908. {
  9909. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9910. }
  9911. else
  9912. {
  9913. tempIndex = connectorIdInt -1;
  9914. }
  9915. for (int index = 0; index < CCS_QUANTITY; index++)
  9916. {
  9917. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9918. {
  9919. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9920. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9921. {
  9922. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9923. {
  9924. meet = TRUE;
  9925. break;
  9926. }
  9927. }
  9928. }
  9929. }
  9930. }
  9931. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9932. {
  9933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9934. {
  9935. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9936. }
  9937. else
  9938. {
  9939. tempIndex = connectorIdInt -1;
  9940. }
  9941. for (int index = 0; index < GB_QUANTITY; index++)
  9942. {
  9943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9944. {
  9945. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9946. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9947. {
  9948. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9949. {
  9950. meet = TRUE;
  9951. break;
  9952. }
  9953. }
  9954. }
  9955. }
  9956. }
  9957. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9958. {
  9959. tempIndex = connectorIdInt -1;
  9960. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9961. {
  9962. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9963. {
  9964. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9965. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9966. {
  9967. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9968. {
  9969. meet = TRUE;
  9970. break;
  9971. }
  9972. }
  9973. }
  9974. }
  9975. }
  9976. else
  9977. {
  9978. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9979. {
  9980. tempIndex = 2;
  9981. }
  9982. else
  9983. {
  9984. tempIndex = (connectorIdInt -1);
  9985. }
  9986. for (int index = 0; index < AC_QUANTITY; index++)
  9987. {
  9988. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9989. {
  9990. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9991. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9992. {
  9993. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9994. {
  9995. meet = TRUE;
  9996. break;
  9997. }
  9998. }
  9999. }
  10000. }
  10001. }
  10002. //check Transaction active
  10003. if(meet == FALSE)
  10004. {
  10005. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10006. goto end;
  10007. }
  10008. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10009. {
  10010. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10011. goto end;
  10012. }
  10013. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10014. fptr1 = fopen(filename, "r");
  10015. if (!fptr1)
  10016. {
  10017. //file not exist
  10018. DEBUG_INFO("Unable to open the input file!!\n");
  10019. fptr1 = fopen(filename, "w+");
  10020. }
  10021. else
  10022. {
  10023. //Check Charging Profile Count
  10024. while(fscanf(fptr1, "%s", word) != EOF)
  10025. {
  10026. //DEBUG_INFO("word=%s\n",word);
  10027. if(strstr(word, "chargingProfileId")!= NULL)
  10028. {
  10029. //DEBUG_INFO("test chargingProfileId \n");
  10030. n_chargingProfile = n_chargingProfile + 1;
  10031. //DEBUG_INFO("chargingProfileId Found\n");
  10032. }
  10033. }
  10034. }
  10035. fclose(fptr1);
  10036. }
  10037. // Check ChargeProfileMaxStackLevel
  10038. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10039. {
  10040. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10041. goto end;
  10042. }
  10043. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10044. {
  10045. int i = 0;
  10046. char fnametemp[200]={0};
  10047. n_chargingProfile = 0;
  10048. //Check ChargePointMaxProfile.json exit
  10049. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10050. {
  10051. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10052. //Check Charging Profile Count
  10053. while(fscanf(fptr1, "%s", word) != EOF)
  10054. {
  10055. //DEBUG_INFO("word=%s\n",word);
  10056. if(strstr(word, "chargingProfileId")!= NULL)
  10057. {
  10058. //DEBUG_INFO("test chargingProfileId \n");
  10059. n_chargingProfile = n_chargingProfile + 1;
  10060. i = i + 1;
  10061. //DEBUG_INFO("chargingProfileId Found\n");
  10062. }
  10063. memset(word, 0, ARRAY_SIZE(word));
  10064. }
  10065. fclose(fptr1);
  10066. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10067. }
  10068. //Check TxDefaultProfile_0.json exit
  10069. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10070. {
  10071. i = 0;
  10072. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10073. //Check Charging Profile Count
  10074. while(fscanf(fptr1, "%s", word) != EOF)
  10075. {
  10076. //DEBUG_INFO("word=%s\n",word);
  10077. if(strstr(word, "chargingProfileId")!= NULL)
  10078. {
  10079. //DEBUG_INFO("test chargingProfileId \n");
  10080. n_chargingProfile = n_chargingProfile + 1;
  10081. i = i + 1;
  10082. //DEBUG_INFO("chargingProfileId Found\n");
  10083. }
  10084. memset(word, 0, ARRAY_SIZE(word));
  10085. }
  10086. fclose(fptr1);
  10087. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10088. }
  10089. //Check TxDefaultProfile_%d.json
  10090. for(int j=1; j <= gunTotalNumber; j++)
  10091. {
  10092. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10093. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10094. if((access(fnametemp,F_OK))!=-1)
  10095. {
  10096. i = 0;
  10097. fptr1 = fopen(fnametemp, "r");
  10098. //Check Charging Profile Count
  10099. while(fscanf(fptr1, "%s", word) != EOF)
  10100. {
  10101. //DEBUG_INFO("word=%s\n",word);
  10102. if(strstr(word, "chargingProfileId")!= NULL)
  10103. {
  10104. //DEBUG_INFO("test chargingProfileId \n");
  10105. n_chargingProfile = n_chargingProfile + 1;
  10106. i = i + 1;
  10107. //DEBUG_INFO("chargingProfileId Found\n");
  10108. }
  10109. memset(word, 0, ARRAY_SIZE(word));
  10110. }
  10111. fclose(fptr1);
  10112. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10113. }
  10114. }
  10115. //Check TxProfile_%d.json
  10116. for(int j=1; j <= gunTotalNumber; j++)
  10117. {
  10118. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10119. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10120. if((access(fnametemp,F_OK))!=-1)
  10121. {
  10122. i = 0;
  10123. fptr1 = fopen(fnametemp, "r");
  10124. //Check Charging Profile Count
  10125. while(fscanf(fptr1, "%s", word) != EOF)
  10126. {
  10127. //DEBUG_INFO("word=%s\n",word);
  10128. if(strstr(word, "chargingProfileId")!= NULL)
  10129. {
  10130. //DEBUG_INFO("test chargingProfileId \n");
  10131. n_chargingProfile = n_chargingProfile + 1;
  10132. i = i + 1;
  10133. //DEBUG_INFO("chargingProfileId Found\n");
  10134. }
  10135. memset(word, 0, ARRAY_SIZE(word));
  10136. }
  10137. fclose(fptr1);
  10138. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10139. }
  10140. }
  10141. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10142. {
  10143. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10144. goto end;
  10145. }
  10146. }
  10147. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10148. //**********************************Write to File********************************************************/
  10149. FILE *infile;
  10150. FILE *outfile;
  10151. infile = fopen (filename, "r");
  10152. outfile = fopen (tempfile, "w");
  10153. int d =0;
  10154. d = fgetc(infile);
  10155. rewind(infile);
  10156. if(d == EOF)
  10157. {
  10158. // Profile is empty
  10159. fprintf(outfile,"%s\n",payload);
  10160. fclose(infile);
  10161. fclose(outfile);
  10162. sprintf(rmFileCmd,"rm -f %s",filename);
  10163. system(rmFileCmd);
  10164. rename(tempfile, filename);
  10165. }
  10166. else
  10167. {
  10168. // Profile is not empty
  10169. char buf[2048]={0};
  10170. int ChargingProfileAdded = FALSE;
  10171. while (fgets(buf, sizeof(buf), infile) != NULL)
  10172. {
  10173. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10174. json_object *tmpChargingProfile;
  10175. tmpChargingProfile = json_tokener_parse(buf);
  10176. if(!is_error(SetChargingProfile))
  10177. {
  10178. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10179. {
  10180. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10181. }
  10182. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10183. {
  10184. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10185. {
  10186. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10187. }
  10188. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10189. {
  10190. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10191. }
  10192. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10193. {
  10194. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10195. }
  10196. }
  10197. }
  10198. json_object_put(tmpChargingProfile);
  10199. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10200. {
  10201. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10202. {
  10203. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10204. if(ChargingProfileAdded == FALSE)
  10205. {
  10206. fprintf(outfile,"%s\n",payload);
  10207. ChargingProfileAdded = TRUE;
  10208. }
  10209. }
  10210. else
  10211. {
  10212. if(tempstackLevelInt < stackLevelInt)
  10213. {
  10214. if(ChargingProfileAdded == FALSE)
  10215. {
  10216. fprintf(outfile,"%s\n",buf);
  10217. fprintf(outfile,"%s\n",payload);
  10218. ChargingProfileAdded = TRUE;
  10219. }
  10220. else
  10221. {
  10222. fprintf(outfile,"%s\n",buf);
  10223. }
  10224. }
  10225. else
  10226. {
  10227. if(ChargingProfileAdded == FALSE)
  10228. {
  10229. fprintf(outfile,"%s\n",buf);
  10230. fprintf(outfile,"%s\n",payload);
  10231. ChargingProfileAdded = TRUE;
  10232. }
  10233. else
  10234. {
  10235. fprintf(outfile,"%s\n",buf);
  10236. }
  10237. }
  10238. }
  10239. }
  10240. else
  10241. {
  10242. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10243. {
  10244. if(ChargingProfileAdded == FALSE)
  10245. {
  10246. fprintf(outfile,"%s\n",buf);
  10247. fprintf(outfile,"%s\n",payload);
  10248. ChargingProfileAdded = TRUE;
  10249. }
  10250. else
  10251. {
  10252. fprintf(outfile,"%s\n",buf);
  10253. }
  10254. }
  10255. else if(tempstackLevelInt < stackLevelInt)
  10256. {
  10257. if(ChargingProfileAdded == FALSE)
  10258. {
  10259. fprintf(outfile,"%s\n",buf);
  10260. fprintf(outfile,"%s\n",payload);
  10261. ChargingProfileAdded = TRUE;
  10262. }
  10263. else
  10264. {
  10265. fprintf(outfile,"%s\n",buf);
  10266. }
  10267. }
  10268. else
  10269. {
  10270. if(ChargingProfileAdded == FALSE)
  10271. {
  10272. fprintf(outfile,"%s\n",buf);
  10273. fprintf(outfile,"%s\n",payload);
  10274. ChargingProfileAdded = TRUE;
  10275. }
  10276. else
  10277. {
  10278. fprintf(outfile,"%s\n",buf);
  10279. }
  10280. }
  10281. }
  10282. } // end of while loop
  10283. fclose(infile);
  10284. fclose(outfile);
  10285. sprintf(rmFileCmd,"rm -f %s",filename);
  10286. system(rmFileCmd);
  10287. rename(tempfile, filename);
  10288. }
  10289. sleep(1);
  10290. result = TRUE;
  10291. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10292. end:
  10293. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10294. {
  10295. if(connectorIdInt == 0)
  10296. {
  10297. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10298. {
  10299. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10300. }
  10301. }
  10302. else
  10303. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10304. }
  10305. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10306. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10307. return result;
  10308. }
  10309. int handleTriggerMessageRequest(char *uuid, char *payload)
  10310. {
  10311. mtrace();
  10312. int result = FAIL;
  10313. int connectorIdIsNULL = FALSE;
  10314. int connectorIdInt =0;
  10315. char sstr[40]={0},sstrtemp[100]={ 0 };
  10316. char requestedMessagestr[40]={0};
  10317. char comfirmstr[20]={0};
  10318. int c = 0;
  10319. char *loc;
  10320. DEBUG_INFO("handleTriggerMessageRequest\n");
  10321. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10322. strcpy(sstrtemp, stringtrimspace(payload));
  10323. c = 0;
  10324. loc = strstr(sstrtemp, "requestedMessage");
  10325. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10326. {
  10327. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10328. c++;
  10329. }
  10330. sstr[c] = '\0';
  10331. strcpy(requestedMessagestr, sstr);
  10332. c = 0;
  10333. loc = strstr(sstrtemp, "connectorId");
  10334. if(loc == NULL)
  10335. {
  10336. connectorIdIsNULL = TRUE;
  10337. }
  10338. else
  10339. {
  10340. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10341. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10342. {
  10343. sstr[c] = loc[strlen("connectorId")+2+c];
  10344. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10345. c++;
  10346. }
  10347. sstr[c] = '\0';
  10348. connectorIdInt = atoi(sstr);
  10349. }
  10350. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10351. {
  10352. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10353. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10354. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10355. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10356. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10357. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10358. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10359. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10360. {
  10361. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10362. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10363. return TRUE;
  10364. }
  10365. else
  10366. {
  10367. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10368. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10369. }
  10370. }
  10371. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10372. {
  10373. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10374. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10375. return TRUE;
  10376. }
  10377. //==========================
  10378. // Trigger message
  10379. //==========================
  10380. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10381. {
  10382. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10383. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10384. {
  10385. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10386. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10387. }
  10388. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10389. }
  10390. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10391. {
  10392. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10393. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10394. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10395. }
  10396. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10397. {
  10398. //sendBootNotificationRequest();
  10399. server_sign = FALSE;
  10400. }
  10401. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10402. {
  10403. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10404. }
  10405. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10406. {
  10407. if(connectorIdIsNULL == FALSE)
  10408. {
  10409. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10410. {
  10411. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10412. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10413. }
  10414. }
  10415. else
  10416. {
  10417. for(int idx=0;idx< gunTotalNumber;idx++)
  10418. {
  10419. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10420. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10421. }
  10422. }
  10423. }
  10424. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10425. {
  10426. if(connectorIdIsNULL == FALSE)
  10427. {
  10428. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  10429. {
  10430. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10431. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  10432. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10433. }
  10434. }
  10435. else
  10436. {
  10437. for(int idx=0;idx< gunTotalNumber;idx++)
  10438. {
  10439. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10440. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10441. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10442. }
  10443. }
  10444. }
  10445. return result;
  10446. }
  10447. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10448. {
  10449. mtrace();
  10450. int result = FAIL;
  10451. int connectorIdInt =0;
  10452. char comfirmstr[20]={0};
  10453. int tempIndex = 0;
  10454. json_object *UnlockConnector;
  10455. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10456. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10457. UnlockConnector = json_tokener_parse(payload);
  10458. if(!is_error(UnlockConnector))
  10459. {
  10460. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10461. {
  10462. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10463. }
  10464. }
  10465. json_object_put(UnlockConnector);
  10466. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10467. if(gunTotalNumber == 0)
  10468. {
  10469. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10470. goto end;
  10471. }
  10472. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10473. {
  10474. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10475. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10476. goto end;
  10477. }
  10478. else
  10479. {
  10480. //check Transaction active
  10481. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10482. {
  10483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10484. {
  10485. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10486. }
  10487. else
  10488. {
  10489. tempIndex = connectorIdInt -1;
  10490. }
  10491. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10492. {
  10493. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10494. {
  10495. //stop Transaction
  10496. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10497. }
  10498. }
  10499. }
  10500. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10501. {
  10502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10503. {
  10504. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10505. }
  10506. else
  10507. {
  10508. tempIndex = connectorIdInt -1;
  10509. }
  10510. for (int index = 0; index < CCS_QUANTITY; index++)
  10511. {
  10512. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10513. {
  10514. //stop Transaction
  10515. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10516. }
  10517. }
  10518. }
  10519. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10520. {
  10521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10522. {
  10523. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10524. }
  10525. else
  10526. {
  10527. tempIndex = connectorIdInt -1;
  10528. }
  10529. for (int index = 0; index < GB_QUANTITY; index++)
  10530. {
  10531. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10532. {
  10533. //stop Transaction
  10534. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10535. }
  10536. }
  10537. }
  10538. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10539. {
  10540. tempIndex = connectorIdInt -1;
  10541. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10542. {
  10543. 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)))
  10544. {
  10545. //stop Transaction
  10546. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10547. }
  10548. }
  10549. }
  10550. else
  10551. {
  10552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10553. {
  10554. tempIndex = 2;
  10555. }
  10556. else
  10557. {
  10558. tempIndex = connectorIdInt-1;
  10559. }
  10560. for (int index = 0; index < AC_QUANTITY; index++)
  10561. {
  10562. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10563. {
  10564. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10565. }
  10566. }
  10567. }
  10568. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10569. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10570. result = TRUE;
  10571. return result;
  10572. }
  10573. end:
  10574. //json_object_put(obj); --- remove temporally
  10575. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10576. return result;
  10577. }
  10578. static char UpdateFirmwarepayloadData[300]={0};
  10579. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10580. {
  10581. mtrace();
  10582. int result = FAIL;
  10583. pthread_t t;
  10584. sendUpdateFirmwareConfirmation(uuid);
  10585. memset(UpdateFirmwarepayloadData, 0, 300);
  10586. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10587. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10588. ////pthread_join(t, NULL); //
  10589. //pthread_detach(t);
  10590. //sendUpdateFirmwareConfirmation(uuid);
  10591. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10592. return result;
  10593. }
  10594. void *UpdateFirmwareProcess(void *data)
  10595. {
  10596. pthread_detach(pthread_self());
  10597. mtrace();
  10598. int retriesInt =0, retryIntervalInt=0;
  10599. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10600. int port=0;
  10601. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10602. int isSuccess = 0;
  10603. char ftpbuf[1024];
  10604. char temp[1024];
  10605. char * pch;
  10606. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10607. json_object *UpdateFirmware;
  10608. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10609. if(!is_error(UpdateFirmware))
  10610. {
  10611. // Required data
  10612. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10613. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10614. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10615. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10616. // Optional data
  10617. if(json_object_object_get(UpdateFirmware, "retries"))
  10618. {
  10619. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10620. }
  10621. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10622. {
  10623. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10624. }
  10625. }
  10626. json_object_put(UpdateFirmware);
  10627. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10628. memset(path, 0, ARRAY_SIZE(path));
  10629. // Wait retrieveData
  10630. if(strlen(retrieveDatestr) > 10)
  10631. {
  10632. do
  10633. {
  10634. sleep(1);
  10635. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10636. }
  10637. // Ready to download
  10638. system("rm -f /mnt/*");
  10639. if(strncmp(locationstr,"http", 4) == 0)
  10640. {
  10641. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10642. sprintf(ftppath,"/%s", path);
  10643. DEBUG_INFO("locationstr: %s\n", locationstr);
  10644. DEBUG_INFO("protocol: %s\n",protocol);
  10645. DEBUG_INFO("host: %s\n",host);
  10646. DEBUG_INFO("path: %s\n",path);
  10647. DEBUG_INFO("ftppath: %s\n",ftppath);
  10648. int ftppathlen=strlen(ftppath);
  10649. int i=1;
  10650. char filenametemp[50];
  10651. while(i < ftppathlen)
  10652. {
  10653. int len=ftppathlen-i;
  10654. if(ftppath[len]== 47) // '/' ascll code: 47
  10655. {
  10656. DEBUG_INFO("compare '/' all right\n");
  10657. break;
  10658. }
  10659. i=i+1;
  10660. }
  10661. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10662. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10663. filenametemp[i+1] = 0;
  10664. do
  10665. {
  10666. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10667. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10668. sleep(1);
  10669. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10670. if(!isSuccess)
  10671. {
  10672. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10673. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10674. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10675. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10676. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10677. }
  10678. else
  10679. {
  10680. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10681. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10682. }
  10683. retriesInt--;
  10684. }while((isSuccess == 0)&&(retriesInt >= 0));
  10685. }
  10686. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10687. {
  10688. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10689. memset(temp, 0, ARRAY_SIZE(temp));
  10690. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10691. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10692. int ftppathlen=strlen(ftpbuf);
  10693. int i=1;
  10694. char filenametemp[50];
  10695. while(i < ftppathlen)
  10696. {
  10697. int len=ftppathlen-i;
  10698. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10699. {
  10700. DEBUG_INFO(" compare '/' all right\n");
  10701. break;
  10702. }
  10703. i=i+1;
  10704. }
  10705. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10706. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10707. filenametemp[i+1] = 0;
  10708. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10709. pch=strchr(temp,'@');
  10710. if(pch==NULL)
  10711. {
  10712. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10713. protocol, host, &port, path);
  10714. strcpy(user,"anonymous");
  10715. strcpy(password,"");
  10716. }
  10717. else
  10718. {
  10719. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10720. protocol, user, password, host, &port, path);
  10721. }
  10722. sscanf(host,"%[^/]%s",host1, path1);
  10723. sprintf(ftppath,"%s", path1);
  10724. //DEBUG_INFO("protocol =%s\n",protocol);
  10725. //DEBUG_INFO("user =%s\n",user);
  10726. //DEBUG_INFO("password =%s\n",password);
  10727. //DEBUG_INFO("host1 =%s\n",host1);
  10728. //DEBUG_INFO("port =%d\n",port);
  10729. //DEBUG_INFO("path1 =%s\n",path1);
  10730. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10731. //ftpFile(host, user, password, port, ftppath, fname);
  10732. //download firmware pthred
  10733. if(port == 0)
  10734. {
  10735. port = 21;
  10736. }
  10737. do
  10738. {
  10739. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10740. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10741. sleep(1);
  10742. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10743. if(!isSuccess)
  10744. {
  10745. //BulldogUtil.sleepMs(interval*1000);
  10746. DEBUG_INFO("Update firmware request and download file fail.\n");
  10747. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10748. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10749. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10750. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10751. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10752. }
  10753. else
  10754. {
  10755. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10756. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10757. }
  10758. retriesInt--;
  10759. }while((!isSuccess)&&(retriesInt >= 0));
  10760. }
  10761. else
  10762. {
  10763. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10764. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10765. sleep(1);
  10766. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10767. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10768. }
  10769. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10770. pthread_exit(NULL);
  10771. }
  10772. int handleCertificateSignedRequest(char *uuid, char *payload)
  10773. {
  10774. mtrace();
  10775. int result = PASS;
  10776. json_object *CertificateSigned;
  10777. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10778. CertificateSigned = json_tokener_parse(payload);
  10779. if(!is_error(CertificateSigned))
  10780. {
  10781. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10782. }
  10783. json_object_put(CertificateSigned);
  10784. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10785. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10786. fclose(fp);
  10787. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10788. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10789. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10790. sendCertificateSignedConfirmation(uuid);
  10791. return result;
  10792. }
  10793. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10794. {
  10795. mtrace();
  10796. int result = PASS;
  10797. json_object *DeleteCertificate;
  10798. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10799. DeleteCertificate = json_tokener_parse(payload);
  10800. if(!is_error(DeleteCertificate))
  10801. {
  10802. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10803. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10804. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10805. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10806. }
  10807. json_object_put(DeleteCertificate);
  10808. /*
  10809. * TODO: Delete certificateSigned process
  10810. */
  10811. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10812. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10813. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10814. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10815. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10816. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10817. sendDeleteCertificateConfirmation(uuid);
  10818. return result;
  10819. }
  10820. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10821. {
  10822. mtrace();
  10823. int result = PASS;
  10824. json_object *ExtendedTriggerMessage;
  10825. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10826. ExtendedTriggerMessage = json_tokener_parse(payload);
  10827. if(!is_error(ExtendedTriggerMessage))
  10828. {
  10829. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10830. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10831. {
  10832. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10833. }
  10834. else
  10835. {
  10836. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10837. }
  10838. }
  10839. json_object_put(ExtendedTriggerMessage);
  10840. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10841. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10842. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10843. {
  10844. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10845. }
  10846. else
  10847. {
  10848. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10849. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10850. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10851. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10852. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10853. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10854. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10855. {
  10856. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10857. }
  10858. else
  10859. {
  10860. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10861. }
  10862. }
  10863. sendExtendedTriggerMessageConfirmation(uuid);
  10864. //==========================
  10865. // Trigger message
  10866. //==========================
  10867. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10868. {
  10869. //sendBootNotificationRequest();
  10870. server_sign = FALSE;
  10871. }
  10872. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10873. {
  10874. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10875. }
  10876. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10877. {
  10878. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10879. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10880. {
  10881. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10882. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10883. }
  10884. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10885. }
  10886. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10887. {
  10888. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10889. }
  10890. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10891. {
  10892. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10893. {
  10894. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10895. }
  10896. else
  10897. {
  10898. for(int idx=0;idx< gunTotalNumber;idx++)
  10899. {
  10900. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10901. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10902. }
  10903. }
  10904. }
  10905. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10906. {
  10907. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10908. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10909. {
  10910. 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\" &");
  10911. }
  10912. }
  10913. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10914. {
  10915. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10916. {
  10917. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10918. }
  10919. else
  10920. {
  10921. for(int idx=0;idx< gunTotalNumber;idx++)
  10922. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10923. }
  10924. }
  10925. return result;
  10926. }
  10927. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10928. {
  10929. mtrace();
  10930. int result = PASS;
  10931. json_object *GetInstalledCertificateIds;
  10932. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10933. GetInstalledCertificateIds = json_tokener_parse(payload);
  10934. if(!is_error(GetInstalledCertificateIds))
  10935. {
  10936. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10937. }
  10938. json_object_put(GetInstalledCertificateIds);
  10939. /*
  10940. * TODO: Return installed certificate process
  10941. */
  10942. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10943. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10944. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10945. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10946. sendGetInstalledCertificateIdsConfirmation(uuid);
  10947. return result;
  10948. }
  10949. int handleGetLogRequest(char *uuid, char *payload)
  10950. {
  10951. mtrace();
  10952. int result = PASS;
  10953. json_object *GetLog;
  10954. DEBUG_INFO("handleGetLogRequest...\n");
  10955. GetLog = json_tokener_parse(payload);
  10956. if(!is_error(GetLog))
  10957. {
  10958. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10959. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10960. if(json_object_object_get(GetLog, "retries") != NULL)
  10961. {
  10962. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10963. }
  10964. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10965. {
  10966. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10967. }
  10968. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10969. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10970. {
  10971. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10972. }
  10973. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10974. {
  10975. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10976. }
  10977. }
  10978. json_object_put(GetLog);
  10979. /*
  10980. * TODO: Upload log process
  10981. */
  10982. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10983. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10984. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10985. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10986. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10987. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10988. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10989. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10990. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10991. sendGetLogConfirmation(uuid);
  10992. return result;
  10993. }
  10994. int handleInstallCertificateRequest(char *uuid, char *payload)
  10995. {
  10996. mtrace();
  10997. int result = PASS;
  10998. json_object *InstallCertificate;
  10999. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11000. InstallCertificate = json_tokener_parse(payload);
  11001. if(!is_error(InstallCertificate))
  11002. {
  11003. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11004. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11005. /*
  11006. * TODO: Install certificate process
  11007. */
  11008. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11009. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11010. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11011. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11012. sendInstallCertificateConfirmation(uuid);
  11013. }
  11014. json_object_put(InstallCertificate);
  11015. return result;
  11016. }
  11017. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11018. {
  11019. mtrace();
  11020. int result = PASS;
  11021. json_object *SignedUpdateFirmware;
  11022. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11023. SignedUpdateFirmware = json_tokener_parse(payload);
  11024. if(!is_error(SignedUpdateFirmware))
  11025. {
  11026. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11027. {
  11028. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11029. }
  11030. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11031. {
  11032. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11033. }
  11034. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11035. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11036. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11037. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11038. {
  11039. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11040. }
  11041. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11042. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11043. }
  11044. json_object_put(SignedUpdateFirmware);
  11045. /*
  11046. * TODO: Upgrade firmware process
  11047. */
  11048. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11049. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11050. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11051. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11052. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11053. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11054. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11055. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11056. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11057. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11058. sendInstallCertificateConfirmation(uuid);
  11059. return result;
  11060. }
  11061. int handleUnknownRequest(char *uuid, char *payload)
  11062. {
  11063. mtrace();
  11064. int result = PASS;
  11065. DEBUG_INFO("handleUnknownRequest...\n");
  11066. sendUnknownConfirmation(uuid);
  11067. result = PASS;
  11068. return result;
  11069. }
  11070. //==========================================
  11071. // Handle server response routine
  11072. //==========================================
  11073. void handleAuthorizeResponse(char *payload, int gun_index)
  11074. {
  11075. mtrace();
  11076. char expiryDatestr[30]={0};
  11077. char parentIdTagstr[20]={0};
  11078. char statusstr[20]={0};
  11079. int expiryDateISNULL=FALSE;
  11080. int parentIdTagISNULL=FALSE;
  11081. DEBUG_INFO("handleAuthorizeResponse...\n");
  11082. json_object *Authorize;
  11083. Authorize = json_tokener_parse(payload);
  11084. if(!is_error(Authorize))
  11085. {
  11086. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11087. {
  11088. // Required data
  11089. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11090. // Optional data
  11091. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11092. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11093. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11094. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11095. }
  11096. }
  11097. json_object_put(Authorize);
  11098. if(expiryDateISNULL == FALSE)
  11099. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11100. if(parentIdTagISNULL == FALSE)
  11101. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11102. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11103. //Update idTag information to authorization cache if supproted
  11104. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11105. {
  11106. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11107. }
  11108. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11109. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11110. authorizeRetryTimes = 0;
  11111. }
  11112. void handleBootNotificationResponse(char *payload, int gun_index)
  11113. {
  11114. mtrace();
  11115. char statusStr[12]={0};
  11116. char currentTimeStr[30]={0};
  11117. int intervalInt = 0;
  11118. DEBUG_INFO("handleBootNotificationResponse...\n");
  11119. json_object *BootNotification;
  11120. BootNotification = json_tokener_parse(payload);
  11121. if(!is_error(BootNotification))
  11122. {
  11123. // Required data
  11124. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11125. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11126. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11127. }
  11128. json_object_put(BootNotification);
  11129. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11130. BootNotificationInterval = intervalInt;
  11131. HeartBeatWaitTime = intervalInt;
  11132. //write back to ShmOCPP16Data->BootNotification
  11133. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11134. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11135. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11136. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11137. {
  11138. server_sign = TRUE;
  11139. server_pending =FALSE;
  11140. }
  11141. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11142. {
  11143. server_pending = TRUE;
  11144. }
  11145. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11146. srand(time(NULL));
  11147. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11148. SetOcppConnStatus(TRUE);
  11149. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11150. }
  11151. void handleDataTransferResponse(char *payload, int gun_index)
  11152. {
  11153. char sstr[160]={0};//sstr[200]={ 0 };
  11154. int c = 0;
  11155. char *loc;
  11156. DEBUG_INFO("handleDataTransferResponse ...\n");
  11157. loc = strstr(payload, "status");
  11158. c = 0;
  11159. while (loc[3+strlen("status")+c] != '\"')
  11160. {
  11161. sstr[c] = loc[3+strlen("status")+c];
  11162. c++;
  11163. }
  11164. sstr[c] = '\0';
  11165. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11166. }
  11167. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11168. {
  11169. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11170. //struct json_object *obj;
  11171. // obj = json_tokener_parse(payload);
  11172. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11173. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11174. //No fields are defined.
  11175. }
  11176. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11177. {
  11178. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11179. //struct json_object *obj;
  11180. // obj = json_tokener_parse(payload);
  11181. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11182. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11183. //No fields are defined.
  11184. }
  11185. void handleHeartbeatResponse(char *payload, int gun_index)
  11186. {
  11187. mtrace();
  11188. DEBUG_INFO("handleHeartbeatResponse...\n");
  11189. json_object *Heartbeat;
  11190. Heartbeat = json_tokener_parse(payload);
  11191. if(!is_error(Heartbeat))
  11192. {
  11193. // Required data
  11194. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11195. }
  11196. json_object_put(Heartbeat);
  11197. if(FirstHeartBeat == 0)
  11198. {
  11199. FirstHeartBeat = 1;
  11200. DEBUG_INFO("FirstHeartBeat \n");
  11201. }
  11202. HeartBeatWithNOResponse = 0;
  11203. clientTime.Heartbeat=time((time_t*)NULL);
  11204. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11205. }
  11206. void handleMeterValuesResponse(char *payload, int gun_index)
  11207. {
  11208. mtrace();
  11209. DEBUG_INFO("handleMeterValuesResponse...\n");
  11210. }
  11211. void handleStartTransactionResponse(char *payload, int gun_index)
  11212. {
  11213. mtrace();
  11214. //int transactionIdInt = 0;
  11215. FILE *outfile;
  11216. char data[100]={0};
  11217. DEBUG_INFO("handleStartTransactionResponse...\n");
  11218. json_object *StartTransaction;
  11219. StartTransaction = json_tokener_parse(payload);
  11220. if(!is_error(StartTransaction))
  11221. {
  11222. // Required data
  11223. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11224. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11225. // Optional data
  11226. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11227. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11228. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11229. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11230. }
  11231. json_object_put(StartTransaction);
  11232. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11233. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11234. //-----------Start : write to the Queue TransactionId file -----------------//
  11235. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11236. {}
  11237. else
  11238. {
  11239. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11240. if(log == NULL)
  11241. {
  11242. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11243. return ;
  11244. }
  11245. else
  11246. {
  11247. fclose(log);
  11248. }
  11249. }
  11250. // open file for writing
  11251. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11252. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11253. {
  11254. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11255. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11256. fputs(data, outfile);
  11257. fclose (outfile);
  11258. }
  11259. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11260. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11261. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11262. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11263. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11264. }
  11265. void handleStatusNotificationResponse(char *payload, int gun_index)
  11266. {
  11267. mtrace();
  11268. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11269. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11270. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11271. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11272. }
  11273. void handleStopTransactionnResponse(char *payload, int gun_index)
  11274. {
  11275. mtrace();
  11276. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11277. json_object *StopTransaction;
  11278. StopTransaction = json_tokener_parse(payload);
  11279. if(!is_error(StopTransaction))
  11280. {
  11281. // Optional data
  11282. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11283. {
  11284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11285. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11287. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11288. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11289. }
  11290. }
  11291. json_object_put(StopTransaction);
  11292. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11293. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11294. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11295. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11296. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11297. }
  11298. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11299. {
  11300. mtrace();
  11301. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11302. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11303. }
  11304. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11305. {
  11306. mtrace();
  11307. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11308. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11309. }
  11310. void handleSignCertificateResponse(char *payload, int gun_index)
  11311. {
  11312. mtrace();
  11313. DEBUG_INFO("handleSignCertificateResponse...\n");
  11314. json_object *SignCertificate;
  11315. SignCertificate = json_tokener_parse(payload);
  11316. if(!is_error(SignCertificate))
  11317. {
  11318. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11319. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11320. }
  11321. json_object_put(SignCertificate);
  11322. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11323. }
  11324. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11325. {
  11326. mtrace();
  11327. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11328. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11329. }
  11330. //==========================================
  11331. // Handle Error routine
  11332. //==========================================
  11333. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11334. {
  11335. mtrace();
  11336. #ifdef SystemLogMessage
  11337. DEBUG_INFO("errorCode: %s\n", errorCode);
  11338. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11339. DEBUG_INFO("errorDetails: %s\n", payload);
  11340. #endif
  11341. }
  11342. //===============================================
  11343. // Common routine
  11344. //===============================================
  11345. int initialConfigurationTable(void)
  11346. {
  11347. //clock_t start_t, end_t, total_t;
  11348. FILE *fp;
  11349. FILE *outfile;
  11350. char str[512]={0};
  11351. char sstr[256]={0};
  11352. int c = 0;
  11353. char *loc;
  11354. int confVersion = 5;
  11355. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11356. //start_t = clock();
  11357. //printf("Starting of the program, start_t = %ld\n", start_t);
  11358. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11359. // Check configuration file size is correct
  11360. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11361. {
  11362. struct stat st;
  11363. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11364. if(st.st_size < 3100)
  11365. {
  11366. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11367. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11368. }
  11369. }
  11370. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11371. {
  11372. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11373. if(outfile == NULL)
  11374. {
  11375. DEBUG_INFO("Error opening file\n");
  11376. return FALSE;
  11377. }
  11378. /*Core Profile*/
  11379. //AllowOfflineTxForUnknownId
  11380. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11384. //AuthorizationCacheEnabled
  11385. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11389. //AuthorizeRemoteTxRequests
  11390. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11394. //BlinkRepeat
  11395. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11399. //ClockAlignedDataInterval
  11400. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11404. //ConnectionTimeOut
  11405. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11409. //GetConfigurationMaxKeys
  11410. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11414. // HeartbeatInterval
  11415. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11419. // LightIntensity
  11420. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11424. // LocalAuthorizeOffline
  11425. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11429. // LocalPreAuthorize
  11430. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11434. // MaxEnergyOnInvalidId
  11435. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11439. // MeterValuesAlignedData
  11440. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11444. else
  11445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11447. // MeterValuesAlignedDataMaxLength
  11448. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11452. else
  11453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11455. // MeterValuesSampledData
  11456. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11458. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11460. else
  11461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11463. // MeterValuesSampledDataMaxLength
  11464. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11468. else
  11469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11471. // MeterValueSampleInterval
  11472. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11476. // MinimumStatusDuration
  11477. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11480. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11482. // NumberOfConnectors
  11483. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11486. {
  11487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11488. }
  11489. else
  11490. {
  11491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11492. }
  11493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11494. // ResetRetries
  11495. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11499. // ConnectorPhaseRotation
  11500. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11504. // ConnectorPhaseRotationMaxLength
  11505. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11509. // StopTransactionOnEVSideDisconnect
  11510. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11514. // StopTransactionOnInvalidId
  11515. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11519. // StopTxnAlignedData
  11520. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11524. // StopTxnAlignedDataMaxLength
  11525. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11529. // StopTxnSampledData
  11530. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11534. else
  11535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11537. // StopTxnSampledDataMaxLength
  11538. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11541. {
  11542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11543. }
  11544. else
  11545. {
  11546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11547. }
  11548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11549. // SupportedFeatureProfiles
  11550. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11554. // SupportedFeatureProfilesMaxLength
  11555. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11559. // TransactionMessageAttempts
  11560. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11563. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11565. // TransactionMessageRetryInterval
  11566. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11569. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11571. // UnlockConnectorOnEVSideDisconnect
  11572. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11576. // WebSocketPingInterval
  11577. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11581. // QueueOffLineStartTransactionMessage
  11582. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11586. // AuthorizationKey
  11587. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11591. // SecurityProfile
  11592. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11596. // DefaultPrice
  11597. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11601. // CustomDisplayCostAndPrice
  11602. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11606. // CustomIdleFeeAfterStop
  11607. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11611. // TimeOffset
  11612. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  11613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  11614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  11615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  11616. // NextTimeOffsetTransitionDateTime
  11617. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  11618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  11619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  11620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  11621. // TimeOffsetNextTransition
  11622. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  11623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  11624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  11625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  11626. // Configuration Version
  11627. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11631. //* Local Auth List Management Profile*/
  11632. #if 0
  11633. //For OCTT Test Case
  11634. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11637. #endif
  11638. #if 1
  11639. //LocalAuthListEnabled
  11640. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11644. #endif
  11645. //LocalAuthListMaxLength
  11646. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11650. //SendLocalListMaxLength
  11651. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11655. //ReserveConnectorZeroSupported
  11656. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11660. //* Smart Charging Profile */
  11661. //ChargeProfileMaxStackLevel
  11662. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11666. // ChargingScheduleAllowedChargingRateUnit
  11667. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11671. // ChargingScheduleMaxPeriods
  11672. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11676. // ConnectorSwitch3to1PhaseSupported
  11677. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11681. // MaxChargingProfilesInstalled
  11682. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11686. fclose(outfile);
  11687. }
  11688. else
  11689. {
  11690. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11691. char keystr[60]={0};
  11692. char readonlystr[10]={0};
  11693. char valuestr[256]={0};
  11694. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11695. if(fp == NULL) {
  11696. DEBUG_INFO("Error opening file");
  11697. return FALSE;
  11698. }
  11699. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11700. {
  11701. //DEBUG_INFO("Get Configuration \n");
  11702. if(strlen(str) > 0)
  11703. {
  11704. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11705. //*************************key*********************************/
  11706. if(strstr(str, "key") != NULL)
  11707. {
  11708. loc = strstr(str, "key");
  11709. c = 0;
  11710. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11711. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11712. {
  11713. sstr[c] = loc[strlen("key")+3+c];
  11714. c++;
  11715. }
  11716. sstr[c] = '\0';
  11717. strcpy(keystr,sstr);
  11718. }
  11719. //*************************readonly*********************************/
  11720. if(strstr(str, "readonly") != NULL)
  11721. {
  11722. loc = strstr(str, "readonly");
  11723. c = 0;
  11724. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11725. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11726. {
  11727. sstr[c] = loc[strlen("readonly")+2+c];
  11728. c++;
  11729. }
  11730. sstr[c] = '\0';
  11731. strcpy(readonlystr,sstr);
  11732. }
  11733. //*************************value*********************************/
  11734. if(strstr(str, "value") != NULL)
  11735. {
  11736. loc = strstr(str, "value");
  11737. c = 0;
  11738. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11739. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11740. {
  11741. sstr[c] = loc[strlen("value")+3+c];
  11742. c++;
  11743. }
  11744. sstr[c] = '\0';
  11745. strcpy(valuestr,sstr);
  11746. }
  11747. // DEBUG_INFO("keystr=%s\n",keystr);
  11748. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11749. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11750. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11751. {
  11752. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11753. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11755. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11756. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11757. }
  11758. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11759. {
  11760. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11761. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11763. }
  11764. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11765. {
  11766. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11768. }
  11769. if(strcmp(keystr, "BlinkRepeat") == 0)
  11770. {
  11771. //Charger.BlinkRepeat = Integer.parseInt(value);
  11772. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11774. }
  11775. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11776. {
  11777. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11779. }
  11780. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11781. {
  11782. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11784. }
  11785. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11786. {
  11787. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11789. }
  11790. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11791. {
  11792. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11794. HeartBeatWaitTime = atoi(valuestr);
  11795. }
  11796. if(strcmp(keystr, "LightIntensity") == 0)
  11797. {
  11798. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11800. }
  11801. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11802. {
  11803. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11805. }
  11806. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11807. {
  11808. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11810. }
  11811. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11812. {
  11813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11815. }
  11816. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11817. {
  11818. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11820. }
  11821. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11822. {
  11823. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11825. }
  11826. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11827. {
  11828. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11830. }
  11831. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11832. {
  11833. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11835. }
  11836. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11837. {
  11838. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11840. }
  11841. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11842. {
  11843. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11845. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11846. }
  11847. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11848. {
  11849. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11851. }
  11852. if(strcmp(keystr, "ResetRetries") == 0)
  11853. {
  11854. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11856. }
  11857. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11858. {
  11859. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11861. }
  11862. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11863. {
  11864. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11866. }
  11867. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11868. {
  11869. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11871. }
  11872. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11873. {
  11874. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11876. }
  11877. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11878. {
  11879. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11881. }
  11882. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11883. {
  11884. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11886. }
  11887. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11888. {
  11889. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11891. }
  11892. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11893. {
  11894. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11896. }
  11897. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11898. {
  11899. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11901. }
  11902. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11903. {
  11904. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11906. }
  11907. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11908. {
  11909. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11911. TransactionMessageAttemptsValue = atoi(valuestr);
  11912. }
  11913. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11914. {
  11915. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11917. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11918. }
  11919. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11920. {
  11921. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11923. }
  11924. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11925. {
  11926. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11928. }
  11929. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11930. {
  11931. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11933. }
  11934. if(strcmp(keystr, "AuthorizationKey") == 0)
  11935. {
  11936. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11937. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11939. }
  11940. if(strcmp(keystr, "SecurityProfile") == 0)
  11941. {
  11942. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11944. }
  11945. if(strcmp(keystr, "DefaultPrice") == 0)
  11946. {
  11947. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11949. }
  11950. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11951. {
  11952. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11954. }
  11955. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11956. {
  11957. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11959. }
  11960. if(strcmp(keystr, "TimeOffset") == 0)
  11961. {
  11962. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  11964. }
  11965. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  11966. {
  11967. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  11969. }
  11970. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  11971. {
  11972. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  11974. }
  11975. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11976. {
  11977. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11979. }
  11980. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11981. {
  11982. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11984. }
  11985. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11986. {
  11987. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11989. }
  11990. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11991. {
  11992. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11994. }
  11995. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11996. {
  11997. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11999. }
  12000. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12001. {
  12002. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12004. }
  12005. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12006. {
  12007. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12009. }
  12010. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12011. {
  12012. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12014. }
  12015. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12016. {
  12017. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12019. }
  12020. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12021. {
  12022. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12024. }
  12025. }
  12026. }
  12027. fclose(fp);
  12028. }
  12029. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12030. {
  12031. return PASS;
  12032. }
  12033. else
  12034. {
  12035. return FAIL;
  12036. }
  12037. }
  12038. void StoreConfigurationTable(void)
  12039. {
  12040. FILE *outfile;
  12041. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12042. if(outfile == NULL)
  12043. {
  12044. DEBUG_INFO("Error opening file");
  12045. return ;
  12046. }
  12047. /*Core Profile*/
  12048. //AllowOfflineTxForUnknownId
  12049. /*
  12050. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12051. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12054. */
  12055. //DEBUG_INFO("data=%s\n",data);
  12056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12057. //AuthorizationCacheEnabled
  12058. /*
  12059. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12062. */
  12063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12064. //AuthorizeRemoteTxRequests
  12065. /*
  12066. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12069. */
  12070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12071. //BlinkRepeat
  12072. /*
  12073. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12076. */
  12077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12078. //ClockAlignedDataInterval
  12079. /*
  12080. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12083. */
  12084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12085. //ConnectionTimeOut
  12086. /*
  12087. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12090. */
  12091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12092. //GetConfigurationMaxKeys
  12093. /*
  12094. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12097. */
  12098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12099. // HeartbeatInterval
  12100. /*
  12101. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12104. */
  12105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12106. // LightIntensity
  12107. /*
  12108. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12111. */
  12112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12113. // LocalAuthorizeOffline
  12114. /*
  12115. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12118. */
  12119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12120. // LocalPreAuthorize
  12121. /*
  12122. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12125. */
  12126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12127. // MaxEnergyOnInvalidId
  12128. /*
  12129. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12132. */
  12133. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12135. // MeterValuesAlignedData
  12136. /*
  12137. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12140. */
  12141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12142. // MeterValuesAlignedDataMaxLength
  12143. /*
  12144. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12147. */
  12148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12149. // MeterValuesSampledData
  12150. /*
  12151. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12154. */
  12155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12156. // MeterValuesSampledDataMaxLength
  12157. /*
  12158. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12161. */
  12162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12163. // MeterValueSampleInterval
  12164. /*
  12165. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12168. */
  12169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12170. // MinimumStatusDuration
  12171. /*
  12172. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12175. */
  12176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12177. // NumberOfConnectors
  12178. /*
  12179. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12182. {
  12183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12184. }
  12185. else
  12186. {
  12187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12188. }
  12189. */
  12190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12191. // ResetRetries
  12192. /*
  12193. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12196. */
  12197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12198. // ConnectorPhaseRotation
  12199. /*
  12200. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12203. */
  12204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12205. // ConnectorPhaseRotationMaxLength
  12206. /*
  12207. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12210. */
  12211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12212. // StopTransactionOnEVSideDisconnect
  12213. /*
  12214. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12217. */
  12218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12219. // StopTransactionOnInvalidId
  12220. /*
  12221. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12224. */
  12225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12226. // StopTxnAlignedData
  12227. /*
  12228. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12231. */
  12232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12233. // StopTxnAlignedDataMaxLength
  12234. /*
  12235. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12238. */
  12239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12240. // StopTxnSampledData
  12241. /*
  12242. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12245. */
  12246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12247. // StopTxnSampledDataMaxLength
  12248. /*
  12249. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12252. */
  12253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12254. // SupportedFeatureProfiles
  12255. /*
  12256. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12259. */
  12260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12261. // SupportedFeatureProfilesMaxLength
  12262. /*
  12263. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12266. */
  12267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12268. // TransactionMessageAttempts
  12269. /*
  12270. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12273. */
  12274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12275. // TransactionMessageRetryInterval
  12276. /*
  12277. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12280. */
  12281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12282. // UnlockConnectorOnEVSideDisconnect
  12283. /*
  12284. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12287. */
  12288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12289. // WebSocketPingInterval
  12290. /*
  12291. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12294. */
  12295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12296. // QueueOffLineStartTransactionMessage
  12297. /*
  12298. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12301. */
  12302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12303. // AuthorizationKey
  12304. /*
  12305. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12308. */
  12309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12310. // SecurityProfile
  12311. /*
  12312. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12315. */
  12316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12317. // DefaultPrice
  12318. /*
  12319. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12322. */
  12323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12324. // CustomDisplayCostAndPrice
  12325. /*
  12326. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12329. */
  12330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12331. // CustomIdleFeeAfterStop
  12332. /*
  12333. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12336. */
  12337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12338. // TimeOffset
  12339. /*
  12340. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  12343. */
  12344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12345. // NextTimeOffsetTransitionDateTime
  12346. /*
  12347. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  12350. */
  12351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12352. // TimeOffsetNextTransition
  12353. /*
  12354. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  12357. */
  12358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12359. // ConfigurationVersion
  12360. /*
  12361. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12364. */
  12365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12366. //* Local Auth List Management Profile*/
  12367. //LocalAuthListEnabled
  12368. /*
  12369. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12372. */
  12373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12374. //LocalAuthListMaxLength
  12375. /*
  12376. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12379. */
  12380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12381. //SendLocalListMaxLength
  12382. /*
  12383. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12386. */
  12387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12388. //ReserveConnectorZeroSupported
  12389. /*
  12390. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12393. */
  12394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12395. //* Smart Charging Profile */
  12396. //ChargeProfileMaxStackLevel
  12397. /*
  12398. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12401. */
  12402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12403. // ChargingScheduleAllowedChargingRateUnit
  12404. /*
  12405. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12408. */
  12409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12410. // ChargingScheduleMaxPeriods
  12411. /*
  12412. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12415. */
  12416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12417. // ConnectorSwitch3to1PhaseSupported
  12418. /*
  12419. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12422. */
  12423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12424. // MaxChargingProfilesInstalled
  12425. /*
  12426. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12429. */
  12430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12431. fclose(outfile);
  12432. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12433. }
  12434. void getKeyValue(char *keyReq)
  12435. {
  12436. int isEmpty = FALSE;
  12437. int isKnowKey = FALSE;
  12438. DEBUG_INFO("keyReq = %s\n", keyReq);
  12439. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12440. isEmpty = TRUE;
  12441. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12442. {
  12443. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12446. {
  12447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12448. }
  12449. else
  12450. {
  12451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12452. }
  12453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12454. isKnowKey = TRUE;
  12455. }
  12456. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12457. {
  12458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12461. {
  12462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12463. }
  12464. else
  12465. {
  12466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12467. }
  12468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12469. isKnowKey = TRUE;
  12470. }
  12471. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12472. {
  12473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12476. {
  12477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12478. }
  12479. else
  12480. {
  12481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12482. }
  12483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12484. isKnowKey = TRUE;
  12485. }
  12486. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12487. {
  12488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12491. {
  12492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12493. }
  12494. else
  12495. {
  12496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12497. }
  12498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12499. isKnowKey = TRUE;
  12500. }
  12501. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12502. {
  12503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12506. {
  12507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12508. }
  12509. else
  12510. {
  12511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12512. }
  12513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12514. isKnowKey = TRUE;
  12515. }
  12516. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12517. {
  12518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12521. {
  12522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12523. }
  12524. else
  12525. {
  12526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12527. }
  12528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12529. isKnowKey = TRUE;
  12530. }
  12531. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12532. {
  12533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12536. {
  12537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12538. }
  12539. else
  12540. {
  12541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12542. }
  12543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12544. isKnowKey = TRUE;
  12545. }
  12546. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12547. {
  12548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12551. {
  12552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12553. }
  12554. else
  12555. {
  12556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12557. }
  12558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12559. isKnowKey = TRUE;
  12560. }
  12561. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12562. {
  12563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12566. {
  12567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12568. }
  12569. else
  12570. {
  12571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12572. }
  12573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12574. isKnowKey = TRUE;
  12575. }
  12576. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12577. {
  12578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12581. {
  12582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12583. }
  12584. else
  12585. {
  12586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12587. }
  12588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12589. isKnowKey = TRUE;
  12590. }
  12591. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12592. {
  12593. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12596. {
  12597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12598. }
  12599. else
  12600. {
  12601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12602. }
  12603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12604. isKnowKey = TRUE;
  12605. }
  12606. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12607. {
  12608. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12611. {
  12612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12613. }
  12614. else
  12615. {
  12616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12617. }
  12618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12619. isKnowKey = TRUE;
  12620. }
  12621. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12622. {
  12623. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12626. {
  12627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12628. }
  12629. else
  12630. {
  12631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12632. }
  12633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12634. isKnowKey = TRUE;
  12635. }
  12636. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12637. {
  12638. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12641. {
  12642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12643. }
  12644. else
  12645. {
  12646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12647. }
  12648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12649. isKnowKey = TRUE;
  12650. }
  12651. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12652. {
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12656. {
  12657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12658. }
  12659. else
  12660. {
  12661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12662. }
  12663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12664. isKnowKey = TRUE;
  12665. }
  12666. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12667. {
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12671. {
  12672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12673. }
  12674. else
  12675. {
  12676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12677. }
  12678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12679. isKnowKey = TRUE;
  12680. }
  12681. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12682. {
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12686. {
  12687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12688. }
  12689. else
  12690. {
  12691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12692. }
  12693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12694. isKnowKey = TRUE;
  12695. }
  12696. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12697. {
  12698. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12700. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12701. {
  12702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12703. }
  12704. else
  12705. {
  12706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12707. }
  12708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12709. isKnowKey = TRUE;
  12710. }
  12711. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12712. {
  12713. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12716. {
  12717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12718. }
  12719. else
  12720. {
  12721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12722. }
  12723. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12725. isKnowKey = TRUE;
  12726. }
  12727. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12728. {
  12729. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12732. {
  12733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12734. }
  12735. else
  12736. {
  12737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12738. }
  12739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12740. isKnowKey = TRUE;
  12741. }
  12742. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12743. {
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12747. {
  12748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12749. }
  12750. else
  12751. {
  12752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12753. }
  12754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12755. isKnowKey = TRUE;
  12756. }
  12757. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12758. {
  12759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12762. {
  12763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12764. }
  12765. else
  12766. {
  12767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12768. }
  12769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12770. isKnowKey = TRUE;
  12771. }
  12772. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12773. {
  12774. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12777. {
  12778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12779. }
  12780. else
  12781. {
  12782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12783. }
  12784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12785. isKnowKey = TRUE;
  12786. }
  12787. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12788. {
  12789. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12792. {
  12793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12794. }
  12795. else
  12796. {
  12797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12798. }
  12799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12800. isKnowKey = TRUE;
  12801. }
  12802. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12803. {
  12804. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12807. {
  12808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12809. }
  12810. else
  12811. {
  12812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12813. }
  12814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12815. isKnowKey = TRUE;
  12816. }
  12817. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12818. {
  12819. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12822. {
  12823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12824. }
  12825. else
  12826. {
  12827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12828. }
  12829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12830. isKnowKey = TRUE;
  12831. }
  12832. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12833. {
  12834. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12837. {
  12838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12839. }
  12840. else
  12841. {
  12842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12843. }
  12844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12845. isKnowKey = TRUE;
  12846. }
  12847. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12848. {
  12849. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12852. {
  12853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12854. }
  12855. else
  12856. {
  12857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12858. }
  12859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12860. isKnowKey = TRUE;
  12861. }
  12862. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12863. {
  12864. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12867. {
  12868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12869. }
  12870. else
  12871. {
  12872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12873. }
  12874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12875. isKnowKey = TRUE;
  12876. }
  12877. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12878. {
  12879. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12882. {
  12883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12884. }
  12885. else
  12886. {
  12887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12888. }
  12889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12890. isKnowKey = TRUE;
  12891. }
  12892. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12893. {
  12894. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12897. {
  12898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12899. }
  12900. else
  12901. {
  12902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12903. }
  12904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12905. isKnowKey = TRUE;
  12906. }
  12907. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12908. {
  12909. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12912. {
  12913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12914. }
  12915. else
  12916. {
  12917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12918. }
  12919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12920. isKnowKey = TRUE;
  12921. }
  12922. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12923. {
  12924. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12927. {
  12928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12929. }
  12930. else
  12931. {
  12932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12933. }
  12934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12935. isKnowKey = TRUE;
  12936. }
  12937. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12938. {
  12939. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12942. {
  12943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12944. }
  12945. else
  12946. {
  12947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12948. }
  12949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12950. isKnowKey = TRUE;
  12951. }
  12952. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12953. {
  12954. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12957. {
  12958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12959. }
  12960. else
  12961. {
  12962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12963. }
  12964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12965. isKnowKey = TRUE;
  12966. }
  12967. /*
  12968. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12969. {
  12970. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12973. {
  12974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12975. }
  12976. else
  12977. {
  12978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12979. }
  12980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12981. isKnowKey = TRUE;
  12982. }*/
  12983. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12984. {
  12985. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12988. {
  12989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12990. }
  12991. else
  12992. {
  12993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12994. }
  12995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12996. isKnowKey = TRUE;
  12997. }
  12998. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12999. {
  13000. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13003. {
  13004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13005. }
  13006. else
  13007. {
  13008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13009. }
  13010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13011. isKnowKey = TRUE;
  13012. }
  13013. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13014. {
  13015. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13018. {
  13019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13020. }
  13021. else
  13022. {
  13023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13024. }
  13025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13026. isKnowKey = TRUE;
  13027. }
  13028. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13029. {
  13030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13033. {
  13034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13035. }
  13036. else
  13037. {
  13038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13039. }
  13040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13041. isKnowKey = TRUE;
  13042. }
  13043. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13044. {
  13045. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13048. {
  13049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13050. }
  13051. else
  13052. {
  13053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13054. }
  13055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13056. isKnowKey = TRUE;
  13057. }
  13058. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13059. {
  13060. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13063. {
  13064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13065. }
  13066. else
  13067. {
  13068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13069. }
  13070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13071. isKnowKey = TRUE;
  13072. }
  13073. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13074. {
  13075. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13078. {
  13079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13080. }
  13081. else
  13082. {
  13083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13084. }
  13085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13086. isKnowKey = TRUE;
  13087. }
  13088. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13089. {
  13090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13093. {
  13094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13095. }
  13096. else
  13097. {
  13098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13099. }
  13100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13101. isKnowKey = TRUE;
  13102. }
  13103. #if 1
  13104. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13105. {
  13106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13108. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13109. {
  13110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13111. }
  13112. else
  13113. {
  13114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13115. }
  13116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13117. isKnowKey = TRUE;
  13118. }
  13119. #endif
  13120. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13121. {
  13122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13124. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13125. {
  13126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13127. }
  13128. else
  13129. {
  13130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13131. }
  13132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13133. isKnowKey = TRUE;
  13134. }
  13135. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13136. {
  13137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13139. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13140. {
  13141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13142. }
  13143. else
  13144. {
  13145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13146. }
  13147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13148. isKnowKey = TRUE;
  13149. }
  13150. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13151. {
  13152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13154. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13155. {
  13156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13157. }
  13158. else
  13159. {
  13160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13161. }
  13162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13163. isKnowKey = TRUE;
  13164. }
  13165. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13166. {
  13167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13169. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13170. {
  13171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13172. }
  13173. else
  13174. {
  13175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13176. }
  13177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13178. isKnowKey = TRUE;
  13179. }
  13180. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13181. {
  13182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13184. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13185. {
  13186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13187. }
  13188. else
  13189. {
  13190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13191. }
  13192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13193. isKnowKey = TRUE;
  13194. }
  13195. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13196. {
  13197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13199. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13200. {
  13201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13202. }
  13203. else
  13204. {
  13205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13206. }
  13207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13208. isKnowKey = TRUE;
  13209. }
  13210. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13211. {
  13212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13214. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13215. {
  13216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13217. }
  13218. else
  13219. {
  13220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13221. }
  13222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13223. isKnowKey = TRUE;
  13224. }
  13225. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13226. {
  13227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13229. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13230. {
  13231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13232. }
  13233. else
  13234. {
  13235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13236. }
  13237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13238. isKnowKey = TRUE;
  13239. }
  13240. //=========================================================
  13241. if(!isEmpty && !isKnowKey)
  13242. {
  13243. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13244. strcpy(unknownkey[UnknownKeynum], keyReq);
  13245. UnknownKeynum = UnknownKeynum + 1;
  13246. }
  13247. }
  13248. void processUnkownKey(void)
  13249. {
  13250. DEBUG_INFO("processUnkownKey...\n");
  13251. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13252. for(int index=0; index < UnknownKeynum; index++)
  13253. {
  13254. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13255. {
  13256. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13257. }
  13258. }
  13259. }
  13260. int setKeyValue(char *key, char *value)
  13261. {
  13262. int isSuccess = NotSupported;
  13263. int check_ascii=0;
  13264. char str[256]={0};
  13265. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13266. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13267. {
  13268. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13270. {
  13271. strcpy(str, (const char*)value);
  13272. for(int i = 0; str[i]; i++){
  13273. str[i] = tolower(str[i]);
  13274. }
  13275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13276. isSuccess = ConfigurationStatus_Accepted;
  13277. }
  13278. else
  13279. {
  13280. isSuccess = ConfigurationStatus_Rejected;
  13281. }
  13282. }
  13283. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13284. {
  13285. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13287. {
  13288. strcpy(str, (const char*)value);
  13289. for(int i = 0; str[i]; i++){
  13290. str[i] = tolower(str[i]);
  13291. }
  13292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13293. isSuccess = ConfigurationStatus_Accepted;
  13294. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13295. }
  13296. else
  13297. {
  13298. isSuccess = ConfigurationStatus_Rejected;
  13299. }
  13300. }
  13301. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13302. {
  13303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13304. {
  13305. strcpy(str, (const char*)value);
  13306. for(int i = 0; str[i]; i++)
  13307. {
  13308. str[i] = tolower(str[i]);
  13309. }
  13310. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13312. isSuccess = ConfigurationStatus_Accepted;
  13313. }
  13314. else
  13315. {
  13316. isSuccess = ConfigurationStatus_Rejected;
  13317. }
  13318. }
  13319. if(strcmp(key, "BlinkRepeat") == 0)
  13320. {
  13321. //Charger.BlinkRepeat = Integer.parseInt(value);
  13322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13323. {
  13324. check_ascii = value[0];
  13325. if( (check_ascii < 48) || (check_ascii > 57) )
  13326. {
  13327. isSuccess = ConfigurationStatus_Rejected;
  13328. }
  13329. else
  13330. {
  13331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13332. isSuccess = ConfigurationStatus_Accepted;
  13333. }
  13334. }
  13335. else
  13336. {
  13337. isSuccess = ConfigurationStatus_Rejected;
  13338. }
  13339. }
  13340. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13341. {
  13342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13343. {
  13344. check_ascii = value[0];
  13345. if( (check_ascii < 48) || (check_ascii > 57) )
  13346. {
  13347. isSuccess = ConfigurationStatus_Rejected;
  13348. }
  13349. else
  13350. {
  13351. if((atoi(value) == 0) || (atoi(value) >= 10))
  13352. {
  13353. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13355. isSuccess = ConfigurationStatus_Accepted;
  13356. }
  13357. else
  13358. isSuccess = ConfigurationStatus_Rejected;
  13359. }
  13360. }
  13361. else
  13362. {
  13363. isSuccess = ConfigurationStatus_Rejected;
  13364. }
  13365. }
  13366. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13367. {
  13368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13369. {
  13370. check_ascii = value[0];
  13371. if( (check_ascii < 48) || (check_ascii > 57) )
  13372. {
  13373. isSuccess = ConfigurationStatus_Rejected;
  13374. }
  13375. else
  13376. {
  13377. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13379. isSuccess = ConfigurationStatus_Accepted;
  13380. }
  13381. }
  13382. else
  13383. {
  13384. isSuccess = ConfigurationStatus_Rejected;
  13385. }
  13386. }
  13387. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13388. {
  13389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13390. {
  13391. check_ascii = value[0];
  13392. if( (check_ascii < 48) || (check_ascii > 57) )
  13393. {
  13394. isSuccess = ConfigurationStatus_Rejected;
  13395. }
  13396. else
  13397. {
  13398. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13400. isSuccess = ConfigurationStatus_Accepted;
  13401. }
  13402. }
  13403. else
  13404. {
  13405. isSuccess = ConfigurationStatus_Rejected;
  13406. }
  13407. }
  13408. if(strcmp(key, "HeartbeatInterval") == 0)
  13409. {
  13410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13411. {
  13412. check_ascii = value[0];
  13413. if( (check_ascii < 48) || (check_ascii > 57) )
  13414. {
  13415. isSuccess = ConfigurationStatus_Rejected;
  13416. }
  13417. else
  13418. {
  13419. if((atoi(value) == 0) || (atoi(value) >= 10))
  13420. {
  13421. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13423. HeartBeatWaitTime = atoi(value);
  13424. isSuccess = ConfigurationStatus_Accepted;
  13425. }
  13426. else
  13427. {
  13428. isSuccess = ConfigurationStatus_Rejected;
  13429. }
  13430. }
  13431. }
  13432. else
  13433. {
  13434. isSuccess = ConfigurationStatus_Rejected;
  13435. }
  13436. }
  13437. if(strcmp(key, "LightIntensity") == 0)
  13438. {
  13439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13440. {
  13441. check_ascii = value[0];
  13442. if( (check_ascii < 48) || (check_ascii > 57) )
  13443. {
  13444. isSuccess = ConfigurationStatus_Rejected;
  13445. }
  13446. else
  13447. {
  13448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13449. isSuccess = ConfigurationStatus_Accepted;
  13450. }
  13451. }
  13452. else
  13453. {
  13454. isSuccess = ConfigurationStatus_Rejected;
  13455. }
  13456. }
  13457. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13458. {
  13459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13460. {
  13461. strcpy(str, (const char*)value);
  13462. for(int i = 0; str[i]; i++)
  13463. {
  13464. str[i] = tolower(str[i]);
  13465. }
  13466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13467. isSuccess = ConfigurationStatus_Accepted;
  13468. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13469. }
  13470. else
  13471. {
  13472. isSuccess = ConfigurationStatus_Rejected;
  13473. }
  13474. }
  13475. if(strcmp(key, "LocalPreAuthorize") == 0)
  13476. {
  13477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13478. {
  13479. strcpy(str, (const char*)value);
  13480. for(int i = 0; str[i]; i++)
  13481. {
  13482. str[i] = tolower(str[i]);
  13483. }
  13484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13485. isSuccess = ConfigurationStatus_Accepted;
  13486. }
  13487. else
  13488. {
  13489. isSuccess = ConfigurationStatus_Rejected;
  13490. }
  13491. }
  13492. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13493. {
  13494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13495. {
  13496. check_ascii = value[0];
  13497. if( (check_ascii < 48) || (check_ascii > 57) )
  13498. {
  13499. isSuccess = ConfigurationStatus_Rejected;
  13500. }
  13501. else
  13502. {
  13503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13504. isSuccess = ConfigurationStatus_Accepted;
  13505. }
  13506. }
  13507. else
  13508. {
  13509. isSuccess = ConfigurationStatus_Rejected;
  13510. }
  13511. }
  13512. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13513. {
  13514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13515. {
  13516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13517. isSuccess = ConfigurationStatus_Accepted;
  13518. }
  13519. else
  13520. {
  13521. isSuccess = ConfigurationStatus_Rejected;
  13522. }
  13523. }
  13524. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13525. {
  13526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13527. {
  13528. check_ascii = value[0];
  13529. if( (check_ascii < 48) || (check_ascii > 57) )
  13530. {
  13531. isSuccess = ConfigurationStatus_Rejected;
  13532. }
  13533. else
  13534. {
  13535. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13537. isSuccess = ConfigurationStatus_Accepted;
  13538. }
  13539. }
  13540. else
  13541. {
  13542. isSuccess = ConfigurationStatus_Rejected;
  13543. }
  13544. }
  13545. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13546. {
  13547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13548. {
  13549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13550. isSuccess = ConfigurationStatus_Accepted;
  13551. }
  13552. else
  13553. {
  13554. isSuccess = ConfigurationStatus_Rejected;
  13555. }
  13556. }
  13557. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13558. {
  13559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13560. {
  13561. check_ascii = value[0];
  13562. if( (check_ascii < 48) || (check_ascii > 57) )
  13563. {
  13564. isSuccess = ConfigurationStatus_Rejected;
  13565. }
  13566. else
  13567. {
  13568. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13570. isSuccess = ConfigurationStatus_Accepted;
  13571. }
  13572. }
  13573. else
  13574. {
  13575. isSuccess = ConfigurationStatus_Rejected;
  13576. }
  13577. }
  13578. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13579. {
  13580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13581. {
  13582. check_ascii = value[0];
  13583. if( (check_ascii < 48) || (check_ascii > 57) )
  13584. {
  13585. isSuccess = ConfigurationStatus_Rejected;
  13586. }
  13587. else
  13588. {
  13589. if((atoi(value) == 0) || (atoi(value) >= 10))
  13590. {
  13591. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13593. isSuccess = ConfigurationStatus_Accepted;
  13594. }
  13595. else
  13596. {
  13597. isSuccess = ConfigurationStatus_Rejected;
  13598. }
  13599. }
  13600. }
  13601. else
  13602. {
  13603. isSuccess = ConfigurationStatus_Rejected;
  13604. }
  13605. }
  13606. if(strcmp(key, "MinimumStatusDuration") == 0)
  13607. {
  13608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13609. {
  13610. check_ascii = value[0];
  13611. if( (check_ascii < 48) || (check_ascii > 57) )
  13612. {
  13613. isSuccess = ConfigurationStatus_Rejected;
  13614. }
  13615. else
  13616. {
  13617. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13618. {
  13619. isSuccess = ConfigurationStatus_Rejected;
  13620. }
  13621. else
  13622. {
  13623. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13625. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13626. isSuccess = ConfigurationStatus_Accepted;
  13627. }
  13628. }
  13629. }
  13630. else
  13631. {
  13632. isSuccess = ConfigurationStatus_Rejected;
  13633. }
  13634. }
  13635. if(strcmp(key, "NumberOfConnectors") == 0)
  13636. {
  13637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13638. {
  13639. check_ascii = value[0];
  13640. if( (check_ascii < 48) || (check_ascii > 57) )
  13641. {
  13642. isSuccess = ConfigurationStatus_Rejected;
  13643. }
  13644. else
  13645. {
  13646. //Charger.ResetRetries = Integer.parseInt(value);
  13647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13648. isSuccess = ConfigurationStatus_Accepted;
  13649. }
  13650. }
  13651. else
  13652. {
  13653. isSuccess = ConfigurationStatus_Rejected;
  13654. }
  13655. }
  13656. if(strcmp(key, "ResetRetries") == 0)
  13657. {
  13658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13659. {
  13660. check_ascii = value[0];
  13661. if( (check_ascii < 48) || (check_ascii > 57) )
  13662. {
  13663. isSuccess = ConfigurationStatus_Rejected;
  13664. }
  13665. else
  13666. {
  13667. //Charger.ResetRetries = Integer.parseInt(value);
  13668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13669. isSuccess = ConfigurationStatus_Accepted;
  13670. }
  13671. }
  13672. else
  13673. {
  13674. isSuccess = ConfigurationStatus_Rejected;
  13675. }
  13676. }
  13677. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13678. {
  13679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13680. {
  13681. strcpy(str, (const char*)value);
  13682. for(int i = 0; str[i]; i++)
  13683. {
  13684. str[i] = tolower(str[i]);
  13685. }
  13686. if(strcmp(str, "notapplicable")== 0)
  13687. {
  13688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13689. isSuccess = ConfigurationStatus_Accepted;
  13690. }
  13691. else if(strcmp(str, "unknown")== 0)
  13692. {
  13693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13694. isSuccess = ConfigurationStatus_Accepted;
  13695. }
  13696. else if(strcmp(str, "rst")== 0)
  13697. {
  13698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13699. isSuccess = ConfigurationStatus_Accepted;
  13700. }
  13701. else if(strcmp(str, "rts")== 0)
  13702. {
  13703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13704. isSuccess = ConfigurationStatus_Accepted;
  13705. }
  13706. else if(strcmp(str, "srt")== 0)
  13707. {
  13708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13709. isSuccess = ConfigurationStatus_Accepted;
  13710. }
  13711. else if(strcmp(str, "str")== 0)
  13712. {
  13713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13714. isSuccess = ConfigurationStatus_Accepted;
  13715. }
  13716. else if(strcmp(str, "trs")== 0)
  13717. {
  13718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13719. isSuccess = ConfigurationStatus_Accepted;
  13720. }
  13721. else if(strcmp(str, "tsr")== 0)
  13722. {
  13723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13724. isSuccess = ConfigurationStatus_Accepted;
  13725. }
  13726. else
  13727. {
  13728. isSuccess = ConfigurationStatus_Rejected;
  13729. }
  13730. }
  13731. else
  13732. {
  13733. isSuccess = ConfigurationStatus_Rejected;
  13734. }
  13735. }
  13736. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13737. {
  13738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13739. {
  13740. check_ascii = value[0];
  13741. if( (check_ascii < 48) || (check_ascii > 57) )
  13742. {
  13743. isSuccess = ConfigurationStatus_Rejected;
  13744. }
  13745. else
  13746. {
  13747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13748. isSuccess = ConfigurationStatus_Accepted;
  13749. }
  13750. }
  13751. else
  13752. {
  13753. isSuccess = ConfigurationStatus_Rejected;
  13754. }
  13755. }
  13756. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13757. {
  13758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13759. {
  13760. strcpy(str, (const char*)value);
  13761. for(int i = 0; str[i]; i++)
  13762. {
  13763. str[i] = tolower(str[i]);
  13764. }
  13765. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13767. isSuccess = ConfigurationStatus_Accepted;
  13768. }
  13769. else
  13770. {
  13771. isSuccess = ConfigurationStatus_Rejected;
  13772. }
  13773. }
  13774. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13775. {
  13776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13777. {
  13778. strcpy(str, (const char*)value);
  13779. for(int i = 0; str[i]; i++)
  13780. {
  13781. str[i] = tolower(str[i]);
  13782. }
  13783. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13785. isSuccess = ConfigurationStatus_Accepted;
  13786. }
  13787. else
  13788. {
  13789. isSuccess = ConfigurationStatus_Rejected;
  13790. }
  13791. }
  13792. if(strcmp(key, "StopTxnAlignedData") == 0)
  13793. {
  13794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13795. {
  13796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13797. isSuccess = ConfigurationStatus_Accepted;
  13798. }
  13799. else
  13800. {
  13801. isSuccess = ConfigurationStatus_Rejected;
  13802. }
  13803. }
  13804. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13805. {
  13806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13807. {
  13808. check_ascii = value[0];
  13809. if( (check_ascii < 48) || (check_ascii > 57) )
  13810. {
  13811. isSuccess = ConfigurationStatus_Rejected;
  13812. }
  13813. else
  13814. {
  13815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13816. isSuccess = ConfigurationStatus_Accepted;
  13817. }
  13818. }
  13819. else
  13820. {
  13821. isSuccess = ConfigurationStatus_Rejected;
  13822. }
  13823. }
  13824. if(strcmp(key, "StopTxnSampledData") == 0)
  13825. {
  13826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13827. {
  13828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13829. isSuccess = ConfigurationStatus_Accepted;
  13830. }
  13831. else
  13832. {
  13833. isSuccess = ConfigurationStatus_Rejected;
  13834. }
  13835. }
  13836. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13837. {
  13838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13839. {
  13840. check_ascii = value[0];
  13841. if( (check_ascii < 48) || (check_ascii > 57) )
  13842. {
  13843. isSuccess = ConfigurationStatus_Rejected;
  13844. }
  13845. else
  13846. {
  13847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13848. isSuccess = ConfigurationStatus_Accepted;
  13849. }
  13850. }
  13851. else
  13852. {
  13853. isSuccess = ConfigurationStatus_Rejected;
  13854. }
  13855. }
  13856. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13857. {
  13858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13859. {
  13860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13861. isSuccess = ConfigurationStatus_Accepted;
  13862. }
  13863. else
  13864. {
  13865. isSuccess = ConfigurationStatus_Rejected;
  13866. }
  13867. }
  13868. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13869. {
  13870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13871. {
  13872. check_ascii = value[0];
  13873. if( (check_ascii < 48) || (check_ascii > 57) )
  13874. {
  13875. isSuccess = ConfigurationStatus_Rejected;
  13876. }
  13877. else
  13878. {
  13879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13880. isSuccess = ConfigurationStatus_Accepted;
  13881. }
  13882. }
  13883. else
  13884. {
  13885. isSuccess = ConfigurationStatus_Rejected;
  13886. }
  13887. }
  13888. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13889. {
  13890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13891. {
  13892. check_ascii = value[0];
  13893. if( (check_ascii < 48) || (check_ascii > 57) )
  13894. {
  13895. isSuccess = ConfigurationStatus_Rejected;
  13896. }
  13897. else
  13898. {
  13899. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13901. TransactionMessageAttemptsValue = atoi(value);
  13902. isSuccess = ConfigurationStatus_Accepted;
  13903. }
  13904. }
  13905. else
  13906. {
  13907. isSuccess = ConfigurationStatus_Rejected;
  13908. }
  13909. }
  13910. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13911. {
  13912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13913. {
  13914. check_ascii = value[0];
  13915. if( (check_ascii < 48) || (check_ascii > 57) )
  13916. {
  13917. isSuccess = ConfigurationStatus_Rejected;
  13918. }
  13919. else
  13920. {
  13921. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13923. TransactionMessageRetryIntervalValue = atoi(value);
  13924. isSuccess = ConfigurationStatus_Accepted;
  13925. }
  13926. }
  13927. else
  13928. {
  13929. isSuccess = ConfigurationStatus_Rejected;
  13930. }
  13931. }
  13932. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13933. {
  13934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13935. {
  13936. strcpy(str, (const char*)value);
  13937. for(int i = 0; str[i]; i++)
  13938. {
  13939. str[i] = tolower(str[i]);
  13940. }
  13941. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13943. isSuccess = ConfigurationStatus_Accepted;
  13944. }
  13945. else
  13946. {
  13947. isSuccess = ConfigurationStatus_Rejected;
  13948. }
  13949. }
  13950. if(strcmp(key, "WebSocketPingInterval") == 0)
  13951. {
  13952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13953. {
  13954. check_ascii = value[0];
  13955. if( (check_ascii < 48) || (check_ascii > 57) )
  13956. {
  13957. isSuccess = ConfigurationStatus_Rejected;
  13958. }
  13959. else
  13960. {
  13961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13962. isSuccess = ConfigurationStatus_Accepted;
  13963. }
  13964. }
  13965. else
  13966. {
  13967. isSuccess = ConfigurationStatus_Rejected;
  13968. }
  13969. }
  13970. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13971. {
  13972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13973. {
  13974. strcpy(str, (const char*)value);
  13975. for(int i = 0; str[i]; i++)
  13976. {
  13977. str[i] = tolower(str[i]);
  13978. }
  13979. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13981. isSuccess = ConfigurationStatus_Accepted;
  13982. }
  13983. else
  13984. {
  13985. isSuccess = ConfigurationStatus_Rejected;
  13986. }
  13987. }
  13988. if(strcmp(key, "AuthorizationKey") == 0)
  13989. {
  13990. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13991. {
  13992. strcpy(str, (const char*)value);
  13993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13994. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13995. isSuccess = ConfigurationStatus_Accepted;
  13996. }
  13997. else
  13998. {
  13999. isSuccess = ConfigurationStatus_Rejected;
  14000. }
  14001. }
  14002. if(strcmp(key, "SecurityProfile") == 0)
  14003. {
  14004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14005. {
  14006. check_ascii = value[0];
  14007. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14008. {
  14009. isSuccess = ConfigurationStatus_Rejected;
  14010. }
  14011. else if(check_ascii == 0x33)
  14012. {
  14013. isSuccess = NotSupported;
  14014. }
  14015. else
  14016. {
  14017. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14018. {
  14019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14020. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14021. isSuccess = ConfigurationStatus_Accepted;
  14022. }
  14023. else
  14024. isSuccess = ConfigurationStatus_Rejected;
  14025. }
  14026. }
  14027. else
  14028. {
  14029. isSuccess = ConfigurationStatus_Rejected;
  14030. }
  14031. }
  14032. if(strcmp(key, "DefaultPrice") == 0)
  14033. {
  14034. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14035. {
  14036. strcpy(str, (const char*)value);
  14037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14038. isSuccess = ConfigurationStatus_Accepted;
  14039. }
  14040. else
  14041. {
  14042. isSuccess = ConfigurationStatus_Rejected;
  14043. }
  14044. }
  14045. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14046. {
  14047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14048. {
  14049. strcpy(str, (const char*)value);
  14050. for(int i = 0; str[i]; i++)
  14051. {
  14052. str[i] = tolower(str[i]);
  14053. }
  14054. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14056. isSuccess = ConfigurationStatus_Accepted;
  14057. }
  14058. else
  14059. {
  14060. isSuccess = ConfigurationStatus_Rejected;
  14061. }
  14062. }
  14063. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14064. {
  14065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14066. {
  14067. strcpy(str, (const char*)value);
  14068. for(int i = 0; str[i]; i++)
  14069. {
  14070. str[i] = tolower(str[i]);
  14071. }
  14072. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14074. isSuccess = ConfigurationStatus_Accepted;
  14075. }
  14076. else
  14077. {
  14078. isSuccess = ConfigurationStatus_Rejected;
  14079. }
  14080. }
  14081. if(strcmp(key, "TimeOffset") == 0)
  14082. {
  14083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14084. {
  14085. strcpy(str, (const char*)value);
  14086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14087. isSuccess = ConfigurationStatus_Accepted;
  14088. }
  14089. else
  14090. {
  14091. isSuccess = ConfigurationStatus_Rejected;
  14092. }
  14093. }
  14094. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14095. {
  14096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14097. {
  14098. strcpy(str, (const char*)value);
  14099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14100. isSuccess = ConfigurationStatus_Accepted;
  14101. }
  14102. else
  14103. {
  14104. isSuccess = ConfigurationStatus_Rejected;
  14105. }
  14106. }
  14107. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14108. {
  14109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14110. {
  14111. strcpy(str, (const char*)value);
  14112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14113. isSuccess = ConfigurationStatus_Accepted;
  14114. }
  14115. else
  14116. {
  14117. isSuccess = ConfigurationStatus_Rejected;
  14118. }
  14119. }
  14120. #if 0
  14121. //For OCPP Test Case
  14122. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14123. {
  14124. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14125. {
  14126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14127. isSuccess = ConfigurationStatus_Accepted;
  14128. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14129. }
  14130. else
  14131. {
  14132. isSuccess = ConfigurationStatus_Rejected;
  14133. }
  14134. }
  14135. #endif
  14136. #if 1
  14137. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14138. {
  14139. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14140. {
  14141. strcpy(str, (const char*)value);
  14142. for(int i = 0; str[i]; i++)
  14143. {
  14144. str[i] = tolower(str[i]);
  14145. }
  14146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14147. isSuccess = ConfigurationStatus_Accepted;
  14148. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14149. }
  14150. else
  14151. {
  14152. isSuccess = ConfigurationStatus_Rejected;
  14153. }
  14154. }
  14155. #endif
  14156. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14157. {
  14158. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14159. {
  14160. check_ascii = value[0];
  14161. if( (check_ascii < 48) || (check_ascii > 57) )
  14162. {
  14163. isSuccess = ConfigurationStatus_Rejected;
  14164. }
  14165. else
  14166. {
  14167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14168. isSuccess = ConfigurationStatus_Accepted;
  14169. }
  14170. }
  14171. else
  14172. {
  14173. isSuccess = ConfigurationStatus_Rejected;
  14174. }
  14175. }
  14176. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14177. {
  14178. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14179. {
  14180. check_ascii = value[0];
  14181. if( (check_ascii < 48) || (check_ascii > 57) )
  14182. {
  14183. isSuccess = ConfigurationStatus_Rejected;
  14184. }
  14185. else
  14186. {
  14187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14188. isSuccess = ConfigurationStatus_Accepted;
  14189. }
  14190. }
  14191. else
  14192. {
  14193. isSuccess = ConfigurationStatus_Rejected;
  14194. }
  14195. }
  14196. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14197. {
  14198. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14199. {
  14200. strcpy(str, (const char*)value);
  14201. for(int i = 0; str[i]; i++)
  14202. {
  14203. str[i] = tolower(str[i]);
  14204. }
  14205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14206. isSuccess = ConfigurationStatus_Accepted;
  14207. }
  14208. else
  14209. {
  14210. isSuccess = ConfigurationStatus_Rejected;
  14211. }
  14212. }
  14213. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14214. {
  14215. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14216. {
  14217. check_ascii = value[0];
  14218. if( (check_ascii < 48) || (check_ascii > 57) )
  14219. {
  14220. isSuccess = ConfigurationStatus_Rejected;
  14221. }
  14222. else
  14223. {
  14224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14225. isSuccess = ConfigurationStatus_Accepted;
  14226. }
  14227. }
  14228. else
  14229. {
  14230. isSuccess = ConfigurationStatus_Rejected;
  14231. }
  14232. }
  14233. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14234. {
  14235. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14236. {
  14237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14238. isSuccess = ConfigurationStatus_Accepted;
  14239. }
  14240. else
  14241. {
  14242. isSuccess = ConfigurationStatus_Rejected;
  14243. }
  14244. }
  14245. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14246. {
  14247. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14248. {
  14249. check_ascii = value[0];
  14250. if( (check_ascii < 48) || (check_ascii > 57) )
  14251. {
  14252. isSuccess = ConfigurationStatus_Rejected;
  14253. }
  14254. else
  14255. {
  14256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14257. isSuccess = ConfigurationStatus_Accepted;
  14258. }
  14259. }
  14260. else
  14261. {
  14262. isSuccess = ConfigurationStatus_Rejected;
  14263. }
  14264. }
  14265. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14266. {
  14267. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14268. {
  14269. strcpy(str, (const char*)value);
  14270. for(int i = 0; str[i]; i++)
  14271. {
  14272. str[i] = tolower(str[i]);
  14273. }
  14274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14275. isSuccess = ConfigurationStatus_Accepted;
  14276. }
  14277. else
  14278. {
  14279. isSuccess = ConfigurationStatus_Rejected;
  14280. }
  14281. }
  14282. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14283. {
  14284. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14285. {
  14286. check_ascii = value[0];
  14287. if( (check_ascii < 48) || (check_ascii > 57) )
  14288. {
  14289. isSuccess = ConfigurationStatus_Rejected;
  14290. }
  14291. else
  14292. {
  14293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14294. isSuccess = ConfigurationStatus_Accepted;
  14295. }
  14296. }
  14297. else
  14298. {
  14299. isSuccess = ConfigurationStatus_Rejected;
  14300. }
  14301. }
  14302. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14303. return isSuccess;
  14304. }
  14305. int TransactionMessageAttemptsGet(void)
  14306. {
  14307. return TransactionMessageAttemptsValue;
  14308. }
  14309. int FirstHeartBeatResponse(void)
  14310. {
  14311. return FirstHeartBeat;
  14312. }
  14313. int TransactionMessageRetryIntervalGet(void)
  14314. {
  14315. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14316. }
  14317. int ReadHttpStatus(int sock)
  14318. {
  14319. //char c;
  14320. char buff[1024]="",*ptr=buff+1;
  14321. int bytes_received, status;
  14322. DEBUG_INFO("Begin Response ..\n");
  14323. while((bytes_received = recv(sock, ptr, 1, 0))){
  14324. if(bytes_received==-1){
  14325. perror("ReadHttpStatus");
  14326. exit(1);
  14327. }
  14328. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14329. ptr++;
  14330. }
  14331. *ptr=0;
  14332. ptr=buff+1;
  14333. sscanf(ptr,"%*s %d ", &status);
  14334. DEBUG_INFO("%s\n",ptr);
  14335. DEBUG_INFO("status=%d\n",status);
  14336. DEBUG_INFO("End Response ..\n");
  14337. return (bytes_received>0)?status:0;
  14338. }
  14339. //the only filed that it parsed is 'Content-Length'
  14340. int ParseHeader(int sock)
  14341. {
  14342. //char c;
  14343. char buff[1024]="",*ptr=buff+4;
  14344. int bytes_received;
  14345. DEBUG_INFO("Begin HEADER ..\n");
  14346. while((bytes_received = recv(sock, ptr, 1, 0))){
  14347. if(bytes_received==-1){
  14348. perror("Parse Header");
  14349. exit(1);
  14350. }
  14351. if(
  14352. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14353. (ptr[-1]=='\r') && (*ptr=='\n' )
  14354. ) break;
  14355. ptr++;
  14356. }
  14357. *ptr=0;
  14358. ptr=buff+4;
  14359. //printf("%s",ptr);
  14360. if(bytes_received){
  14361. ptr=strstr(ptr,"Content-Length:");
  14362. if(ptr){
  14363. sscanf(ptr,"%*s %d",&bytes_received);
  14364. }else
  14365. bytes_received=-1; //unknown size
  14366. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14367. }
  14368. DEBUG_INFO("End HEADER ..\n");
  14369. return bytes_received ;
  14370. }
  14371. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14372. {
  14373. int result = TRUE;
  14374. char rmFileCmd[100]={0};
  14375. char FilePath[100]={0};
  14376. char ftpbuf[200];
  14377. int systemresult;
  14378. //DEBUG_INFO("filename=%s\n",filename);
  14379. //DEBUG_INFO("url=%s\n",url);
  14380. sprintf(FilePath,"/mnt/%s",filename);
  14381. system("ping 8.8.8.8 &");
  14382. if((access(FilePath,F_OK))!=-1)
  14383. {
  14384. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14385. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14386. system(rmFileCmd);
  14387. }
  14388. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14389. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14390. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14391. systemresult = system(ftpbuf);
  14392. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14393. if(systemresult != 0)
  14394. {
  14395. DEBUG_INFO("http DownLoad error!\n");
  14396. result = FALSE;
  14397. }
  14398. system("pkill ping");
  14399. return result;
  14400. }
  14401. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14402. {
  14403. int result = TRUE;
  14404. char rmFileCmd[100]={0};
  14405. char FilePath[100]={0};
  14406. char ftpbuf[200];
  14407. int systemresult;
  14408. //char temp[100];
  14409. sprintf(FilePath,"/mnt/%s",filename);
  14410. system("ping 8.8.8.8 &");
  14411. if((access(FilePath,F_OK))!=-1)
  14412. {
  14413. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14414. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14415. system(rmFileCmd);
  14416. }
  14417. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14418. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14419. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14420. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14421. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14422. systemresult = system(ftpbuf);
  14423. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14424. if(systemresult != 0)
  14425. {
  14426. DEBUG_WARN("wget error!\n");
  14427. result = FALSE;
  14428. }
  14429. system("pkill ping");
  14430. return result;
  14431. }
  14432. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14433. {
  14434. char rmFileCmd[100]={0};
  14435. char FilePath[100]={0};
  14436. char buf[512];
  14437. int systemresult = 0;
  14438. //DEBUG_INFO("filename=%s\n",filename);
  14439. //DEBUG_INFO("url=%s\n",url);
  14440. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14441. if((access(FilePath,F_OK))!=-1)
  14442. {
  14443. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14444. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14445. system(rmFileCmd);
  14446. }
  14447. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14448. if(fp == NULL)
  14449. {
  14450. DEBUG_INFO("log is NULL\n");
  14451. return FALSE;
  14452. }
  14453. else
  14454. {
  14455. fprintf(fp, "%s\n", url);
  14456. fprintf(fp, "%s\n", filename);
  14457. fclose(fp);
  14458. }
  14459. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14460. if(phpFP == NULL)
  14461. {
  14462. DEBUG_INFO("PHP upload fail.\n");
  14463. return FALSE;
  14464. }
  14465. else
  14466. {
  14467. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14468. {
  14469. if(strstr(buf, "result") != NULL)
  14470. {
  14471. sscanf(buf, "result: %d", &systemresult);
  14472. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14473. }
  14474. }
  14475. pclose(phpFP);
  14476. }
  14477. if(systemresult != 1)
  14478. {
  14479. DEBUG_INFO("HTTP upload error!\n");
  14480. return FALSE;
  14481. }
  14482. return TRUE;
  14483. }
  14484. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14485. {
  14486. struct hostent* server;
  14487. char *IPbuffer;
  14488. char ftpbuf[200];
  14489. int systemresult;
  14490. // To retrieve host information
  14491. server = gethostbyname(location);
  14492. // To convert an Internet network
  14493. // address into ASCII string
  14494. IPbuffer = inet_ntoa(*((struct in_addr*)
  14495. server->h_addr_list[0]));
  14496. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14497. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14498. /* format : ftpput -u username -p passwd IP target source*/
  14499. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14500. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14501. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14502. systemresult = system(ftpbuf);
  14503. DEBUG_INFO("systemresult=%d\n",systemresult);
  14504. if(systemresult != 0)
  14505. {
  14506. DEBUG_INFO("ftpput error!\n");
  14507. return FALSE;
  14508. }
  14509. return TRUE;
  14510. }
  14511. int GetOcppServerURL()
  14512. {
  14513. int result = FALSE;
  14514. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14515. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14516. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14517. struct yuarel url;
  14518. char urlStr[512];
  14519. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14520. {
  14521. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14522. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14523. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14524. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14525. if(yuarel_parse(&url, urlStr) != -1)
  14526. {
  14527. sprintf(OcppProtocol, "%s", url.scheme);
  14528. sprintf(OcppHost, "%s", url.host);
  14529. if(url.path == NULL)
  14530. OcppTempPath[0] = '\0';
  14531. else
  14532. {
  14533. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14534. {
  14535. sprintf(OcppTempPath, "%s/", url.path);
  14536. }
  14537. else
  14538. {
  14539. sprintf(OcppTempPath, "%s", url.path);
  14540. }
  14541. }
  14542. if(url.port == 0)
  14543. {
  14544. if(strcmp(OcppProtocol, "wss") == 0)
  14545. OcppPort = 443;
  14546. else
  14547. OcppPort = 80;
  14548. }
  14549. else
  14550. OcppPort = url.port;
  14551. result = TRUE;
  14552. }
  14553. }
  14554. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14555. {
  14556. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14557. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14558. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14559. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14560. if(yuarel_parse(&url, urlStr) != -1)
  14561. {
  14562. sprintf(OcppProtocol, "%s", url.scheme);
  14563. sprintf(OcppHost, "%s", url.host);
  14564. if(url.path == NULL)
  14565. OcppTempPath[0] = '\0';
  14566. else
  14567. sprintf(OcppTempPath, "%s", url.path);
  14568. if(url.port == 0)
  14569. {
  14570. if(strcmp(OcppProtocol, "wss") == 0)
  14571. OcppPort = 443;
  14572. else
  14573. OcppPort = 80;
  14574. }
  14575. else
  14576. OcppPort = url.port;
  14577. result = TRUE;
  14578. }
  14579. }
  14580. else
  14581. {
  14582. strcpy(OcppHost,"");
  14583. }
  14584. return result;
  14585. }
  14586. int GetOcppPath()
  14587. {
  14588. int result = FALSE;
  14589. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14590. {
  14591. if(OcppTempPath == NULL)
  14592. {
  14593. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14594. }
  14595. else
  14596. {
  14597. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14598. }
  14599. result = TRUE;
  14600. goto End;
  14601. }
  14602. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14603. {
  14604. if(OcppTempPath == NULL)
  14605. {
  14606. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14607. }
  14608. else
  14609. {
  14610. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14611. }
  14612. result = TRUE;
  14613. goto End;
  14614. }
  14615. else
  14616. {
  14617. strcpy(OcppPath,"");
  14618. }
  14619. End:
  14620. return result;
  14621. }
  14622. int GetOcppPort()
  14623. {
  14624. return OcppPort;
  14625. }
  14626. int GetOcppConnStatus(void)
  14627. {
  14628. return ShmOCPP16Data->OcppConnStatus;
  14629. }
  14630. void SetOcppConnStatus(uint8_t status)
  14631. {
  14632. ShmOCPP16Data->OcppConnStatus = status;
  14633. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14634. }
  14635. int GetHeartBeatWithNOResponse(void)
  14636. {
  14637. return HeartBeatWithNOResponse;
  14638. }
  14639. void SetHeartBeatWithNOResponse(void)
  14640. {
  14641. HeartBeatWithNOResponse = 0;
  14642. }
  14643. void GetStartTransactionIdTag(int gun_index)
  14644. {
  14645. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14646. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14647. }
  14648. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14649. {
  14650. char ch;
  14651. FILE *fptr1;
  14652. int temptransactionId;
  14653. char str[100]={0};
  14654. temptransactionId = 0;
  14655. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14656. {
  14657. DEBUG_INFO("IdTag is empty.\n");
  14658. return temptransactionId;
  14659. }
  14660. /*------ Read the file ----------------*/
  14661. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14662. if (!fptr1)
  14663. {
  14664. DEBUG_INFO("QueueTransactionId file open error.\n");
  14665. //printf(" File not found or unable to open the input file!!\n");
  14666. return temptransactionId;
  14667. }
  14668. ch=fgetc(fptr1);
  14669. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14670. rewind(fptr1);
  14671. if(ch!=EOF)
  14672. {
  14673. // printf("%c",ch);
  14674. while (fgets(str, 100, fptr1) != NULL)
  14675. {
  14676. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14677. if(str[0]=='\0')
  14678. {
  14679. break;
  14680. }
  14681. char *revbuf[8] = {0}; // Variable store string split
  14682. int num = 0;// Quantity after string split
  14683. DEBUG_INFO("Transaction queue data= %s\n", str);
  14684. splitstring(str,",",revbuf,&num); // String split
  14685. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14686. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14687. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14688. DEBUG_INFO("------------------------------\n");
  14689. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14690. {
  14691. if(isStopTransaction)
  14692. {
  14693. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14694. {
  14695. temptransactionId = atoi(revbuf[2]);
  14696. //break;
  14697. }
  14698. }
  14699. else
  14700. {
  14701. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14702. {
  14703. temptransactionId = atoi(revbuf[2]);
  14704. //break;
  14705. }
  14706. }
  14707. }
  14708. }
  14709. }
  14710. else
  14711. DEBUG_INFO("EOF\n");
  14712. fclose(fptr1);
  14713. /*------- End of reading ---------------*/
  14714. return temptransactionId;
  14715. }
  14716. void SetTransactionIdZero(int transactionId)
  14717. {
  14718. char ch;
  14719. FILE *fptr1, *fptr2;
  14720. int temptransactionId = 0;
  14721. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14722. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14723. if (!fptr1)
  14724. {
  14725. //printf(" File not found or unable to open the input file!!\n");
  14726. return ;
  14727. }
  14728. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14729. if (!fptr2)
  14730. {
  14731. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14732. fclose(fptr1);
  14733. return ;
  14734. }
  14735. ch=fgetc(fptr1);
  14736. rewind(fptr1);
  14737. if(ch!=EOF)
  14738. {
  14739. // copy all contents to the temporary file except the specific line
  14740. while (fgets(str, 100, fptr1) != NULL)
  14741. {
  14742. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14743. if(str[0]=='\0')
  14744. {
  14745. break;
  14746. }
  14747. char *revbuf[8] = {0};
  14748. int num = 0;
  14749. strcpy(strtemp, str);
  14750. splitstring(str,",",revbuf,&num);
  14751. if(revbuf[2][0] != '\0')
  14752. {
  14753. temptransactionId = atoi(revbuf[2]);
  14754. if(transactionId != temptransactionId)
  14755. {
  14756. fprintf(fptr2, "%s\n", strtemp);
  14757. }
  14758. }
  14759. }
  14760. }
  14761. fclose(fptr1);
  14762. fclose(fptr2);
  14763. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14764. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14765. /*------ Read the file ----------------*/
  14766. }
  14767. int InternetDisconnect(void)
  14768. {
  14769. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14770. }
  14771. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14772. void storeTempStopTransaction(int gun_index)
  14773. {
  14774. char guid[37]={0};
  14775. int tempIndex = 0;
  14776. char TempStopTransaction[256];
  14777. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14778. DEBUG_INFO("storeTempStopTransaction...\n");
  14779. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14780. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14781. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14782. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14784. {
  14785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14786. {
  14787. tempIndex = ((gun_index==2) ? 1: 0);
  14788. }
  14789. else
  14790. {
  14791. tempIndex = gun_index;
  14792. }
  14793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14794. {
  14795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14796. {
  14797. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14798. }
  14799. }// END OF CHAdeMO_QUANTITY
  14800. }
  14801. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14802. {
  14803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14804. {
  14805. tempIndex = ((gun_index==2) ? 1: 0);
  14806. }
  14807. else
  14808. {
  14809. tempIndex = gun_index;
  14810. }
  14811. for (int index = 0; index < CCS_QUANTITY; index++)
  14812. {
  14813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14814. {
  14815. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14816. }
  14817. }// END OF CCS_QUANTITY
  14818. }
  14819. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14820. {
  14821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14822. {
  14823. tempIndex = ((gun_index==2) ? 1: 0);
  14824. }
  14825. else
  14826. {
  14827. tempIndex = gun_index;
  14828. }
  14829. for (int index = 0; index < GB_QUANTITY; index++)
  14830. {
  14831. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14832. {
  14833. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14834. }
  14835. }// END OF GB_QUANTITY
  14836. }
  14837. else if(gunType[gun_index] == GUN_TYPE_DO)
  14838. {
  14839. tempIndex = gun_index;
  14840. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14841. {
  14842. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14843. {
  14844. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14845. }
  14846. }
  14847. }
  14848. else
  14849. {
  14850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14851. {
  14852. tempIndex = 2;
  14853. }
  14854. else
  14855. {
  14856. tempIndex = gun_index;
  14857. }
  14858. for (int index = 0; index < AC_QUANTITY; index++)
  14859. {
  14860. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14861. {
  14862. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14863. }
  14864. }// END OF AC_QUANTITY
  14865. }
  14866. //Stop Transaction Time
  14867. struct timeval tmnow;
  14868. struct tm *tm;
  14869. char buf[28];//, usec_buf[6];
  14870. gettimeofday(&tmnow, NULL);
  14871. time_t t;
  14872. t = time(NULL);
  14873. /*UTC time and date*/
  14874. tm = gmtime(&t);
  14875. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14877. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14879. random_uuid(guid);
  14880. /***********************************transactionData******************************************************/
  14881. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14883. //=================================
  14884. //1. Transaction_Begin
  14885. //=================================
  14886. //============================== Energy.Active.Import.Interval ===========================================
  14887. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14888. {
  14889. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14892. 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*/]);
  14893. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14894. 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))
  14895. {
  14896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14897. }
  14898. else
  14899. {
  14900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14901. }
  14902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14904. }
  14905. //=================================
  14906. //2. Transaction_End
  14907. //=================================
  14908. //2.1====================================== Current.Import L1 ==============================================
  14909. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14910. {
  14911. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14913. {
  14914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14915. {
  14916. tempIndex = ((gun_index==2) ? 1: 0);
  14917. }
  14918. else
  14919. {
  14920. tempIndex = gun_index;
  14921. }
  14922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14923. {
  14924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14925. {
  14926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14927. }
  14928. }// End of for CHAdeMO_QUANTITY
  14929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14930. }
  14931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14932. {
  14933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14934. {
  14935. tempIndex = ((gun_index==2) ? 1: 0);
  14936. }
  14937. else
  14938. {
  14939. tempIndex = gun_index;
  14940. }
  14941. for (int index = 0; index < CCS_QUANTITY; index++)
  14942. {
  14943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14944. {
  14945. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14946. }
  14947. }// End of for CCS_QUANTITY
  14948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14949. }
  14950. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14951. {
  14952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14953. {
  14954. tempIndex = ((gun_index==2) ? 1: 0);
  14955. }
  14956. else
  14957. {
  14958. tempIndex = gun_index;
  14959. }
  14960. for (int index = 0; index < GB_QUANTITY; index++)
  14961. {
  14962. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14963. {
  14964. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14965. }
  14966. }// End of for GB_QUANTITY
  14967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14968. }
  14969. else if(gunType[gun_index] == GUN_TYPE_DO)
  14970. {
  14971. tempIndex = gun_index;
  14972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14973. {
  14974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14975. {
  14976. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14977. }
  14978. }
  14979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14980. }
  14981. else
  14982. {
  14983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14984. {
  14985. tempIndex = 2;
  14986. }
  14987. else
  14988. {
  14989. tempIndex = gun_index;
  14990. }
  14991. for (int index = 0; index < AC_QUANTITY; index++)
  14992. {
  14993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14994. {
  14995. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14996. }
  14997. }// End of for AC_QUANTITY
  14998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14999. }
  15000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15003. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15006. }
  15007. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15008. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15009. {
  15010. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15011. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15012. {
  15013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15014. {
  15015. tempIndex = ((gun_index==2) ? 1: 0);
  15016. }
  15017. else
  15018. {
  15019. tempIndex = gun_index;
  15020. }
  15021. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15022. {
  15023. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15024. {
  15025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15026. }
  15027. }// END OF CHAdeMO_QUANTITY
  15028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15029. }
  15030. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15031. {
  15032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15033. {
  15034. tempIndex = ((gun_index==2) ? 1: 0);
  15035. }
  15036. else
  15037. {
  15038. tempIndex = gun_index;
  15039. }
  15040. for (int index = 0; index < CCS_QUANTITY; index++)
  15041. {
  15042. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15043. {
  15044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15045. }
  15046. }// END OF CCS_QUANTITY
  15047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15048. }
  15049. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15050. {
  15051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15052. {
  15053. tempIndex = ((gun_index==2) ? 1: 0);
  15054. }
  15055. else
  15056. {
  15057. tempIndex = gun_index;
  15058. }
  15059. for (int index = 0; index < GB_QUANTITY; index++)
  15060. {
  15061. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15062. {
  15063. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15064. }
  15065. }// END OF GB_QUANTITY
  15066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15067. }
  15068. else if(gunType[gun_index] == GUN_TYPE_DO)
  15069. {
  15070. tempIndex = gun_index;
  15071. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15072. {
  15073. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15074. {
  15075. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15076. }
  15077. }
  15078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15079. }
  15080. else
  15081. {
  15082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15083. {
  15084. tempIndex = 2;
  15085. }
  15086. else
  15087. {
  15088. tempIndex = gun_index;
  15089. }
  15090. for (int index = 0; index < AC_QUANTITY; index++)
  15091. {
  15092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15093. {
  15094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15095. }
  15096. }// END OF AC_QUANTITY
  15097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15098. }
  15099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15102. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15105. }
  15106. //2.3====================================== Power.Active.Import =========================================
  15107. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15108. {
  15109. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15110. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15111. {
  15112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15113. {
  15114. tempIndex = ((gun_index==2) ? 1: 0);
  15115. }
  15116. else
  15117. {
  15118. tempIndex = gun_index;
  15119. }
  15120. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15121. {
  15122. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15123. {
  15124. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15125. }
  15126. } // End for CHAdeMO_QUANTITY
  15127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15128. }
  15129. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15130. {
  15131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15132. {
  15133. tempIndex = ((gun_index==2) ? 1: 0);
  15134. }
  15135. else
  15136. {
  15137. tempIndex = gun_index;
  15138. }
  15139. for (int index = 0; index < CCS_QUANTITY; index++)
  15140. {
  15141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15142. {
  15143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15144. }
  15145. } // END for CCS_QUANTITY
  15146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15147. }
  15148. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15149. {
  15150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15151. {
  15152. tempIndex = ((gun_index==2) ? 1: 0);
  15153. }
  15154. else
  15155. {
  15156. tempIndex = gun_index;
  15157. }
  15158. for (int index = 0; index < GB_QUANTITY; index++)
  15159. {
  15160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15161. {
  15162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15163. }
  15164. }// END for GB_QUANTITY
  15165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15166. }
  15167. else if(gunType[gun_index] == GUN_TYPE_DO)
  15168. {
  15169. tempIndex = gun_index;
  15170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15171. {
  15172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15173. {
  15174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15175. }
  15176. }
  15177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15178. }
  15179. else
  15180. {
  15181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15182. {
  15183. tempIndex = 2;
  15184. }
  15185. else
  15186. {
  15187. tempIndex = gun_index;
  15188. }
  15189. for (int index = 0; index < AC_QUANTITY; index++)
  15190. {
  15191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15192. {
  15193. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15194. }
  15195. } // END for AC_QUANTITY
  15196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15197. }
  15198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15201. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15204. }
  15205. //2.4====================================== Voltage L1 ====================================================
  15206. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15207. {
  15208. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15209. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15210. {
  15211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15212. {
  15213. tempIndex = ((gun_index==2) ? 1: 0);
  15214. }
  15215. else
  15216. {
  15217. tempIndex = gun_index;
  15218. }
  15219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15220. {
  15221. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15222. {
  15223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15224. }
  15225. } // END OF FOR CHAdeMO_QUANTITY
  15226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15227. }
  15228. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15229. {
  15230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15231. {
  15232. tempIndex = ((gun_index==2) ? 1: 0);
  15233. }
  15234. else
  15235. {
  15236. tempIndex = gun_index;
  15237. }
  15238. for (int index = 0; index < CCS_QUANTITY; index++)
  15239. {
  15240. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15241. {
  15242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15243. }
  15244. } // END OF FOR CCS_QUANTITY
  15245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15246. }
  15247. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15248. {
  15249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15250. {
  15251. tempIndex = ((gun_index==2) ? 1: 0);
  15252. }
  15253. else
  15254. {
  15255. tempIndex = gun_index;
  15256. }
  15257. for (int index = 0; index < GB_QUANTITY; index++)
  15258. {
  15259. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15260. {
  15261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15262. }
  15263. } // END OF FOR GB_QUANTITY
  15264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15265. }
  15266. else if(gunType[gun_index] == GUN_TYPE_DO)
  15267. {
  15268. tempIndex = gun_index;
  15269. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15270. {
  15271. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15272. {
  15273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15274. }
  15275. }
  15276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15277. }
  15278. else
  15279. {
  15280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15281. {
  15282. tempIndex = 2;
  15283. }
  15284. else
  15285. {
  15286. tempIndex = gun_index;
  15287. }
  15288. for (int index = 0; index < AC_QUANTITY; index++)
  15289. {
  15290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15291. {
  15292. 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
  15293. }
  15294. } // END OF FOR AC_QUANTITY
  15295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15296. }
  15297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15300. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15303. }
  15304. //2.5============================================== End SoC =========================================================
  15305. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15306. {
  15307. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15308. 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))
  15309. {
  15310. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15311. {
  15312. tempIndex = ((gun_index==2) ? 1: 0);
  15313. }
  15314. else
  15315. {
  15316. tempIndex = gun_index;
  15317. }
  15318. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15319. {
  15320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15321. {
  15322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15323. {
  15324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15325. }
  15326. }
  15327. }
  15328. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15329. {
  15330. for (int index = 0; index < CCS_QUANTITY; index++)
  15331. {
  15332. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15333. {
  15334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15335. }
  15336. }
  15337. }
  15338. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15339. {
  15340. for (int index = 0; index < GB_QUANTITY; index++)
  15341. {
  15342. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15343. {
  15344. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15345. }
  15346. }
  15347. }
  15348. else if(gunType[gun_index] == GUN_TYPE_DO)
  15349. {
  15350. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15351. {
  15352. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15353. {
  15354. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15355. }
  15356. }
  15357. }
  15358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15364. } // END FOR DC CASE
  15365. }
  15366. //2.6====================================== Current.Import L2 ==============================================
  15367. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15368. {
  15369. // AC 3 phase L2 current
  15370. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15371. {
  15372. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15373. {
  15374. tempIndex = 2;
  15375. }
  15376. else
  15377. {
  15378. tempIndex = gun_index;
  15379. }
  15380. for (int index = 0; index < AC_QUANTITY; index++)
  15381. {
  15382. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15383. {
  15384. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15385. }
  15386. }// End of for AC_QUANTITY
  15387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15388. }
  15389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15394. }
  15395. //2.7====================================== Current.Import L3 ==============================================
  15396. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15397. {
  15398. // AC 3 phase L3 current
  15399. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15400. {
  15401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15402. {
  15403. tempIndex = 2;
  15404. }
  15405. else
  15406. {
  15407. tempIndex = gun_index;
  15408. }
  15409. for (int index = 0; index < AC_QUANTITY; index++)
  15410. {
  15411. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15412. {
  15413. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15414. }
  15415. }// End of for AC_QUANTITY
  15416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15417. }
  15418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15423. }
  15424. //2.9====================================== Voltage L2 ====================================================
  15425. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15426. {
  15427. // AC 3 phase L2 volatge
  15428. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15429. {
  15430. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15431. {
  15432. tempIndex = 2;
  15433. }
  15434. else
  15435. {
  15436. tempIndex = gun_index;
  15437. }
  15438. for (int index = 0; index < AC_QUANTITY; index++)
  15439. {
  15440. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15441. {
  15442. 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
  15443. }
  15444. } // END OF FOR AC_QUANTITY
  15445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15446. }
  15447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15452. }
  15453. //2.10====================================== Voltage L3 ====================================================
  15454. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15455. {
  15456. // AC 3 phase L3 volatge
  15457. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15458. {
  15459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15460. {
  15461. tempIndex = 2;
  15462. }
  15463. else
  15464. {
  15465. tempIndex = gun_index;
  15466. }
  15467. for (int index = 0; index < AC_QUANTITY; index++)
  15468. {
  15469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15470. {
  15471. 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
  15472. }
  15473. } // END OF FOR AC_QUANTITY
  15474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15475. }
  15476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15481. }
  15482. //====================== Start SoC ================================
  15483. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15484. {
  15485. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15486. 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))
  15487. {
  15488. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15489. {
  15490. tempIndex = ((gun_index==2) ? 1: 0);
  15491. }
  15492. else
  15493. {
  15494. tempIndex = gun_index;
  15495. }
  15496. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15497. {
  15498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15499. {
  15500. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15501. {
  15502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15503. }
  15504. }
  15505. }
  15506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15507. {
  15508. for (int index = 0; index < CCS_QUANTITY; index++)
  15509. {
  15510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15511. {
  15512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15513. }
  15514. }
  15515. }
  15516. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15517. {
  15518. for (int index = 0; index < GB_QUANTITY; index++)
  15519. {
  15520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15521. {
  15522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15523. }
  15524. }
  15525. }
  15526. else if(gunType[gun_index] == GUN_TYPE_DO)
  15527. {
  15528. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15529. {
  15530. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15531. {
  15532. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15533. }
  15534. }
  15535. }
  15536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15542. } // END FOR DC CASE
  15543. }
  15544. //======================================== Message create ==============================================
  15545. json_object *StopTransaction = json_object_new_object();
  15546. json_object *transactionDatas = json_object_new_array();
  15547. json_object *sampledValues = json_object_new_array();
  15548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15549. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15550. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15551. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15552. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15553. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15554. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15555. {
  15556. json_object *transactionData = json_object_new_object();
  15557. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15558. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15559. {
  15560. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15561. {
  15562. json_object *sampledValue = json_object_new_object();
  15563. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15564. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15565. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15566. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15567. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15568. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15569. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15570. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15571. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15572. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15573. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15574. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15575. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15576. json_object_array_add(sampledValues, sampledValue);
  15577. }
  15578. }
  15579. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15580. json_object_array_add(transactionDatas, transactionData);
  15581. }
  15582. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15583. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15584. ,MESSAGE_TYPE_CALL
  15585. ,guid
  15586. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15587. json_object_put(StopTransaction);
  15588. // Check File "TempStopTransaction" Exist
  15589. if((access(TempStopTransaction,F_OK))!=-1)
  15590. {
  15591. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15592. fclose(fopen(TempStopTransaction, "w"));
  15593. }
  15594. else
  15595. {
  15596. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15597. FILE *log = fopen(TempStopTransaction, "w+");
  15598. if(log == NULL)
  15599. {
  15600. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15601. return ;
  15602. }
  15603. else
  15604. {
  15605. fclose(log);
  15606. }
  15607. }
  15608. //Add TempStopTransaction | Update TempStopTransaction
  15609. // open file for writing
  15610. FILE *outfile;
  15611. outfile = fopen (TempStopTransaction, "a");
  15612. //DEBUG_INFO("data = %s\n", queuedata);
  15613. fputs(queuedata, outfile);
  15614. fputs("\n", outfile);
  15615. fclose (outfile);
  15616. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15617. }
  15618. void checkTempStopTransaction(int gun_index)
  15619. {
  15620. FILE *fptr1;
  15621. char ch;
  15622. char str[QUEUE_MESSAGE_LENGTH]={0};
  15623. char guid[37]={0};
  15624. char tempdata[65]={0};
  15625. char connectorStr[2]={0};
  15626. char TempStopTransaction[256];
  15627. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15628. fptr1 = fopen(TempStopTransaction, "r");
  15629. //TempStopTransaction格式: 槍號,StopTransaction封包
  15630. if (!fptr1)
  15631. {
  15632. //printf(" File not found or unable to open the input file!!\n");
  15633. return ;
  15634. }
  15635. ch=fgetc(fptr1);
  15636. //printf(" Now the content of the file %s is : \n",fname);
  15637. rewind(fptr1);
  15638. if(ch!=EOF)
  15639. {
  15640. // copy all contents to the temporary file except the specific line
  15641. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15642. {
  15643. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15644. if(str[0]=='\0')
  15645. {
  15646. break;
  15647. }
  15648. //TempStopTransaction格式: 槍號,StopTransaction封包
  15649. strncpy(connectorStr, str, 1);
  15650. if(atoi(connectorStr) != (gun_index+1))
  15651. {
  15652. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15653. fclose(fptr1);
  15654. return ;
  15655. }
  15656. //random_uuid(guid);
  15657. strncpy(guid, str+6, 36); //copy guid
  15658. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15659. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15660. {
  15661. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15662. }
  15663. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15664. OCPP_insert_transaction_msg(NO, str);
  15665. memset(str,0,ARRAY_SIZE(str));
  15666. }
  15667. }
  15668. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15669. fclose(fptr1);
  15670. remove(TempStopTransaction); // remove the original file
  15671. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15672. }
  15673. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15674. {
  15675. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15676. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15677. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15678. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15679. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15680. }
  15681. int GetWebSocketPingInterval(void)
  15682. {
  15683. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15684. }
  15685. int GetServerSign(void)
  15686. {
  15687. return server_sign;
  15688. }
  15689. uint8_t GetOcppSecurityProfile()
  15690. {
  15691. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15692. }
  15693. void GetOcppChargerBoxId(uint8_t *data)
  15694. {
  15695. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15696. }
  15697. void GetOcppSecurityPassword(uint8_t *data)
  15698. {
  15699. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15700. }
  15701. void SetOcppVersion(uint8_t *version)
  15702. {
  15703. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15704. DEBUG_INFO("ocpp version: %s\n", version);
  15705. if(strstr((char*)version, "ocpp1.6") != NULL)
  15706. {
  15707. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15708. }
  15709. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15710. {
  15711. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15712. system("pkill OcppBackend");
  15713. }
  15714. }
  15715. void SetServerSign(int value)
  15716. {
  15717. server_sign = value;
  15718. }
  15719. int GetBootNotificationInterval(void)
  15720. {
  15721. return BootNotificationInterval;
  15722. }
  15723. int GetInternetConn(void)
  15724. {
  15725. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15726. }
  15727. int GetBackendConnectionTimeout(void)
  15728. {
  15729. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15730. }
  15731. int isConnectorInitMode(int gun_index)
  15732. {
  15733. int tempIndex = 0;
  15734. int result = TRUE;
  15735. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15736. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15737. {
  15738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15739. {
  15740. tempIndex = ((gun_index==2) ? 1: 0);
  15741. }
  15742. else
  15743. {
  15744. tempIndex = gun_index;
  15745. }
  15746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15747. {
  15748. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15749. {
  15750. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15751. } //end of the same index
  15752. }//end of for CHAdeMO_QUANTITY
  15753. }
  15754. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15755. {
  15756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15757. {
  15758. tempIndex = ((gun_index==2) ? 1: 0);
  15759. }
  15760. else
  15761. {
  15762. tempIndex = gun_index;
  15763. }
  15764. for (int index = 0; index < CCS_QUANTITY; index++)
  15765. {
  15766. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15767. {
  15768. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15769. } //end of the same index
  15770. } // end of for CCS_QUANTITY
  15771. }
  15772. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15773. {
  15774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15775. {
  15776. tempIndex = ((gun_index==2) ? 1: 0);
  15777. }
  15778. else
  15779. {
  15780. tempIndex = gun_index;
  15781. }
  15782. for (int index = 0; index < GB_QUANTITY; index++)
  15783. {
  15784. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15785. {
  15786. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15787. } //end of the same index
  15788. } // end of for GB_QUANTITY
  15789. }
  15790. else if(gunType[gun_index] == GUN_TYPE_DO)
  15791. {
  15792. tempIndex = gun_index;
  15793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15794. {
  15795. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15796. {
  15797. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15798. } //end of the same index
  15799. }
  15800. }
  15801. else
  15802. {
  15803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15804. {
  15805. tempIndex = 2;
  15806. }
  15807. else
  15808. {
  15809. tempIndex = gun_index;
  15810. }
  15811. for (int index = 0; index < AC_QUANTITY; index++)
  15812. {
  15813. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15814. {
  15815. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15816. }//end of the same index
  15817. }//end of for AC_QUANTITY
  15818. }
  15819. return result;
  15820. }
  15821. void refreshProcDogTimer()
  15822. {
  15823. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15824. }
  15825. void InitialSystemValue(void)
  15826. {
  15827. int connectorIndex = 0;
  15828. //int valueASCII = 0;
  15829. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15830. gunTotalNumber=0;
  15831. SystemInitial = 0;
  15832. locallistVersion=0;
  15833. BootNotificationInterval = 0;
  15834. authorizeRetryTimes = 0;
  15835. GunStatusInterval = 10;
  15836. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15837. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15838. //Hear Beat
  15839. HeartBeatWithNOResponse = 0;
  15840. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15841. FirstHeartBeat = 0;
  15842. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15843. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15844. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15845. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15846. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15847. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15848. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15849. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15850. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15851. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15852. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15853. memset(gunType, 0, ARRAY_SIZE(gunType));
  15854. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15855. {
  15856. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  15857. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  15858. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  15859. {
  15860. // DO series
  15861. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15862. {
  15863. SystemInitial = SystemInitial + 1;
  15864. gunTotalNumber = gunTotalNumber + 1;
  15865. gunType[connectorIndex] = GUN_TYPE_DO;
  15866. connectorIndex = connectorIndex + 1;
  15867. }
  15868. }
  15869. else
  15870. {
  15871. // DM, DW, DS series
  15872. //check connector / socket type (index: 8, 9, 10)
  15873. for(int index=7; index <10 ; index++)
  15874. {
  15875. if(index != 8)
  15876. {
  15877. // DC Connector
  15878. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15879. {
  15880. SystemInitial = SystemInitial + 1;
  15881. gunTotalNumber = gunTotalNumber + 1;
  15882. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15883. connectorIndex = connectorIndex + 1;
  15884. }
  15885. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15886. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15887. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15888. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15889. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15890. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15891. {
  15892. SystemInitial = SystemInitial + 1;
  15893. gunTotalNumber = gunTotalNumber + 1;
  15894. gunType[connectorIndex] = GUN_TYPE_CCS;
  15895. connectorIndex = connectorIndex + 1;
  15896. }
  15897. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15898. {
  15899. SystemInitial = SystemInitial + 1;
  15900. gunTotalNumber = gunTotalNumber + 1;
  15901. gunType[connectorIndex] = GUN_TYPE_GBT;
  15902. connectorIndex = connectorIndex + 1;
  15903. }
  15904. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15905. {
  15906. SystemInitial = SystemInitial + 1;
  15907. gunTotalNumber = gunTotalNumber + 1;
  15908. gunType[connectorIndex] = GUN_TYPE_DO;
  15909. connectorIndex = connectorIndex + 1;
  15910. }
  15911. }
  15912. else
  15913. {
  15914. // AC Connector
  15915. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15916. {
  15917. SystemInitial = SystemInitial + 1;
  15918. gunTotalNumber = gunTotalNumber + 1;
  15919. gunType[connectorIndex] = GUN_TYPE_AC;
  15920. connectorIndex = connectorIndex + 1;
  15921. }
  15922. }
  15923. }
  15924. }
  15925. //DEBUG_INFO("DC ...\n");
  15926. }
  15927. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15928. {
  15929. //check connector / socket type (index: 8, 9, 10)
  15930. for(int index=7; index <10 ; index++)
  15931. {
  15932. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15933. {
  15934. SystemInitial = SystemInitial + 1;
  15935. gunTotalNumber = gunTotalNumber + 1;
  15936. gunType[connectorIndex] = GUN_TYPE_AC;
  15937. connectorIndex = connectorIndex + 1;
  15938. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15939. }
  15940. }
  15941. }
  15942. //Status && ConnectorPlugIn Setting
  15943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15944. {
  15945. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15946. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15947. }
  15948. for (int index = 0; index < CCS_QUANTITY; index++)
  15949. {
  15950. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15951. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15952. }
  15953. for (int index = 0; index < GB_QUANTITY; index++)
  15954. {
  15955. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15956. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15957. }
  15958. for (int index = 0; index < AC_QUANTITY; index++)
  15959. {
  15960. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15961. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15962. }
  15963. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15964. {
  15965. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15966. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15967. }
  15968. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15969. {
  15970. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15971. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15972. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15973. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15974. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15975. }
  15976. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15977. clientTime.Heartbeat=time((time_t*)NULL);
  15978. sleep(1);
  15979. }
  15980. void LWS_Send(char *str)
  15981. {
  15982. //=====================================================
  15983. // Check InternetConn 0: disconnected, 1: connected
  15984. //====================================================
  15985. if(GetOcppConnStatus() == 0)
  15986. {
  15987. DEBUG_INFO("offline now !!!\n");
  15988. return;
  15989. }
  15990. // Only disable isWebsocketSendable operation initiated by charger
  15991. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15992. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15993. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15994. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15995. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15996. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15997. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15998. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15999. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16000. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16001. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16002. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16003. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16004. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16005. {
  16006. isWebsocketSendable = 0;
  16007. }
  16008. pthread_mutex_lock(&lock_send);
  16009. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16010. sprintf((char *)SendBuffer, "%s", str);
  16011. SendBufLen = strlen(str);
  16012. pthread_mutex_unlock(&lock_send);
  16013. lws_callback_on_writable(wsi_client);
  16014. //lws_service(context, 0);
  16015. //sleep(1);
  16016. }
  16017. void LWS_SendNow(char *str)
  16018. {
  16019. //=====================================================
  16020. // Check InternetConn 0: disconnected, 1: connected
  16021. //====================================================
  16022. if(GetOcppConnStatus() == 0)
  16023. {
  16024. DEBUG_INFO("offline now !!!\n");
  16025. return;
  16026. }
  16027. // Only disable isWebsocketSendable operation initiated by charger
  16028. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16029. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16030. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16031. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16032. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16033. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16034. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16035. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16036. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16037. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16038. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16039. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16040. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16041. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16042. {
  16043. isWebsocketSendable = 0;
  16044. }
  16045. pthread_mutex_lock(&lock_send);
  16046. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16047. sprintf((char *)SendBuffer, "%s", str);
  16048. SendBufLen = strlen(str);
  16049. pthread_mutex_unlock(&lock_send);
  16050. lws_callback_on_writable(wsi_client);
  16051. lws_service(context, 0);
  16052. //sleep(1);
  16053. }