MessageHandler.c 777 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264
  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 localversion=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 :4; //bit 4~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Save configuration
  355. //=========================================
  356. int runShellCmd(const char*cmd)
  357. {
  358. int result = FAIL;
  359. char buf[256];
  360. FILE *fp;
  361. fp = popen(cmd, "r");
  362. if(fp != NULL)
  363. {
  364. while(fgets(buf, sizeof(buf), fp) != NULL)
  365. {
  366. DEBUG_INFO("%s\n", buf);
  367. }
  368. result = PASS;
  369. }
  370. pclose(fp);
  371. return result;
  372. }
  373. int StoreUsrConfigData(struct SysConfigData *UsrData)
  374. {
  375. int result = PASS;
  376. int fd,wrd;
  377. unsigned int i,Chk;
  378. unsigned char *ptr, *BufTmp;
  379. int MtdBlockSize = 0x300000;
  380. Chk=0;
  381. ptr=(unsigned char *)UsrData;
  382. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  383. {
  384. memset(BufTmp,0,MtdBlockSize);
  385. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  386. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  387. Chk+=*(BufTmp+i);
  388. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  389. // Output configuration to file.
  390. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  391. if (fd < 0)
  392. {
  393. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  394. free(BufTmp);
  395. return 0;
  396. }
  397. wrd=write(fd, BufTmp, MtdBlockSize);
  398. close(fd);
  399. if(wrd<MtdBlockSize)
  400. {
  401. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  402. free(BufTmp);
  403. return 0;
  404. }
  405. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  406. DEBUG_INFO("Erase /dev/mtd10.\n");
  407. runShellCmd("flash_erase /dev/mtd10 0 0");
  408. DEBUG_INFO("Write /dev/mtd10.\n");
  409. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  410. DEBUG_INFO("Erase /dev/mtd11.\n");
  411. runShellCmd("flash_erase /dev/mtd11 0 0");
  412. DEBUG_INFO("Write /dev/mtd11.\n");
  413. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  414. system("rm -f /mnt/EvseConfig.bin");
  415. DEBUG_INFO("EvseConfig write to flash OK\n");
  416. }
  417. else
  418. {
  419. DEBUG_ERROR("alloc BlockSize NG\r\n");
  420. result = FAIL;
  421. }
  422. if(BufTmp!=NULL)
  423. free(BufTmp);
  424. return result;
  425. }
  426. //=========================================
  427. // Sqlite3 related function
  428. //=========================================
  429. static int selectSqlCount = 0;
  430. static int callback(void *data, int argc, char **argv, char **azColName){
  431. int i;
  432. //printf("%s: ", (const char*)data);
  433. selectSqlCount = argc;
  434. for(i = 0; i<argc; i++){
  435. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  436. }
  437. //printf("\n");
  438. return 0;
  439. }
  440. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  441. //int i;
  442. //printf("%s:\n", (const char*)data);
  443. localversion = argv[5] ? atoi(argv[5]) : 0;
  444. //printf("localversion=%d\n", localversion);
  445. return 0;
  446. }
  447. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  448. //printf("%s:\n", (const char*)data);
  449. //idTag
  450. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  451. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. //parentIdTag
  453. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  454. //expir_date
  455. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  456. //status
  457. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  458. //version
  459. if(columenCount > 5)
  460. idTagQuery.listVersionInt = atoi(columnValue[5]);
  461. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  462. return 0;
  463. }
  464. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  465. {
  466. // localversion = argv[5] ? atoi(argv[5]) : 0;
  467. // printf("localversion=%d\n", localversion);
  468. return 0;
  469. }
  470. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  471. {
  472. for (int i = 0; i < n_columns; i++)
  473. {
  474. DEBUG_INFO("%s\t", col_values[i]);
  475. }
  476. DEBUG_INFO("\n");
  477. return 0;
  478. }
  479. int OCPP_cleanLocalCache()
  480. {
  481. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  482. char *errMsg = 0;
  483. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  484. if (SQLITE_OK != rc)
  485. {
  486. DEBUG_INFO("SQL error: %s\n",errMsg);
  487. return FALSE;
  488. }
  489. return TRUE;
  490. }
  491. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  492. {
  493. int isSuccess = TRUE;
  494. int ret = 0;
  495. //const char* data = "Callback function called";
  496. char sql[300];
  497. char zErrMsg[200];
  498. memset(sql, 0, 300);
  499. memset(zErrMsg, 0, 200);
  500. 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);
  501. //* Execute SQL statement */
  502. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  503. if( ret != SQLITE_OK )
  504. {
  505. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  506. isSuccess = FALSE;
  507. }
  508. return isSuccess;
  509. }
  510. void OCPP_getIdTagFromLocalCache(char idTag[])
  511. {
  512. int rc = 0;
  513. char sql[100];
  514. char zErrMsg[100];
  515. memset(sql, 0, 100);
  516. memset(zErrMsg, 0, 100);
  517. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  518. memset(&idTagQuery, 0, sizeof(idTagQuery));
  519. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  520. /* Execute SQL statement */
  521. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  522. if( rc != SQLITE_OK )
  523. {
  524. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  525. }
  526. }
  527. void OCPP_getListVerion()
  528. {
  529. int rc = 0;
  530. // const char* data = "Callback function called";
  531. char sql[100];
  532. char zErrMsg[100];
  533. memset(sql, 0, 100);
  534. memset(zErrMsg, 0, 100);
  535. strcpy(sql, "select * from ocpp_auth_local order by idx");
  536. /* Execute SQL statement */
  537. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  538. if( rc != SQLITE_OK )
  539. {
  540. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  541. }
  542. }
  543. void OCPP_get_TableAuthlocalAllData(void)
  544. {
  545. int rc = 0;
  546. char sql[100];
  547. char zErrMsg[100];
  548. memset(sql, 0, 100);
  549. memset(zErrMsg, 0, 100);
  550. sprintf(sql,"select * from ocpp_auth_local ");
  551. /* Execute SQL statement */
  552. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  553. if( rc != SQLITE_OK )
  554. {
  555. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  556. }
  557. //return ver;
  558. }
  559. int OCPP_cleanLocalList()
  560. {
  561. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  562. char *errMsg = 0;
  563. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  564. if (SQLITE_OK != rc)
  565. {
  566. DEBUG_INFO("%s\n",errMsg);
  567. return FALSE;
  568. }
  569. return TRUE;
  570. }
  571. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  572. {
  573. int isSuccess = FALSE;
  574. int ret = 0;
  575. //const char* data = "Callback function called";
  576. char sql[300];
  577. char zErrMsg[200];
  578. memset(sql, 0, 300);
  579. memset(zErrMsg, 0, 200);
  580. 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);
  581. //* Execute SQL statement */
  582. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  583. if( ret != SQLITE_OK )
  584. {
  585. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  586. return isSuccess;
  587. }
  588. memset(sql, 0, 300);
  589. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  590. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  591. if( ret != SQLITE_OK )
  592. {
  593. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  594. return isSuccess;
  595. }
  596. isSuccess = TRUE;
  597. return isSuccess;
  598. }
  599. void OCPP_getIdTagFromLocalList(char idTag[])
  600. {
  601. int rc = 0;
  602. // const char* data = "Callback function called";
  603. char sql[100];
  604. char zErrMsg[100];
  605. memset(sql, 0, 100);
  606. memset(zErrMsg, 0, 100);
  607. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  608. memset(&idTagQuery, 0, sizeof(idTagQuery));
  609. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  610. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  611. /* Execute SQL statement */
  612. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  613. if( rc != SQLITE_OK )
  614. {
  615. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  616. }
  617. //return ver;
  618. }
  619. void OCPP_deleteIdTagFromLocalList(char idTag[])
  620. {
  621. //int ver = 0;
  622. //int isSuccess = FALSE;
  623. int rc = 0;
  624. char sql[100];
  625. char zErrMsg[100];
  626. memset(sql, 0, 100);
  627. memset(zErrMsg, 0, 100);
  628. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  629. //* Execute SQL statement */
  630. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  631. if( rc != SQLITE_OK )
  632. {
  633. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  634. }
  635. }
  636. int getCurrentYear()
  637. {
  638. int result = 0;
  639. time_t CurrentTime;
  640. struct tm *tm;
  641. CurrentTime = time(NULL);
  642. tm=localtime(&CurrentTime);
  643. result = (tm->tm_year + 1900);
  644. return result;
  645. }
  646. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  647. {
  648. int result = PASS;
  649. char* errMsg = NULL;
  650. char sqlStr[8192];
  651. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  652. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  653. {
  654. result = FAIL;
  655. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  656. }
  657. 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));
  658. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  659. {
  660. result = FAIL;
  661. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  662. }
  663. return result;
  664. }
  665. //==========================================
  666. // Check time passed since today
  667. //==========================================
  668. long long DiffTimebWithNow(struct timeb ST)
  669. {
  670. //return milli-second
  671. struct timeb ET;
  672. long long StartTime,StopTime;
  673. ftime(&ET);
  674. StartTime=(long long)ST.time;
  675. StopTime=(long long)ET.time;
  676. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  677. }
  678. int getTimePassSinceToday(uint8_t gun_index)
  679. {
  680. int result = -1;
  681. static time_t lastTime[4];
  682. time_t t;
  683. struct tm *tmStartToday;
  684. struct timeb tbStartToday;
  685. t=time(NULL);
  686. if(difftime(t, lastTime[gun_index])>0)
  687. {
  688. tmStartToday=localtime(&t);
  689. tmStartToday->tm_hour = 0;
  690. tmStartToday->tm_min = 0;
  691. tmStartToday->tm_sec = 0;
  692. tbStartToday.time = mktime(tmStartToday);
  693. tbStartToday.millitm = 0;
  694. result = DiffTimebWithNow(tbStartToday)/1000;
  695. lastTime[gun_index] = t;
  696. }
  697. return result;
  698. }
  699. void getNowDatetime(uint8_t *data)
  700. {
  701. time_t t = time(NULL);
  702. struct tm tm = *localtime(&t);
  703. 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);
  704. }
  705. int syncDateTimeRTC(uint8_t *data)
  706. {
  707. struct ParsingResult
  708. {
  709. int result;
  710. int scanedElement;
  711. int year;
  712. int month;
  713. int mday;
  714. int hour;
  715. int min;
  716. int sec;
  717. int tz_hour;
  718. int tz_min;
  719. float minSec;
  720. }result;
  721. struct tm tmOrg;
  722. struct tm *tmTarget;
  723. struct timeb tbTarget;
  724. char buf[128];
  725. memset(&result, 0x00, sizeof(struct ParsingResult));
  726. result.result = PASS;
  727. if(strstr((char*)data, ".") != NULL)
  728. {
  729. // Original data with mini second
  730. if(strstr((char*)data, "Z") != NULL)
  731. {
  732. // Original data with Z
  733. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  734. &result.year,
  735. &result.month,
  736. &result.mday,
  737. &result.hour,
  738. &result.min,
  739. &result.sec,
  740. &result.minSec);
  741. }
  742. else
  743. {
  744. // Original data without Z
  745. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  746. &result.year,
  747. &result.month,
  748. &result.mday,
  749. &result.hour,
  750. &result.min,
  751. &result.sec,
  752. &result.minSec,
  753. &result.tz_hour,
  754. &result.tz_min);
  755. }
  756. }
  757. else
  758. {
  759. // Original data without mini second
  760. if(strstr((char*)data, "Z") != NULL)
  761. {
  762. // Original data with Z
  763. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  764. &result.year,
  765. &result.month,
  766. &result.mday,
  767. &result.hour,
  768. &result.min,
  769. &result.sec);
  770. }
  771. else
  772. {
  773. // Original data without Z
  774. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  775. &result.year,
  776. &result.month,
  777. &result.mday,
  778. &result.hour,
  779. &result.min,
  780. &result.sec,
  781. &result.tz_hour,
  782. &result.tz_min);
  783. }
  784. }
  785. tmOrg.tm_year = result.year - 1900;
  786. tmOrg.tm_mon = result.month - 1;
  787. tmOrg.tm_mday = result.mday;
  788. tmOrg.tm_hour = result.hour;
  789. tmOrg.tm_min = result.min;
  790. tmOrg.tm_sec = result.sec;
  791. tmOrg.tm_gmtoff = 0;
  792. tbTarget.time = mktime(&tmOrg);
  793. tbTarget.timezone = 0;
  794. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  795. tmTarget = gmtime(&tbTarget.time);
  796. 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);
  797. //DEBUG_INFO(" org date time: %s\n", data);
  798. //DEBUG_INFO("parse date time: %s\n", buf);
  799. system(buf);
  800. system("/sbin/hwclock -w --systohc");
  801. if(result.scanedElement < 6)
  802. result.result = FAIL;
  803. return result.result;
  804. }
  805. //==========================================
  806. // GetCompositeSchedule logic related function
  807. //==========================================
  808. int DiffTimebSec(struct timeb ST, struct timeb ET)
  809. {
  810. //return milli-second
  811. unsigned int StartTime,StopTime;
  812. StartTime=(unsigned int)ST.time;
  813. StopTime=(unsigned int)ET.time;
  814. return (StopTime-StartTime);
  815. }
  816. int DiffTimebWithNowSec(struct timeb ST)
  817. {
  818. //return milli-second
  819. struct timeb ET;
  820. unsigned int StartTime,StopTime;
  821. ftime(&ET);
  822. StartTime=(unsigned int)ST.time;
  823. StopTime=(unsigned int)ET.time;
  824. return (StopTime-StartTime);
  825. }
  826. int getStartStop(uint8_t *start, uint8_t *stop)
  827. {
  828. int result = -1;
  829. struct tm tmStart;
  830. struct timeb tbStart;
  831. struct tm tmStop;
  832. struct timeb tbStop;
  833. 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) &&
  834. (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))
  835. {
  836. //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);
  837. //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);
  838. tmStart.tm_year -= 1900;
  839. tmStart.tm_mon -= 1;
  840. tbStart.time = mktime(&tmStart);
  841. tbStart.millitm = 0;
  842. tmStop.tm_year -= 1900;
  843. tmStop.tm_mon -= 1;
  844. tbStop.time = mktime(&tmStop);
  845. tbStop.millitm = 0;
  846. result = DiffTimebSec(tbStart, tbStop);
  847. //DEBUG_INFO("getStartStop(): %d\n", result);
  848. }
  849. else
  850. {
  851. DEBUG_WARN("Start or stop date parsing error.\r\n");
  852. }
  853. return result;
  854. }
  855. int isOvertNow(uint8_t *start)
  856. {
  857. int result = NO;
  858. struct tm tmStart;
  859. struct timeb tbStart;
  860. 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))
  861. {
  862. //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);
  863. tmStart.tm_year -= 1900;
  864. tmStart.tm_mon -= 1;
  865. tbStart.time = mktime(&tmStart);
  866. tbStart.millitm = 0;
  867. if(DiffTimebWithNowSec(tbStart) <= 0)
  868. result = NO;
  869. else
  870. result = YES;
  871. }
  872. else
  873. {
  874. DEBUG_WARN("Start date parsing error.\n");
  875. }
  876. return result;
  877. }
  878. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  879. {
  880. int result = -1;
  881. struct tm tmStart;
  882. struct timeb tbStart;
  883. struct tm tmStop;
  884. struct timeb tbStop;
  885. 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) &&
  886. (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))
  887. {
  888. tmStart.tm_year -= 1900;
  889. tmStart.tm_mon -= 1;
  890. tbStart.time = mktime(&tmStart);
  891. tbStart.millitm = 0;
  892. tmStop.tm_year -= 1900;
  893. tmStop.tm_mon -= 1;
  894. tbStop.time = mktime(&tmStop);
  895. tbStop.millitm = 0;
  896. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  897. }
  898. return result;
  899. }
  900. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  901. {
  902. FILE *fp;
  903. char profileFileName[128];
  904. char *line = NULL;
  905. size_t len = 0;
  906. time_t CurrentTime;
  907. struct tm *tmComposite;
  908. struct StructChargingProfile maxProfile;
  909. struct StructChargingProfile defaultTxProfile;
  910. struct StructChargingProfile txProfile;
  911. struct StructChargingSchedulePeriod tmpPeriod;
  912. uint8_t limitMax=0;
  913. uint8_t limitDef=0;
  914. uint8_t limitTx=0;
  915. int compositePeriodIdx = 0;
  916. CurrentTime = time(NULL);
  917. tmComposite=localtime(&CurrentTime);
  918. 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);
  919. if(isUnitA)
  920. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  921. else
  922. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  923. compositeProfile->ChargingSchedule.Duration = durationReq;
  924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  925. {
  926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  929. }
  930. compositeProfile->ChargingProfileId = 0;
  931. compositeProfile->StackLevel = 99 ;
  932. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  933. maxProfile.ChargingProfileId = -1;
  934. defaultTxProfile.ChargingProfileId = -1;
  935. txProfile.ChargingProfileId = -1;
  936. maxProfile.ChargingSchedule.Duration = -1;
  937. defaultTxProfile.ChargingSchedule.Duration = -1;
  938. txProfile.ChargingSchedule.Duration = -1;
  939. system("rm -f /tmp/*.json");
  940. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  941. /*
  942. * Search valid charging profile
  943. */
  944. //DEBUG_INFO("====================================\n");
  945. // Search tx profile
  946. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  947. if((access(profileFileName, F_OK))!=-1)
  948. {
  949. fp = fopen(profileFileName, "r");
  950. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  951. {
  952. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  953. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  955. }
  956. txProfile.ChargingProfileId = -1;
  957. txProfile.StackLevel = -1;
  958. while(getline(&line, &len, fp) != -1)
  959. {
  960. json_object *obj = NULL;
  961. obj = json_tokener_parse(line);
  962. if(is_error(obj))
  963. {
  964. DEBUG_ERROR("Parse txProfile from file error.\n");
  965. }
  966. else
  967. {
  968. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  969. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  970. )
  971. {
  972. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  973. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  974. )
  975. {
  976. struct tm tmFrom, tmTo;
  977. struct timeb tbFrom, tbTo;
  978. 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) &&
  979. (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))
  980. {
  981. tmFrom.tm_year -= 1900;
  982. tmFrom.tm_mon -= 1;
  983. tbFrom.time = mktime(&tmFrom);
  984. tmTo.tm_year -= 1900;
  985. tmTo.tm_mon -= 1;
  986. tbTo.time = mktime(&tmTo);
  987. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  988. {
  989. if(txProfile.ChargingProfileId == -1)
  990. DEBUG_INFO("TxProfile found.\n");
  991. else
  992. DEBUG_INFO("TxProfile updated.\n");
  993. // Required item
  994. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  995. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  996. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  997. if(isUnitA)
  998. {
  999. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1000. 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++)
  1001. {
  1002. 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"));
  1003. 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?
  1004. 3:
  1005. 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")));
  1006. 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")));
  1007. }
  1008. }
  1009. else
  1010. {
  1011. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1012. 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++)
  1013. {
  1014. 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"));
  1015. 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?
  1016. 3:
  1017. 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")));
  1018. 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));
  1019. }
  1020. }
  1021. // Optional item
  1022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1023. {
  1024. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1025. }
  1026. else
  1027. {
  1028. sprintf((char*)txProfile.ValidFrom, " ");
  1029. }
  1030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1031. {
  1032. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1033. }
  1034. else
  1035. {
  1036. sprintf((char*)txProfile.ValidTo, " ");
  1037. }
  1038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1039. {
  1040. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1041. }
  1042. else
  1043. {
  1044. sprintf((char*)txProfile.RecurrencyKind, " ");
  1045. }
  1046. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1047. {
  1048. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1049. }
  1050. else
  1051. {
  1052. txProfile.TransactionId = -1;
  1053. }
  1054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1055. {
  1056. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1057. }
  1058. else
  1059. {
  1060. txProfile.ChargingSchedule.Duration = 86400;
  1061. }
  1062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1063. {
  1064. 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")));
  1065. }
  1066. else
  1067. {
  1068. 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));
  1069. }
  1070. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1071. {
  1072. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1073. }
  1074. else
  1075. {
  1076. txProfile.ChargingSchedule.MinChargingRate = -1;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. else
  1082. {
  1083. if(txProfile.ChargingProfileId == -1)
  1084. DEBUG_INFO("TxProfile found.\n");
  1085. else
  1086. DEBUG_INFO("TxProfile updated.\n");
  1087. // Required item
  1088. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1089. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1090. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1091. if(isUnitA)
  1092. {
  1093. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1094. 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++)
  1095. {
  1096. 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"));
  1097. 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?
  1098. 3:
  1099. 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")));
  1100. 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")));
  1101. }
  1102. }
  1103. else
  1104. {
  1105. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1106. 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++)
  1107. {
  1108. 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"));
  1109. 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?
  1110. 3:
  1111. 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")));
  1112. 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));
  1113. }
  1114. }
  1115. // Optional item
  1116. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1117. {
  1118. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1119. }
  1120. else
  1121. {
  1122. sprintf((char*)txProfile.ValidFrom, " ");
  1123. }
  1124. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1125. {
  1126. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1127. }
  1128. else
  1129. {
  1130. sprintf((char*)txProfile.ValidTo, " ");
  1131. }
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1133. {
  1134. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)txProfile.RecurrencyKind, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1141. {
  1142. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1143. }
  1144. else
  1145. {
  1146. txProfile.TransactionId = -1;
  1147. }
  1148. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1149. {
  1150. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1151. }
  1152. else
  1153. {
  1154. txProfile.ChargingSchedule.Duration = 86400;
  1155. }
  1156. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1157. {
  1158. 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")));
  1159. }
  1160. else
  1161. {
  1162. 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));
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1165. {
  1166. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1167. }
  1168. else
  1169. {
  1170. txProfile.ChargingSchedule.MinChargingRate = -1;
  1171. }
  1172. }
  1173. }
  1174. }
  1175. json_object_put(obj);
  1176. }
  1177. fclose(fp);
  1178. /*
  1179. if(txProfile.ChargingProfileId != -1)
  1180. {
  1181. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1182. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1183. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1184. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1185. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1186. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1187. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1188. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1189. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1190. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1191. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1192. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1193. {
  1194. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1195. {
  1196. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1197. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1198. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1199. }
  1200. }
  1201. }
  1202. else
  1203. DEBUG_INFO("TxProfile not found.\n");*/
  1204. }
  1205. // Search default tx profile
  1206. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1207. if((access(profileFileName, F_OK))==-1)
  1208. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1209. if((access(profileFileName, F_OK))!=-1)
  1210. {
  1211. fp = fopen(profileFileName, "r");
  1212. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1213. {
  1214. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1215. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1217. }
  1218. defaultTxProfile.ChargingProfileId = -1;
  1219. defaultTxProfile.StackLevel = -1;
  1220. while(getline(&line, &len, fp) != -1)
  1221. {
  1222. json_object *obj = NULL;
  1223. obj = json_tokener_parse(line);
  1224. if(is_error(obj))
  1225. {
  1226. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1227. }
  1228. else
  1229. {
  1230. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1231. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1232. )
  1233. {
  1234. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1235. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1236. )
  1237. {
  1238. struct tm tmFrom, tmTo;
  1239. struct timeb tbFrom, tbTo;
  1240. 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) &&
  1241. (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))
  1242. {
  1243. tmFrom.tm_year -= 1900;
  1244. tmFrom.tm_mon -= 1;
  1245. tbFrom.time = mktime(&tmFrom);
  1246. tmTo.tm_year -= 1900;
  1247. tmTo.tm_mon -= 1;
  1248. tbTo.time = mktime(&tmTo);
  1249. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1250. {
  1251. if(defaultTxProfile.ChargingProfileId == -1)
  1252. DEBUG_INFO("TxDefaultProfile found.\n");
  1253. else
  1254. DEBUG_INFO("TxDefaultProfile updated.\n");
  1255. // Required item
  1256. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1257. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1258. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1259. if(isUnitA)
  1260. {
  1261. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1262. 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++)
  1263. {
  1264. 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"));
  1265. 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?
  1266. 3:
  1267. 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")));
  1268. 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")));
  1269. }
  1270. }
  1271. else
  1272. {
  1273. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1274. 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++)
  1275. {
  1276. 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"));
  1277. 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?
  1278. 3:
  1279. 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")));
  1280. 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));
  1281. }
  1282. }
  1283. // Optional item
  1284. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1285. {
  1286. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1287. }
  1288. else
  1289. {
  1290. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1291. }
  1292. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1293. {
  1294. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1295. }
  1296. else
  1297. {
  1298. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1299. }
  1300. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1301. {
  1302. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1303. }
  1304. else
  1305. {
  1306. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1307. }
  1308. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1309. {
  1310. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1311. }
  1312. else
  1313. {
  1314. defaultTxProfile.TransactionId = -1;
  1315. }
  1316. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1317. {
  1318. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1319. }
  1320. else
  1321. {
  1322. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1323. }
  1324. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1325. {
  1326. 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")));
  1327. }
  1328. else
  1329. {
  1330. 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));
  1331. }
  1332. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1333. {
  1334. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1335. }
  1336. else
  1337. {
  1338. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1339. }
  1340. }
  1341. }
  1342. }
  1343. else
  1344. {
  1345. if(defaultTxProfile.ChargingProfileId == -1)
  1346. DEBUG_INFO("TxDefaultProfile found.\n");
  1347. else
  1348. DEBUG_INFO("TxDefaultProfile updated.\n");
  1349. // Required item
  1350. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1351. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1352. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1353. if(isUnitA)
  1354. {
  1355. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1356. 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++)
  1357. {
  1358. 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"));
  1359. 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?
  1360. 3:
  1361. 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")));
  1362. 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")));
  1363. }
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1368. 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++)
  1369. {
  1370. 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"));
  1371. 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?
  1372. 3:
  1373. 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")));
  1374. 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));
  1375. }
  1376. }
  1377. // Optional item
  1378. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1379. {
  1380. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1381. }
  1382. else
  1383. {
  1384. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1385. }
  1386. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1387. {
  1388. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1389. }
  1390. else
  1391. {
  1392. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1393. }
  1394. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1395. {
  1396. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1397. }
  1398. else
  1399. {
  1400. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1401. }
  1402. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1403. {
  1404. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1405. }
  1406. else
  1407. {
  1408. defaultTxProfile.TransactionId = -1;
  1409. }
  1410. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1411. {
  1412. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1413. }
  1414. else
  1415. {
  1416. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1417. }
  1418. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1419. {
  1420. 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")));
  1421. }
  1422. else
  1423. {
  1424. 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));
  1425. }
  1426. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1427. {
  1428. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1429. }
  1430. else
  1431. {
  1432. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1433. }
  1434. }
  1435. }
  1436. }
  1437. json_object_put(obj);
  1438. }
  1439. fclose(fp);
  1440. /*
  1441. if(defaultTxProfile.ChargingProfileId != -1)
  1442. {
  1443. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1444. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1445. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1446. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1447. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1448. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1449. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1450. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1451. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1452. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1453. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1455. {
  1456. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1457. {
  1458. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1459. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1460. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1461. }
  1462. }
  1463. }
  1464. else
  1465. DEBUG_INFO("TxDefaultProfile not found.\n");
  1466. DEBUG_INFO("------------------------------------\n");*/
  1467. }
  1468. // Search max profile
  1469. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1470. if((access(profileFileName, F_OK))!=-1)
  1471. {
  1472. fp = fopen(profileFileName, "r");
  1473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1474. {
  1475. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1478. }
  1479. maxProfile.ChargingProfileId = -1;
  1480. maxProfile.StackLevel = -1;
  1481. while(getline(&line, &len, fp) != -1)
  1482. {
  1483. json_object *obj = NULL;
  1484. obj = json_tokener_parse(line);
  1485. if(is_error(obj))
  1486. {
  1487. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1488. }
  1489. else
  1490. {
  1491. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1492. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1493. )
  1494. {
  1495. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1496. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1497. )
  1498. {
  1499. struct tm tmFrom, tmTo;
  1500. struct timeb tbFrom, tbTo;
  1501. 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) &&
  1502. (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))
  1503. {
  1504. tmFrom.tm_year -= 1900;
  1505. tmFrom.tm_mon -= 1;
  1506. tbFrom.time = mktime(&tmFrom);
  1507. tmTo.tm_year -= 1900;
  1508. tmTo.tm_mon -= 1;
  1509. tbTo.time = mktime(&tmTo);
  1510. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1511. {
  1512. if(maxProfile.ChargingProfileId == -1)
  1513. DEBUG_INFO("MaxProfile found.\n");
  1514. else
  1515. DEBUG_INFO("MaxProfile updated.\n");
  1516. // Required item
  1517. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1518. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1519. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1520. if(isUnitA)
  1521. {
  1522. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1523. 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++)
  1524. {
  1525. 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"));
  1526. 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?
  1527. 3:
  1528. 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")));
  1529. 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")));
  1530. }
  1531. }
  1532. else
  1533. {
  1534. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1535. 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++)
  1536. {
  1537. 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"));
  1538. 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?
  1539. 3:
  1540. 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")));
  1541. 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));
  1542. }
  1543. }
  1544. // Optional item
  1545. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1546. {
  1547. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1548. }
  1549. else
  1550. {
  1551. sprintf((char*)maxProfile.ValidFrom, " ");
  1552. }
  1553. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1554. {
  1555. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1556. }
  1557. else
  1558. {
  1559. sprintf((char*)maxProfile.ValidTo, " ");
  1560. }
  1561. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1562. {
  1563. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1564. }
  1565. else
  1566. {
  1567. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1568. }
  1569. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1570. {
  1571. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1572. }
  1573. else
  1574. {
  1575. maxProfile.TransactionId = -1;
  1576. }
  1577. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1578. {
  1579. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1580. }
  1581. else
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = 86400;
  1584. }
  1585. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1586. {
  1587. 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")));
  1588. }
  1589. else
  1590. {
  1591. 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));
  1592. }
  1593. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1594. {
  1595. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1596. }
  1597. else
  1598. {
  1599. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1600. }
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. if(maxProfile.ChargingProfileId == -1)
  1607. DEBUG_INFO("MaxProfile found.\n");
  1608. else
  1609. DEBUG_INFO("MaxProfile updated.\n");
  1610. // Required item
  1611. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1612. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1613. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1614. if(isUnitA)
  1615. {
  1616. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1617. 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++)
  1618. {
  1619. 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"));
  1620. 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?
  1621. 3:
  1622. 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")));
  1623. 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")));
  1624. }
  1625. }
  1626. else
  1627. {
  1628. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1629. 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++)
  1630. {
  1631. 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"));
  1632. 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?
  1633. 3:
  1634. 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")));
  1635. 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));
  1636. }
  1637. }
  1638. // Optional item
  1639. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1640. {
  1641. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1642. }
  1643. else
  1644. {
  1645. sprintf((char*)maxProfile.ValidFrom, " ");
  1646. }
  1647. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1648. {
  1649. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1650. }
  1651. else
  1652. {
  1653. sprintf((char*)maxProfile.ValidTo, " ");
  1654. }
  1655. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1656. {
  1657. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1658. }
  1659. else
  1660. {
  1661. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1662. }
  1663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1664. {
  1665. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1666. }
  1667. else
  1668. {
  1669. maxProfile.TransactionId = -1;
  1670. }
  1671. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1672. {
  1673. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1674. }
  1675. else
  1676. {
  1677. maxProfile.ChargingSchedule.Duration = 86400;
  1678. }
  1679. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1680. {
  1681. 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")));
  1682. }
  1683. else
  1684. {
  1685. 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));
  1686. }
  1687. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1688. {
  1689. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1690. }
  1691. else
  1692. {
  1693. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1694. }
  1695. }
  1696. }
  1697. }
  1698. json_object_put(obj);
  1699. }
  1700. fclose(fp);
  1701. /*
  1702. if(maxProfile.ChargingProfileId !=-1)
  1703. {
  1704. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1705. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1706. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1707. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1708. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1709. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1710. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1711. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1712. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1713. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1714. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1715. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1716. {
  1717. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1718. {
  1719. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1720. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1721. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1722. }
  1723. }
  1724. }
  1725. else
  1726. DEBUG_INFO("MaxProfile not found.\n");
  1727. DEBUG_INFO("------------------------------------\n");*/
  1728. }
  1729. /*
  1730. * Align found profile start schedule & periods
  1731. */
  1732. //DEBUG_INFO("====================================\n");
  1733. /*
  1734. // For local test usage, force modify found profile start schedule info
  1735. 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);
  1736. 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);
  1737. 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);
  1738. */
  1739. if(txProfile.ChargingProfileId != -1)
  1740. {
  1741. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1742. {
  1743. if(txProfile.ChargingSchedule.Duration != -1)
  1744. {
  1745. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1746. 0:
  1747. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1748. }
  1749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1750. {
  1751. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1752. {
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1754. 0:
  1755. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1756. if(idxPeriod > 0)
  1757. {
  1758. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1759. {
  1760. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1767. {
  1768. if(txProfile.ChargingSchedule.Duration != -1)
  1769. {
  1770. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1771. 0:
  1772. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1773. }
  1774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1775. {
  1776. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1777. {
  1778. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1779. 0:
  1780. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1781. if(idxPeriod > 0)
  1782. {
  1783. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1784. {
  1785. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. }
  1791. else
  1792. {
  1793. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1794. {
  1795. if(txProfile.ChargingSchedule.Duration != -1)
  1796. {
  1797. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1798. 0:
  1799. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1800. }
  1801. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1802. {
  1803. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1804. {
  1805. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1806. 0:
  1807. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1808. if(idxPeriod > 0)
  1809. {
  1810. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1811. {
  1812. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. else
  1819. {
  1820. if(txProfile.ChargingSchedule.Duration != -1)
  1821. {
  1822. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1823. 0:
  1824. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1825. }
  1826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1827. {
  1828. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1829. {
  1830. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1831. 0:
  1832. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1833. if(idxPeriod > 0)
  1834. {
  1835. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1836. {
  1837. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. /*
  1845. DEBUG_INFO("txProfile after align.\n");
  1846. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1847. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1848. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1849. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1850. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1851. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1852. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1853. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1854. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1855. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1856. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1857. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1858. {
  1859. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1860. {
  1861. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1862. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1863. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1864. }
  1865. }*/
  1866. }
  1867. if(defaultTxProfile.ChargingProfileId != -1)
  1868. {
  1869. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1870. {
  1871. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1874. 0:
  1875. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1876. }
  1877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1878. {
  1879. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1880. {
  1881. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1882. 0:
  1883. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1884. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1885. {
  1886. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1887. }
  1888. if(idxPeriod > 0)
  1889. {
  1890. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1891. {
  1892. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1893. }
  1894. }
  1895. }
  1896. }
  1897. }
  1898. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1899. {
  1900. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1903. 0:
  1904. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1905. }
  1906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1907. {
  1908. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1909. {
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1911. 0:
  1912. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1913. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1914. {
  1915. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1916. }
  1917. if(idxPeriod > 0)
  1918. {
  1919. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1920. {
  1921. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. else
  1928. {
  1929. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1930. {
  1931. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1932. {
  1933. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1934. 0:
  1935. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1936. }
  1937. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1938. {
  1939. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1940. {
  1941. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1942. 0:
  1943. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1944. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1945. {
  1946. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1947. }
  1948. if(idxPeriod > 0)
  1949. {
  1950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1951. {
  1952. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. else
  1959. {
  1960. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1961. {
  1962. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1963. 0:
  1964. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1965. }
  1966. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1967. {
  1968. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1969. {
  1970. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1971. 0:
  1972. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1973. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1974. {
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1976. }
  1977. if(idxPeriod > 0)
  1978. {
  1979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1980. {
  1981. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. /*
  1989. DEBUG_INFO("defaultTxProfile after align.\n");
  1990. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1991. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1992. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1993. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1994. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1995. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1996. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1997. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1998. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1999. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2000. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2004. {
  2005. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2006. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2007. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2008. }
  2009. }
  2010. DEBUG_INFO("------------------------------------\n");*/
  2011. }
  2012. if(maxProfile.ChargingProfileId != -1)
  2013. {
  2014. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2015. {
  2016. if(maxProfile.ChargingSchedule.Duration != -1)
  2017. {
  2018. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2019. 0:
  2020. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2021. }
  2022. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2023. {
  2024. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2025. {
  2026. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2027. 0:
  2028. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2029. if(idxPeriod > 0)
  2030. {
  2031. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2032. {
  2033. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2040. {
  2041. if(maxProfile.ChargingSchedule.Duration != -1)
  2042. {
  2043. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2044. 0:
  2045. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2046. }
  2047. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2048. {
  2049. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2050. {
  2051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2052. 0:
  2053. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2054. if(idxPeriod > 0)
  2055. {
  2056. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2057. {
  2058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. else
  2065. {
  2066. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2067. {
  2068. if(maxProfile.ChargingSchedule.Duration != -1)
  2069. {
  2070. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2071. 0:
  2072. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2073. }
  2074. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2075. {
  2076. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2077. {
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2079. 0:
  2080. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2081. if(idxPeriod > 0)
  2082. {
  2083. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2084. {
  2085. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2086. }
  2087. }
  2088. }
  2089. }
  2090. }
  2091. else
  2092. {
  2093. if(maxProfile.ChargingSchedule.Duration != -1)
  2094. {
  2095. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2096. 0:
  2097. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2098. }
  2099. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2100. {
  2101. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2102. {
  2103. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2104. 0:
  2105. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2106. if(idxPeriod > 0)
  2107. {
  2108. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2109. {
  2110. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2111. }
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. /*
  2118. DEBUG_INFO("MaxProfile after align.\n");
  2119. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2120. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2121. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2122. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2123. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2124. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2125. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2126. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2127. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2128. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2129. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2130. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2131. {
  2132. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2133. {
  2134. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2135. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2136. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2137. }
  2138. }
  2139. DEBUG_INFO("------------------------------------\n");*/
  2140. }
  2141. /*
  2142. * Merge to conposite schedule
  2143. */
  2144. //DEBUG_INFO("====================================\n");
  2145. // Find each profile period quantity
  2146. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2147. {
  2148. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2149. limitMax = idx+1;
  2150. }
  2151. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2152. {
  2153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2154. limitDef = idx+1;
  2155. }
  2156. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2157. {
  2158. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2159. limitTx = idx+1;
  2160. }
  2161. // TxProfile found, composite schedule based on it
  2162. if(txProfile.ChargingProfileId != -1)
  2163. {
  2164. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2165. {
  2166. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2167. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2168. (txProfile.ChargingSchedule.Duration > 0))
  2169. {
  2170. if(maxProfile.ChargingProfileId != -1)
  2171. {
  2172. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2173. {
  2174. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2175. {
  2176. if((maxProfile.ChargingSchedule.Duration > 0))
  2177. {
  2178. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2179. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2180. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2181. }
  2182. else
  2183. {
  2184. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2185. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2186. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2187. }
  2188. }
  2189. if(idxMaxPeriod == (limitMax-1))
  2190. {
  2191. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2192. {
  2193. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2194. {
  2195. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2196. compositePeriodIdx++;
  2197. }
  2198. else
  2199. {
  2200. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. else
  2207. {
  2208. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2209. {
  2210. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2211. compositePeriodIdx++;
  2212. }
  2213. else
  2214. {
  2215. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2216. }
  2217. }
  2218. }
  2219. if(idxTxPeriod == (limitTx-1))
  2220. {
  2221. if(defaultTxProfile.ChargingProfileId != -1)
  2222. {
  2223. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2224. {
  2225. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2226. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2227. (defaultTxProfile.ChargingSchedule.Duration>0))
  2228. {
  2229. if(maxProfile.ChargingProfileId != -1)
  2230. {
  2231. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2232. {
  2233. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2234. {
  2235. if((maxProfile.ChargingSchedule.Duration > 0))
  2236. {
  2237. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2238. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2239. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2240. }
  2241. else
  2242. {
  2243. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2244. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2245. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2246. }
  2247. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2248. {
  2249. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2250. {
  2251. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2252. compositePeriodIdx++;
  2253. }
  2254. else
  2255. {
  2256. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2257. }
  2258. }
  2259. // Delete duplicate period
  2260. if(compositePeriodIdx > 1)
  2261. {
  2262. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2263. {
  2264. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2265. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2266. compositePeriodIdx -= 1;
  2267. }
  2268. }
  2269. }
  2270. else
  2271. break;
  2272. }
  2273. }
  2274. else
  2275. {
  2276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2277. {
  2278. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2279. compositePeriodIdx++;
  2280. }
  2281. else
  2282. {
  2283. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2293. else if(defaultTxProfile.ChargingProfileId != -1)
  2294. {
  2295. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2296. {
  2297. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2298. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2299. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2300. {
  2301. if(maxProfile.ChargingProfileId != -1)
  2302. {
  2303. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2304. {
  2305. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2306. {
  2307. if((maxProfile.ChargingSchedule.Duration > 0))
  2308. {
  2309. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2310. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2311. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2312. }
  2313. else
  2314. {
  2315. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2316. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2317. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2318. }
  2319. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2320. {
  2321. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2322. {
  2323. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2324. compositePeriodIdx++;
  2325. }
  2326. else
  2327. {
  2328. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2329. }
  2330. }
  2331. // Delete duplicate period
  2332. if(compositePeriodIdx > 1)
  2333. {
  2334. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2335. {
  2336. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2338. compositePeriodIdx -= 1;
  2339. }
  2340. }
  2341. }
  2342. else
  2343. break;
  2344. }
  2345. }
  2346. else
  2347. {
  2348. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2349. {
  2350. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2351. compositePeriodIdx++;
  2352. }
  2353. else
  2354. {
  2355. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2356. }
  2357. }
  2358. }
  2359. }
  2360. }
  2361. // Fill other period by MaxProfile
  2362. if(maxProfile.ChargingProfileId != -1)
  2363. {
  2364. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2365. {
  2366. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2367. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2368. (maxProfile.ChargingSchedule.Duration > 0))
  2369. {
  2370. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2371. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2372. {
  2373. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2374. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2376. }
  2377. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2378. {
  2379. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2380. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2381. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2382. }
  2383. if(tmpPeriod.Limit != -1)
  2384. {
  2385. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2386. {
  2387. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2388. {
  2389. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2390. compositePeriodIdx++;
  2391. }
  2392. else
  2393. {
  2394. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2395. }
  2396. }
  2397. // Delete duplicate period
  2398. if(compositePeriodIdx > 1)
  2399. {
  2400. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2401. {
  2402. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2403. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2404. compositePeriodIdx -= 1;
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2412. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2413. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2414. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2415. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2416. {
  2417. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2418. {
  2419. compositeProfile->ChargingProfileId = 1;
  2420. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2421. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2422. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2423. }
  2424. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2425. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2426. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2427. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2428. }
  2429. if(line)
  2430. free(line);
  2431. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2432. }
  2433. //==========================================
  2434. // Init all share memory
  2435. //==========================================
  2436. int InitShareMemory()
  2437. {
  2438. int result = PASS;
  2439. int MeterSMId;
  2440. //creat ShmSysConfigAndInfo
  2441. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2442. {
  2443. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2444. result = FAIL;
  2445. }
  2446. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2447. {
  2448. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2449. result = FAIL;
  2450. }
  2451. else
  2452. {}
  2453. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2454. {
  2455. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2456. result = FAIL;
  2457. }
  2458. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2459. {
  2460. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2461. result = FAIL;
  2462. }
  2463. else
  2464. {}
  2465. //creat ShmPsuData
  2466. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2467. {
  2468. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2469. result = FAIL;
  2470. }
  2471. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2472. {
  2473. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2474. result = FAIL;
  2475. }
  2476. else
  2477. {}
  2478. //creat ShmOCPP16Data
  2479. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2480. {
  2481. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2482. result = FAIL;
  2483. }
  2484. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2485. {
  2486. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2487. result = FAIL;
  2488. }
  2489. else
  2490. {}
  2491. /****************************** For Initial Settings************************************************/
  2492. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2493. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2494. // allocate Configuration memory address
  2495. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2496. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2497. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2498. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2499. //offline MeterValue Interval
  2500. TempMeterValueInterval = 0;
  2501. return result;
  2502. }
  2503. int ProcessShareMemory()
  2504. {
  2505. if(InitShareMemory() == FAIL)
  2506. {
  2507. DEBUG_ERROR("InitShareMemory NG\n");
  2508. if(ShmStatusCodeData!=NULL)
  2509. {
  2510. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2511. }
  2512. sleep(5);
  2513. return FAIL;
  2514. }
  2515. return PASS;
  2516. }
  2517. void CheckSystemValue(void)
  2518. {
  2519. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2520. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2521. char filenmae[100]={0};
  2522. char str[100]={0};
  2523. int tempIndex = 0;
  2524. //===============================
  2525. // send Heartbeat
  2526. //===============================
  2527. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2528. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2529. {
  2530. clientTime.Heartbeat=time((time_t*)NULL);
  2531. if(server_sign == TRUE)
  2532. {
  2533. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2534. }
  2535. else
  2536. {
  2537. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2538. }
  2539. }
  2540. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2541. {
  2542. //parameter for test
  2543. sendHeartbeatRequest(0);
  2544. //==============================================
  2545. // Reset Waiting Time
  2546. //==============================================
  2547. HeartBeatWithNOResponse += 1;
  2548. }
  2549. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2550. {
  2551. //==========================================
  2552. // csu trigger DataTransferReq
  2553. //==========================================
  2554. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2555. {
  2556. sendDataTransferRequest(gun_index);
  2557. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2558. }
  2559. //===============================
  2560. // CSU Trigger Authorize Request
  2561. //===============================
  2562. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2563. {
  2564. sendAuthorizeRequest(0);
  2565. authorizeRetryTimes = authorizeRetryTimes + 1;
  2566. if(authorizeRetryTimes < 3)
  2567. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2568. }
  2569. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2570. {
  2571. authorizeRetryTimes = 0;
  2572. SetOcppConnStatus(FALSE);
  2573. server_sign = FALSE;
  2574. }
  2575. 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))
  2576. {
  2577. sendAuthorizeRequest(0);
  2578. }
  2579. //==============================================
  2580. // CSU Trigger Smart Charging Profilw
  2581. //==============================================
  2582. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2583. {
  2584. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2585. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2586. }
  2587. //==============================================
  2588. // Charger start transaction
  2589. //==============================================
  2590. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2591. {
  2592. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2593. sendStartTransactionRequest(gun_index);
  2594. clientTime.StartTransaction = time((time_t*)NULL);
  2595. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2596. storeTempStopTransaction(gun_index);
  2597. }
  2598. //==============================================
  2599. // Charger stop transaction
  2600. //==============================================
  2601. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2602. {
  2603. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2604. sendStopTransactionRequest(gun_index);
  2605. clientTime.StopTransaction = time((time_t*)NULL);
  2606. }
  2607. //==============================================
  2608. // Charger status report
  2609. //==============================================
  2610. //--- Check Mode Change ---//
  2611. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2612. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2613. {
  2614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2615. {
  2616. tempIndex = ((gun_index==2) ? 1: 0);
  2617. }
  2618. else
  2619. {
  2620. tempIndex = gun_index;
  2621. }
  2622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2625. {
  2626. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2627. {
  2628. // Sent unplug message for California pricing logic
  2629. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2630. {
  2631. uint8_t ts[20];
  2632. getNowDatetime(ts);
  2633. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2634. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2636. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2637. }
  2638. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2639. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2640. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2641. }
  2642. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2643. {
  2644. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2645. if((access(filenmae,F_OK))!=-1)
  2646. {
  2647. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2648. sprintf(str,"rm -f %s",filenmae);
  2649. system(str);
  2650. }
  2651. }
  2652. #if 1 // for TempStopTransaction
  2653. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2654. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2655. {
  2656. checkTempStopTransaction(gun_index);
  2657. }
  2658. #endif
  2659. }
  2660. }
  2661. }
  2662. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2663. {
  2664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2665. {
  2666. tempIndex = ((gun_index==2) ? 1: 0);
  2667. }
  2668. else
  2669. {
  2670. tempIndex = gun_index;
  2671. }
  2672. for (int index = 0; index < CCS_QUANTITY; index++)
  2673. {
  2674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2675. {
  2676. 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]*/ )
  2677. {
  2678. // Sent unplug message for California pricing logic
  2679. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2680. {
  2681. uint8_t ts[20];
  2682. getNowDatetime(ts);
  2683. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2684. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2685. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2686. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2687. }
  2688. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2689. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2690. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2691. }
  2692. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2693. {
  2694. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2695. if((access(filenmae,F_OK))!=-1)
  2696. {
  2697. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2698. sprintf(str,"rm -f %s",filenmae);
  2699. system(str);
  2700. }
  2701. }
  2702. #if 1 // for TempStopTransaction
  2703. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2704. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2705. {
  2706. checkTempStopTransaction(gun_index);
  2707. }
  2708. #endif
  2709. }
  2710. }
  2711. }
  2712. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2713. {
  2714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2715. {
  2716. tempIndex = ((gun_index==2) ? 1: 0);
  2717. }
  2718. else
  2719. {
  2720. tempIndex = gun_index;
  2721. }
  2722. for (int index = 0; index < GB_QUANTITY; index++)
  2723. {
  2724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2725. {
  2726. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2727. {
  2728. // Sent unplug message for California pricing logic
  2729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2730. {
  2731. uint8_t ts[20];
  2732. getNowDatetime(ts);
  2733. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2734. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2735. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2736. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2737. }
  2738. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2739. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2740. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2741. }
  2742. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2743. {
  2744. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2745. if((access(filenmae,F_OK))!=-1)
  2746. {
  2747. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2748. sprintf(str,"rm -f %s",filenmae);
  2749. system(str);
  2750. }
  2751. }
  2752. #if 1 // for TempStopTransaction
  2753. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2754. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2755. {
  2756. checkTempStopTransaction(gun_index);
  2757. }
  2758. #endif
  2759. }
  2760. }
  2761. }
  2762. else if(gunType[gun_index] == GUN_TYPE_DO)
  2763. {
  2764. tempIndex = gun_index;
  2765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2766. {
  2767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2768. {
  2769. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2770. {
  2771. // Sent unplug message for California pricing logic
  2772. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2773. {
  2774. uint8_t ts[20];
  2775. getNowDatetime(ts);
  2776. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2777. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2778. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2779. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2780. }
  2781. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2782. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2783. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2784. }
  2785. 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
  2786. {
  2787. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2788. if((access(filenmae,F_OK))!=-1)
  2789. {
  2790. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2791. sprintf(str,"rm -f %s",filenmae);
  2792. system(str);
  2793. }
  2794. }
  2795. #if 1 // for TempStopTransaction
  2796. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2797. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2798. {
  2799. checkTempStopTransaction(gun_index);
  2800. }
  2801. #endif
  2802. }
  2803. }
  2804. }
  2805. else
  2806. {
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2808. {
  2809. tempIndex = 2;
  2810. }
  2811. else
  2812. {
  2813. tempIndex = gun_index;
  2814. }
  2815. for (int index = 0; index < AC_QUANTITY; index++)
  2816. {
  2817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2818. {
  2819. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2820. {
  2821. // Sent unplug message for California pricing logic
  2822. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2823. {
  2824. uint8_t ts[20];
  2825. getNowDatetime(ts);
  2826. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2827. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2828. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2829. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2830. }
  2831. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2832. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2833. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2834. }
  2835. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2836. {
  2837. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2838. if((access(filenmae,F_OK))!=-1)
  2839. {
  2840. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2841. sprintf(str,"rm -f %s",filenmae);
  2842. system(str);
  2843. }
  2844. }
  2845. #if 1 // for TempStopTransaction
  2846. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2847. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2848. {
  2849. checkTempStopTransaction(gun_index);
  2850. }
  2851. #endif
  2852. }
  2853. }// END
  2854. }
  2855. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  2856. (
  2857. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  2858. )
  2859. )
  2860. {
  2861. if(SystemInitial > 0)
  2862. SystemInitial -= 1;
  2863. sendStatusNotificationRequest(gun_index);
  2864. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2865. }
  2866. //==============================================
  2867. // Meter report
  2868. //==============================================
  2869. // Trigger MeterValue
  2870. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2871. {
  2872. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2873. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2874. }
  2875. // ClockAlign MeterValue
  2876. 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))
  2877. {
  2878. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2879. {
  2880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2881. {
  2882. tempIndex = ((gun_index==2) ? 1: 0);
  2883. }
  2884. else
  2885. {
  2886. tempIndex = gun_index;
  2887. }
  2888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2889. {
  2890. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2891. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2892. {
  2893. reqClockAlignMeter[gun_index] = 1;
  2894. }
  2895. }// End for CHAdeMO
  2896. }
  2897. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2898. {
  2899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2900. {
  2901. tempIndex = ((gun_index==2) ? 1: 0);
  2902. }
  2903. else
  2904. {
  2905. tempIndex = gun_index;
  2906. }
  2907. for (int index = 0; index < CCS_QUANTITY; index++)
  2908. {
  2909. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2910. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2911. {
  2912. reqClockAlignMeter[gun_index] = 1;
  2913. }
  2914. } // End for CCS
  2915. }
  2916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2917. {
  2918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2919. {
  2920. tempIndex = ((gun_index==2) ? 1: 0);
  2921. }
  2922. else
  2923. {
  2924. tempIndex = gun_index;
  2925. }
  2926. for (int index = 0; index < GB_QUANTITY; index++)
  2927. {
  2928. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2929. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2930. {
  2931. reqClockAlignMeter[gun_index] = 1;
  2932. }
  2933. }// End for GB
  2934. }
  2935. else if(gunType[gun_index] == GUN_TYPE_DO)
  2936. {
  2937. tempIndex = gun_index;
  2938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2939. {
  2940. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2941. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2942. {
  2943. reqClockAlignMeter[gun_index] = 1;
  2944. }
  2945. }
  2946. }
  2947. else
  2948. {
  2949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2950. {
  2951. tempIndex = 2;
  2952. }
  2953. else
  2954. {
  2955. tempIndex = gun_index;
  2956. }
  2957. for (int index = 0; index < AC_QUANTITY; index++)
  2958. {
  2959. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2960. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2961. {
  2962. reqClockAlignMeter[gun_index] = 1;
  2963. }
  2964. }//End for AC
  2965. }
  2966. if(reqClockAlignMeter[gun_index] == 1)
  2967. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2968. }
  2969. // Sample period MeterValue
  2970. 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))))
  2971. {
  2972. //check Transaction active
  2973. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2974. {
  2975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2976. {
  2977. tempIndex = ((gun_index==2) ? 1: 0);
  2978. }
  2979. else
  2980. {
  2981. tempIndex = gun_index;
  2982. }
  2983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2984. {
  2985. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2986. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2987. {
  2988. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2989. {
  2990. reqSampleMeter[gun_index] = 1;
  2991. }
  2992. }
  2993. }// End for CHAdeMO
  2994. }
  2995. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2996. {
  2997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2998. {
  2999. tempIndex = ((gun_index==2) ? 1: 0);
  3000. }
  3001. else
  3002. {
  3003. tempIndex = gun_index;
  3004. }
  3005. for (int index = 0; index < CCS_QUANTITY; index++)
  3006. {
  3007. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3008. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3009. {
  3010. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3011. {
  3012. reqSampleMeter[gun_index] = 1;
  3013. }
  3014. }
  3015. } // End for CCS
  3016. }
  3017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3018. {
  3019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3020. {
  3021. tempIndex = ((gun_index==2) ? 1: 0);
  3022. }
  3023. else
  3024. {
  3025. tempIndex = gun_index;
  3026. }
  3027. for (int index = 0; index < GB_QUANTITY; index++)
  3028. {
  3029. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3030. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3031. {
  3032. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3033. {
  3034. reqSampleMeter[gun_index] = 1;
  3035. }
  3036. }
  3037. }// End for GB
  3038. }
  3039. else if(gunType[gun_index] == GUN_TYPE_DO)
  3040. {
  3041. tempIndex = gun_index;
  3042. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3043. {
  3044. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3045. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3046. {
  3047. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3048. {
  3049. reqSampleMeter[gun_index] = 1;
  3050. }
  3051. }
  3052. }
  3053. }
  3054. else
  3055. {
  3056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3057. {
  3058. tempIndex = 2;
  3059. }
  3060. else
  3061. {
  3062. tempIndex = gun_index;
  3063. }
  3064. for (int index = 0; index < AC_QUANTITY; index++)
  3065. {
  3066. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3067. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3068. {
  3069. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3070. {
  3071. reqSampleMeter[gun_index] = 1;
  3072. }
  3073. }
  3074. }//End for AC
  3075. }
  3076. if(reqSampleMeter[gun_index] == 1)
  3077. {
  3078. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3079. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3080. storeTempStopTransaction(gun_index);
  3081. }
  3082. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3083. }
  3084. //==============================================
  3085. // Check Connector reserved
  3086. //==============================================
  3087. //===============================
  3088. // Check if Reserve is expired
  3089. //===============================
  3090. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3091. {
  3092. double diff_t;
  3093. struct tm tp;
  3094. // current time
  3095. time_t t = time(NULL);
  3096. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3097. tp.tm_isdst = -1;
  3098. time_t utc = mktime(&tp);
  3099. diff_t = difftime(utc, t);
  3100. if(diff_t <= 0)
  3101. {
  3102. DEBUG_INFO("reserve expired.\n");
  3103. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3104. }
  3105. }//END OF Check if Reserve is expired
  3106. //==========================================
  3107. // csu trigger FirmwareStatusNotificationReq
  3108. //==========================================
  3109. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3110. {
  3111. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3112. }
  3113. //==========================================
  3114. // csu trigger DiagnosticsStatusNotificationReq
  3115. //==========================================
  3116. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3117. {
  3118. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3119. }
  3120. //==========================================
  3121. // csu trigger CancelReservationConf
  3122. //==========================================
  3123. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3124. {
  3125. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3126. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3127. }
  3128. //==========================================
  3129. // csu trigger ChangeAvailabilityConf
  3130. //==========================================
  3131. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3132. {
  3133. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3134. }
  3135. //==========================================
  3136. // csu trigger UnlockConnectorConf
  3137. //==========================================
  3138. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3139. {
  3140. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3141. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3142. }
  3143. //==========================================
  3144. // csu trigger ReserveNowConf
  3145. //==========================================
  3146. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3147. {
  3148. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3149. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3150. }
  3151. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3152. {
  3153. sendSignCertificateRequest();
  3154. }
  3155. }
  3156. }
  3157. //==========================================
  3158. // send request routine
  3159. //==========================================
  3160. int sendAuthorizeRequest(int gun_index)
  3161. {
  3162. mtrace();
  3163. int result = FAIL;
  3164. char message[100]={0};
  3165. char guid[37];
  3166. char tempdata[65]={0};
  3167. DEBUG_INFO("sendAuthorizeRequest...\n");
  3168. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3169. //Local Authorize
  3170. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3171. {
  3172. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3173. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3174. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3175. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3176. result = PASS;
  3177. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3178. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3179. authorizeRetryTimes = 0;
  3180. return result;
  3181. }
  3182. 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))||
  3183. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3184. {
  3185. // Query from cache
  3186. DEBUG_INFO("Authorize from cache.\n");
  3187. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3188. // Query from list
  3189. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3190. {
  3191. DEBUG_INFO("Authorize from list.\n");
  3192. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3193. }
  3194. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3195. {
  3196. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3197. {
  3198. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3199. }
  3200. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3201. {
  3202. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3203. }
  3204. if(!GetOcppConnStatus())
  3205. {
  3206. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3207. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3208. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3209. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3210. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3211. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3212. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3213. authorizeRetryTimes = 0;
  3214. return result;
  3215. }
  3216. }
  3217. else
  3218. {
  3219. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3220. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3221. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3222. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3223. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3224. else
  3225. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3226. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3227. result = PASS;
  3228. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3229. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3230. authorizeRetryTimes = 0;
  3231. return result;
  3232. }
  3233. }
  3234. //initialize struct Authorize
  3235. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3236. //get data from shared memory
  3237. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3238. random_uuid(guid);
  3239. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3240. LWS_Send(message);
  3241. sprintf(tempdata, "Authorize,%d", gun_index);
  3242. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3243. {
  3244. result = PASS;
  3245. DEBUG_INFO("Authorize mapItem pass\n");
  3246. }
  3247. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3248. return result;
  3249. }
  3250. int sendBootNotificationRequest(void)
  3251. {
  3252. mtrace();
  3253. int result = FAIL;
  3254. char message[500]={0}, payload[700]={0};
  3255. char guid[37]={0};
  3256. char tempdata[65]={0};
  3257. // Fill BootNotification fields
  3258. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3259. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3260. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3261. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3262. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3263. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3264. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3265. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3266. ShmOCPP16Data->ChargeBoxId
  3267. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3268. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3269. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3270. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3271. ,ShmOCPP16Data->BootNotification.CpIccid
  3272. ,ShmOCPP16Data->BootNotification.CpImsi);
  3273. random_uuid(guid);
  3274. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3275. LWS_Send(message);
  3276. sprintf(tempdata, "BootNotification,0");
  3277. 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*/)
  3278. {
  3279. result = PASS;
  3280. }
  3281. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3282. strcpy(queuedata,message);
  3283. return result;
  3284. }
  3285. int sendDataTransferRequest(int gun_index)
  3286. {
  3287. mtrace();
  3288. char message[1000]={0};
  3289. char guid[37]={0};
  3290. char tempdata[65]={0};
  3291. int result = FAIL;
  3292. random_uuid(guid);
  3293. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3294. MESSAGE_TYPE_CALL,
  3295. guid,
  3296. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3297. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3298. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3299. LWS_Send(message);
  3300. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3301. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3302. {
  3303. result = PASS;
  3304. DEBUG_INFO("DataTransfer mapItem pass\n");
  3305. }
  3306. return result;
  3307. }
  3308. int sendDiagnosticsStatusNotificationRequest(char *status)
  3309. {
  3310. mtrace();
  3311. int result = FAIL;
  3312. char message[110]={0};
  3313. char guid[37]={0};
  3314. char tempdata[65]={0};
  3315. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3316. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3317. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3318. random_uuid(guid);
  3319. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3320. LWS_SendNow(message);
  3321. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3322. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3323. {
  3324. result = PASS;
  3325. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3326. }
  3327. //#ifdef SystemLogMessage
  3328. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3329. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3330. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3331. //#endif
  3332. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3333. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3334. //record status
  3335. if(strcmp(status,"Idle")==0)
  3336. {
  3337. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3338. }
  3339. else if(strcmp(status,"Uploaded")==0)
  3340. {
  3341. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3342. }
  3343. else if(strcmp(status,"UploadFailed")==0)
  3344. {
  3345. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3346. }
  3347. else if(strcmp(status,"Uploading")==0)
  3348. {
  3349. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3350. }
  3351. return result;
  3352. }
  3353. int sendFirmwareStatusNotificationRequest(char *status)
  3354. {
  3355. mtrace();
  3356. int result = FAIL;
  3357. char message[110]={0};
  3358. char guid[37]={0};
  3359. char tempdata[65]={0};
  3360. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3361. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3362. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3363. random_uuid(guid);
  3364. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3365. LWS_SendNow(message);
  3366. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3367. 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*/)
  3368. {
  3369. result = PASS;
  3370. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3371. }
  3372. //#ifdef SystemLogMessage
  3373. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3374. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3375. //#endif
  3376. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3377. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3378. //record status
  3379. if(strcmp(status,"Downloaded")==0)
  3380. {
  3381. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3382. }
  3383. else if(strcmp(status,"DownloadFailed")==0)
  3384. {
  3385. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3386. }
  3387. else if(strcmp(status,"Downloading")==0)
  3388. {
  3389. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3390. }
  3391. else if(strcmp(status,"Idle")==0)
  3392. {
  3393. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3394. }
  3395. else if(strcmp(status,"InstallationFailed")==0)
  3396. {
  3397. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3398. }
  3399. else if(strcmp(status,"Installing")==0)
  3400. {
  3401. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3402. }
  3403. else if(strcmp(status,"Installed")==0)
  3404. {
  3405. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3406. }
  3407. return result;
  3408. }
  3409. int sendHeartbeatRequest(int gun_index)
  3410. {
  3411. mtrace();
  3412. int result = FAIL;
  3413. char message[80]={0};
  3414. char guid[37]={0};
  3415. char tempdata[65]={0};
  3416. random_uuid(guid);
  3417. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3418. , MESSAGE_TYPE_CALL
  3419. , guid );
  3420. LWS_Send(message);
  3421. sprintf(tempdata, "Heartbeat,%d", 0);
  3422. 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*/)
  3423. {
  3424. result = PASS;
  3425. }
  3426. return result;
  3427. }
  3428. int sendStartTransactionRequest(int gun_index)
  3429. {
  3430. mtrace();
  3431. int result = FAIL;
  3432. char message[250]={0};
  3433. char guid[37]={0};
  3434. struct timeval tmnow;
  3435. struct tm *tm;
  3436. char buf[28];//, usec_buf[6];
  3437. char tempdata[65]={0};
  3438. int tempIndex = 0;
  3439. DEBUG_INFO("sendStartTransactionRequest...\n");
  3440. gettimeofday(&tmnow, NULL);
  3441. time_t t;
  3442. t = time(NULL);
  3443. /*UTC time and date*/
  3444. tm = gmtime(&t);
  3445. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3446. #if 0 // remove temporally
  3447. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3448. strcat(buf,".");
  3449. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3450. strcat(buf,usec_buf);
  3451. #endif
  3452. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3453. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3454. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3455. // clear StartTransaction Response
  3456. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3457. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3458. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3459. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3460. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3473. {
  3474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3475. {
  3476. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3477. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3478. }
  3479. }
  3480. }
  3481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3482. {
  3483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3484. {
  3485. tempIndex = ((gun_index==2) ? 1: 0);
  3486. }
  3487. else
  3488. {
  3489. tempIndex = gun_index;
  3490. }
  3491. for (int index = 0; index < CCS_QUANTITY; index++)
  3492. {
  3493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3494. {
  3495. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3496. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3497. }
  3498. }
  3499. }
  3500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3501. {
  3502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3503. {
  3504. tempIndex = ((gun_index==2) ? 1: 0);
  3505. }
  3506. else
  3507. {
  3508. tempIndex = gun_index;
  3509. }
  3510. for (int index = 0; index < GB_QUANTITY; index++)
  3511. {
  3512. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3513. {
  3514. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3515. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3516. }
  3517. }
  3518. }
  3519. else if(gunType[gun_index] == GUN_TYPE_DO)
  3520. {
  3521. tempIndex = gun_index;
  3522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3523. {
  3524. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3525. {
  3526. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3527. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3528. }
  3529. }
  3530. }
  3531. else
  3532. {
  3533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3534. {
  3535. tempIndex = 2;
  3536. }
  3537. else
  3538. {
  3539. tempIndex = gun_index;
  3540. }
  3541. for (int index = 0; index < AC_QUANTITY; index++)
  3542. {
  3543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3544. {
  3545. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3546. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3547. }
  3548. }
  3549. }
  3550. random_uuid(guid);
  3551. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3552. {
  3553. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3554. , gun_index +1
  3555. , MESSAGE_TYPE_CALL
  3556. , guid
  3557. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3558. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3559. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3560. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3561. }
  3562. else
  3563. {
  3564. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3565. , gun_index +1
  3566. , MESSAGE_TYPE_CALL
  3567. , guid
  3568. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3569. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3570. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3571. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3572. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3573. }
  3574. #if 1
  3575. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3576. 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*/)
  3577. {
  3578. result = PASS;
  3579. }
  3580. #endif
  3581. strcpy(queuedata, message);
  3582. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3583. OCPP_insert_transaction_msg(YES, queuedata);
  3584. return result;
  3585. }
  3586. int sendStatusNotificationRequest(int gun_index)
  3587. {
  3588. mtrace();
  3589. int result = FAIL;
  3590. char message[600]={0};
  3591. char guid[37];
  3592. int currentStatus = 0;
  3593. struct timeval tmnow;
  3594. struct tm *tm;
  3595. char buf[28];//, usec_buf[6];
  3596. char tempdata[65]={0};
  3597. int tempIndex = 0;
  3598. uint8_t isStateChanged = TRUE;
  3599. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3600. gettimeofday(&tmnow, NULL);
  3601. time_t t;
  3602. t = time(NULL);
  3603. /*UTC time and date*/
  3604. tm = gmtime(&t);
  3605. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3606. #if 0 // remove temporally
  3607. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3608. strcat(buf,".");
  3609. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3610. strcat(buf,usec_buf);
  3611. #endif
  3612. printf("%s",buf);
  3613. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3614. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3615. // it's option
  3616. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3617. /*
  3618. enum _SYSTEM_STATUS
  3619. {
  3620. S_BOOTING = 0,
  3621. S_IDLE, = 1
  3622. S_AUTHORIZING, =2
  3623. S_REASSIGN_CHECK, =3
  3624. S_REASSIGN, =4
  3625. S_PRECHARGE, =5
  3626. S_PREPARING_FOR_EV, =6
  3627. S_PREPARING_FOR_EVSE, =7
  3628. S_CHARGING, =8
  3629. S_TERMINATING, =9
  3630. S_COMPLETE, =10
  3631. S_ALARM, =11
  3632. S_FAULT =12
  3633. }
  3634. */
  3635. //check Transaction active
  3636. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3637. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3638. {
  3639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3640. {
  3641. tempIndex = ((gun_index==2) ? 1: 0);
  3642. }
  3643. else
  3644. {
  3645. tempIndex = gun_index;
  3646. }
  3647. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3648. {
  3649. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3650. {
  3651. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3652. {
  3653. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3654. {
  3655. currentStatus = Preparing; //OCPP Status: Preparing
  3656. }
  3657. else
  3658. {
  3659. currentStatus = Available; //OCPP Status: Available
  3660. }
  3661. }
  3662. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3663. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3664. ) //S_PRECHARGE
  3665. {
  3666. currentStatus = Preparing; //OCPP Status: Preparing
  3667. }
  3668. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3669. {
  3670. currentStatus = Charging; //OCPP Status: Charging
  3671. }
  3672. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3673. {
  3674. currentStatus = Finishing; //OCPP Status: Finishing
  3675. }
  3676. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3677. {
  3678. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3679. }
  3680. 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
  3681. {
  3682. currentStatus = Unavailable; //OCPP Status: Unavailable
  3683. }
  3684. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3685. {
  3686. currentStatus = Faulted; //OCPP Status: Faulted
  3687. }
  3688. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3689. {
  3690. currentStatus = Reserved; //OCPP Status: Reserved
  3691. }
  3692. } //end of the same index
  3693. }//end of for CHAdeMO_QUANTITY
  3694. }
  3695. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3696. {
  3697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3698. {
  3699. tempIndex = ((gun_index==2) ? 1: 0);
  3700. }
  3701. else
  3702. {
  3703. tempIndex = gun_index;
  3704. }
  3705. for (int index = 0; index < CCS_QUANTITY; index++)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3710. {
  3711. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3712. {
  3713. currentStatus = Preparing; //OCPP Status: Preparing
  3714. }
  3715. else
  3716. {
  3717. currentStatus = Available; //OCPP Status: Available
  3718. }
  3719. }
  3720. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3721. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3722. ) //S_PRECHARGE
  3723. {
  3724. currentStatus = Preparing; //OCPP Status: Preparing
  3725. }
  3726. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3727. {
  3728. currentStatus = Charging; //OCPP Status: Charging
  3729. }
  3730. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3731. {
  3732. currentStatus = Finishing; //OCPP Status: Finishing
  3733. }
  3734. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3735. {
  3736. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3737. }
  3738. 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
  3739. {
  3740. currentStatus = Unavailable; //OCPP Status : Unavailable
  3741. }
  3742. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3743. {
  3744. currentStatus = Faulted; //OCPP Status: Faulted
  3745. }
  3746. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3747. {
  3748. currentStatus = Reserved; //OCPP Status: Reserved
  3749. }
  3750. } //end of the same index
  3751. } // end of for CCS_QUANTITY
  3752. }
  3753. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3756. {
  3757. tempIndex = ((gun_index==2) ? 1: 0);
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < GB_QUANTITY; index++)
  3764. {
  3765. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3766. {
  3767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3768. {
  3769. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3770. {
  3771. currentStatus = Preparing; //OCPP Status: Preparing
  3772. }
  3773. else
  3774. {
  3775. currentStatus = Available; //OCPP Status: Available
  3776. }
  3777. }
  3778. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3779. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3780. ) //S_PRECHARGE
  3781. {
  3782. currentStatus = Preparing; //OCPP Status: Preparing
  3783. }
  3784. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3785. {
  3786. currentStatus = Charging; //OCPP Status: Charging
  3787. }
  3788. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3789. {
  3790. currentStatus = Finishing; //OCPP Status: Finishing
  3791. }
  3792. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3793. {
  3794. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3795. }
  3796. 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
  3797. {
  3798. currentStatus = Unavailable; //OCPP Status: Unavailable
  3799. }
  3800. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3801. {
  3802. currentStatus = Faulted; //OCPP Status: Faulted
  3803. }
  3804. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3805. {
  3806. currentStatus = Reserved; //OCPP Status: Reserved
  3807. }
  3808. } //end of the same index
  3809. } // end of for GB_QUANTITY
  3810. }
  3811. else if(gunType[gun_index] == GUN_TYPE_DO)
  3812. {
  3813. tempIndex = gun_index;
  3814. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3815. {
  3816. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3817. {
  3818. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3819. {
  3820. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3821. {
  3822. currentStatus = Preparing; //OCPP Status: Preparing
  3823. }
  3824. else
  3825. {
  3826. currentStatus = Available; //OCPP Status: Available
  3827. }
  3828. }
  3829. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3830. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3831. ) //S_PRECHARGE
  3832. {
  3833. currentStatus = Preparing; //OCPP Status: Preparing
  3834. }
  3835. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3836. {
  3837. currentStatus = Charging; //OCPP Status: Charging
  3838. }
  3839. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3840. {
  3841. currentStatus = Finishing; //OCPP Status: Finishing
  3842. }
  3843. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3844. {
  3845. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3846. }
  3847. 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
  3848. {
  3849. currentStatus = Unavailable; //OCPP Status: Unavailable
  3850. }
  3851. 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
  3852. {
  3853. currentStatus = Faulted; //OCPP Status: Faulted
  3854. }
  3855. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3856. {
  3857. currentStatus = Reserved; //OCPP Status: Reserved
  3858. }
  3859. } //end of the same index
  3860. }
  3861. }
  3862. else
  3863. {
  3864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3865. {
  3866. tempIndex = 2;
  3867. }
  3868. else
  3869. {
  3870. tempIndex = gun_index;
  3871. }
  3872. for (int index = 0; index < AC_QUANTITY; index++)
  3873. {
  3874. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3875. {
  3876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3877. {
  3878. 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))
  3879. {
  3880. currentStatus = Preparing; //OCPP Status: Preparing
  3881. }
  3882. else
  3883. {
  3884. currentStatus = Available; //OCPP Status: Available
  3885. }
  3886. }
  3887. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3888. {
  3889. currentStatus = Preparing; //OCPP Status: Preparing
  3890. }
  3891. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3892. {
  3893. currentStatus = Charging; //OCPP Status: Charging
  3894. }
  3895. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3896. {
  3897. currentStatus = Finishing; //OCPP Status: Finishing
  3898. }
  3899. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3900. {
  3901. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3902. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3903. else
  3904. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3905. }
  3906. 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
  3907. {
  3908. currentStatus = Unavailable; //OCPP Status: Unavailable
  3909. }
  3910. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3911. {
  3912. currentStatus = Faulted; //OCPP Status: Faulted
  3913. }
  3914. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3915. {
  3916. currentStatus = Reserved; //OCPP Status: Reserved
  3917. }
  3918. }//end of the same index
  3919. }//end of for AC_QUANTITY
  3920. }
  3921. //it's option
  3922. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3923. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  3924. {
  3925. isStateChanged = FALSE;
  3926. }
  3927. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3928. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3929. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3930. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3931. random_uuid(guid);
  3932. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3933. , MESSAGE_TYPE_CALL
  3934. , guid
  3935. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3936. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3937. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3938. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3939. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3940. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3941. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3942. if((server_sign == TRUE) && isStateChanged)
  3943. {
  3944. LWS_Send(message);
  3945. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3946. 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*/)
  3947. {
  3948. //DEBUG_ERROR("statusNotification mapitem pass");
  3949. result = PASS;
  3950. }
  3951. }
  3952. else
  3953. {
  3954. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3955. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3956. result = PASS;
  3957. }
  3958. return result;
  3959. }
  3960. int sendStopTransactionRequest(int gun_index)
  3961. {
  3962. mtrace();
  3963. int result = FAIL;
  3964. //char message[1500]={0};
  3965. char guid[37]={0};
  3966. char tempdata[65]={0};
  3967. int tempIndex = 0;
  3968. char TempStopTransaction[256];
  3969. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3970. //int idx_sample=0;
  3971. DEBUG_INFO("sendStopTransactionRequest \n");
  3972. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3973. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3974. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3975. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3976. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3977. {
  3978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3979. {
  3980. tempIndex = ((gun_index==2) ? 1: 0);
  3981. }
  3982. else
  3983. {
  3984. tempIndex = gun_index;
  3985. }
  3986. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3987. {
  3988. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3989. {
  3990. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3991. }
  3992. }// END OF CHAdeMO_QUANTITY
  3993. }
  3994. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3997. {
  3998. tempIndex = ((gun_index==2) ? 1: 0);
  3999. }
  4000. else
  4001. {
  4002. tempIndex = gun_index;
  4003. }
  4004. for (int index = 0; index < CCS_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4007. {
  4008. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4009. }
  4010. }// END OF CCS_QUANTITY
  4011. }
  4012. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4013. {
  4014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4015. {
  4016. tempIndex = ((gun_index==2) ? 1: 0);
  4017. }
  4018. else
  4019. {
  4020. tempIndex = gun_index;
  4021. }
  4022. for (int index = 0; index < GB_QUANTITY; index++)
  4023. {
  4024. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4025. {
  4026. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4027. }
  4028. }// END OF GB_QUANTITY
  4029. }
  4030. else if(gunType[gun_index] == GUN_TYPE_DO)
  4031. {
  4032. tempIndex = gun_index;
  4033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4034. {
  4035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4036. {
  4037. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4038. }
  4039. }// END OF GB_QUANTITY
  4040. }
  4041. else
  4042. {
  4043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4044. {
  4045. tempIndex = 2;
  4046. }
  4047. else
  4048. {
  4049. tempIndex = gun_index;
  4050. }
  4051. for (int index = 0; index < AC_QUANTITY; index++)
  4052. {
  4053. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4054. {
  4055. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4056. }
  4057. }// END OF AC_QUANTITY
  4058. }
  4059. //====================================== Stop Transaction Time =====================================================
  4060. struct timeval tmnow;
  4061. struct tm *tm;
  4062. char buf[28];//, usec_buf[6];
  4063. gettimeofday(&tmnow, NULL);
  4064. time_t t;
  4065. t = time(NULL);
  4066. /*UTC time and date*/
  4067. tm = gmtime(&t);
  4068. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4070. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4071. random_uuid(guid);
  4072. /***********************************transactionData******************************************************/
  4073. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4075. //=================================
  4076. // Transaction_Begin
  4077. //=================================
  4078. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4079. {
  4080. //============================================ Energy.Active.Import.Interval ================================
  4081. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4084. 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*/]);
  4085. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4086. 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))
  4087. {
  4088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4089. }
  4090. else
  4091. {
  4092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4093. }
  4094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4096. }
  4097. //=================================
  4098. // Transaction_End
  4099. //=================================
  4100. // ================================= Current.Import L1 ===============================================
  4101. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4102. {
  4103. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4104. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4107. {
  4108. tempIndex = ((gun_index==2) ? 1: 0);
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4115. {
  4116. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4117. {
  4118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4119. }
  4120. }// End of for CHAdeMO_QUANTITY
  4121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4122. }
  4123. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < CCS_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4136. {
  4137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4138. }
  4139. }// End of for CCS_QUANTITY
  4140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4141. }
  4142. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4145. {
  4146. tempIndex = ((gun_index==2) ? 1: 0);
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < GB_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4157. }
  4158. }// End of for GB_QUANTITY
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4160. }
  4161. else if(gunType[gun_index] == GUN_TYPE_DO)
  4162. {
  4163. tempIndex = gun_index;
  4164. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4165. {
  4166. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4167. {
  4168. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4169. }
  4170. }
  4171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4172. }
  4173. else
  4174. {
  4175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4176. {
  4177. tempIndex = 2;
  4178. }
  4179. else
  4180. {
  4181. tempIndex = gun_index;
  4182. }
  4183. for (int index = 0; index < AC_QUANTITY; index++)
  4184. {
  4185. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4186. {
  4187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4188. }
  4189. }// End of for AC_QUANTITY
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4191. }
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4197. }
  4198. // ================================= Energy.Active.Import.Interval ==============================================
  4199. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4200. {
  4201. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4202. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4203. {
  4204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4205. {
  4206. tempIndex = ((gun_index==2) ? 1: 0);
  4207. }
  4208. else
  4209. {
  4210. tempIndex = gun_index;
  4211. }
  4212. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4213. {
  4214. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4215. {
  4216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4217. }
  4218. }// END OF CHAdeMO_QUANTITY
  4219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4220. }
  4221. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4222. {
  4223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4224. {
  4225. tempIndex = ((gun_index==2) ? 1: 0);
  4226. }
  4227. else
  4228. {
  4229. tempIndex = gun_index;
  4230. }
  4231. for (int index = 0; index < CCS_QUANTITY; index++)
  4232. {
  4233. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4234. {
  4235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4236. }
  4237. }// END OF CCS_QUANTITY
  4238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4239. }
  4240. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4243. {
  4244. tempIndex = ((gun_index==2) ? 1: 0);
  4245. }
  4246. else
  4247. {
  4248. tempIndex = gun_index;
  4249. }
  4250. for (int index = 0; index < GB_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4253. {
  4254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4255. }
  4256. }// END OF GB_QUANTITY
  4257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4258. }
  4259. else if(gunType[gun_index] == GUN_TYPE_DO)
  4260. {
  4261. tempIndex = gun_index;
  4262. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4263. {
  4264. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4265. {
  4266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4267. }
  4268. }
  4269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4270. }
  4271. else
  4272. {
  4273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4274. {
  4275. tempIndex = 2;
  4276. }
  4277. else
  4278. {
  4279. tempIndex = gun_index;
  4280. }
  4281. for (int index = 0; index < AC_QUANTITY; index++)
  4282. {
  4283. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4284. {
  4285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4286. }
  4287. }// END OF AC_QUANTITY
  4288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4289. }
  4290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4295. }
  4296. //=================================== Power.Active.Import ==================================================
  4297. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4298. {
  4299. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4300. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4301. {
  4302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4303. {
  4304. tempIndex = ((gun_index==2) ? 1: 0);
  4305. }
  4306. else
  4307. {
  4308. tempIndex = gun_index;
  4309. }
  4310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4311. {
  4312. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4313. {
  4314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4315. }
  4316. } // End for CHAdeMO_QUANTITY
  4317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4318. }
  4319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4320. {
  4321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4322. {
  4323. tempIndex = ((gun_index==2) ? 1: 0);
  4324. }
  4325. else
  4326. {
  4327. tempIndex = gun_index;
  4328. }
  4329. for (int index = 0; index < CCS_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4332. {
  4333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4334. }
  4335. } // END for CCS_QUANTITY
  4336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4337. }
  4338. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4341. {
  4342. tempIndex = ((gun_index==2) ? 1: 0);
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < GB_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4351. {
  4352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4353. }
  4354. }// END for GB_QUANTITY
  4355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4356. }
  4357. else if(gunType[gun_index] == GUN_TYPE_DO)
  4358. {
  4359. tempIndex = gun_index;
  4360. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4361. {
  4362. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4363. {
  4364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4365. }
  4366. }
  4367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4368. }
  4369. else
  4370. {
  4371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4372. {
  4373. tempIndex = 2;
  4374. }
  4375. else
  4376. {
  4377. tempIndex = gun_index;
  4378. }
  4379. for (int index = 0; index < AC_QUANTITY; index++)
  4380. {
  4381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4382. {
  4383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4384. }
  4385. } // END for AC_QUANTITY
  4386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4387. }
  4388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4393. }
  4394. //============================ Voltage L1 ====================================
  4395. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4396. {
  4397. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4398. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4399. {
  4400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4401. {
  4402. tempIndex = ((gun_index==2) ? 1: 0);
  4403. }
  4404. else
  4405. {
  4406. tempIndex = gun_index;
  4407. }
  4408. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4409. {
  4410. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4411. {
  4412. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4413. }
  4414. } // END OF FOR CHAdeMO_QUANTITY
  4415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4416. }
  4417. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4420. {
  4421. tempIndex = ((gun_index==2) ? 1: 0);
  4422. }
  4423. else
  4424. {
  4425. tempIndex = gun_index;
  4426. }
  4427. for (int index = 0; index < CCS_QUANTITY; index++)
  4428. {
  4429. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4430. {
  4431. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4432. }
  4433. } // END OF FOR CCS_QUANTITY
  4434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4435. }
  4436. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4437. {
  4438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4439. {
  4440. tempIndex = ((gun_index==2) ? 1: 0);
  4441. }
  4442. else
  4443. {
  4444. tempIndex = gun_index;
  4445. }
  4446. for (int index = 0; index < GB_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4449. {
  4450. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4451. }
  4452. } // END OF FOR GB_QUANTITY
  4453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4454. }
  4455. else if(gunType[gun_index] == GUN_TYPE_DO)
  4456. {
  4457. tempIndex = gun_index;
  4458. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4459. {
  4460. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4461. {
  4462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4463. }
  4464. }
  4465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4466. }
  4467. else
  4468. {
  4469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4470. {
  4471. tempIndex = 2;
  4472. }
  4473. else
  4474. {
  4475. tempIndex = gun_index;
  4476. }
  4477. for (int index = 0; index < AC_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4480. {
  4481. 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
  4482. }
  4483. } // END OF FOR AC_QUANTITY
  4484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4485. }
  4486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4491. }
  4492. //====================== End SoC ================================
  4493. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4494. {
  4495. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4496. 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))
  4497. {
  4498. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4499. {
  4500. tempIndex = ((gun_index==2) ? 1: 0);
  4501. }
  4502. else
  4503. {
  4504. tempIndex = gun_index;
  4505. }
  4506. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4507. {
  4508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4509. {
  4510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4511. {
  4512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4513. }
  4514. }
  4515. }
  4516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4517. {
  4518. for (int index = 0; index < CCS_QUANTITY; index++)
  4519. {
  4520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4521. {
  4522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4523. }
  4524. }
  4525. }
  4526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4527. {
  4528. for (int index = 0; index < GB_QUANTITY; index++)
  4529. {
  4530. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4531. {
  4532. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4533. }
  4534. }
  4535. }
  4536. else if(gunType[gun_index] == GUN_TYPE_DO)
  4537. {
  4538. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4541. {
  4542. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4543. }
  4544. }
  4545. }
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4552. } // END FOR DC CASE
  4553. }
  4554. // ================================= Current.Import L2 ===============================================
  4555. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4556. {
  4557. // AC 3 phse L2 current
  4558. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4559. {
  4560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4561. {
  4562. tempIndex = 2;
  4563. }
  4564. else
  4565. {
  4566. tempIndex = gun_index;
  4567. }
  4568. for (int index = 0; index < AC_QUANTITY; index++)
  4569. {
  4570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4571. {
  4572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4573. }
  4574. }// End of for AC_QUANTITY
  4575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4576. }
  4577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4582. }
  4583. // ================================= Current.Import L3 ===============================================
  4584. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4585. {
  4586. // AC 3 phse L3 current
  4587. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4588. {
  4589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4590. {
  4591. tempIndex = 2;
  4592. }
  4593. else
  4594. {
  4595. tempIndex = gun_index;
  4596. }
  4597. for (int index = 0; index < AC_QUANTITY; index++)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4600. {
  4601. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4602. }
  4603. }// End of for AC_QUANTITY
  4604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4605. }
  4606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4611. }
  4612. //============================ Voltage L2 ====================================
  4613. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4614. {
  4615. // AC 3 phse L2 voltage
  4616. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4617. {
  4618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4619. {
  4620. tempIndex = 2;
  4621. }
  4622. else
  4623. {
  4624. tempIndex = gun_index;
  4625. }
  4626. for (int index = 0; index < AC_QUANTITY; index++)
  4627. {
  4628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4629. {
  4630. 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
  4631. }
  4632. } // END OF FOR AC_QUANTITY
  4633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4634. }
  4635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4640. }
  4641. //============================ Voltage L3 ====================================
  4642. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4643. {
  4644. // AC 3 phse L3 voltage
  4645. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4646. {
  4647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4648. {
  4649. tempIndex = 2;
  4650. }
  4651. else
  4652. {
  4653. tempIndex = gun_index;
  4654. }
  4655. for (int index = 0; index < AC_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4658. {
  4659. 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
  4660. }
  4661. } // END OF FOR AC_QUANTITY
  4662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4669. }
  4670. //====================== Start SoC ================================
  4671. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4672. {
  4673. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4674. 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))
  4675. {
  4676. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4677. {
  4678. tempIndex = ((gun_index==2) ? 1: 0);
  4679. }
  4680. else
  4681. {
  4682. tempIndex = gun_index;
  4683. }
  4684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4685. {
  4686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4687. {
  4688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4689. {
  4690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4691. }
  4692. }
  4693. }
  4694. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4695. {
  4696. for (int index = 0; index < CCS_QUANTITY; index++)
  4697. {
  4698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4699. {
  4700. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4701. }
  4702. }
  4703. }
  4704. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4705. {
  4706. for (int index = 0; index < GB_QUANTITY; index++)
  4707. {
  4708. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4709. {
  4710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4711. }
  4712. }
  4713. }
  4714. else if(gunType[gun_index] == GUN_TYPE_DO)
  4715. {
  4716. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4717. {
  4718. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4719. {
  4720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4721. }
  4722. }
  4723. }
  4724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4730. } // END FOR DC CASE
  4731. }
  4732. //================================================ Message create ====================================================
  4733. json_object *StopTransaction = json_object_new_object();
  4734. json_object *transactionDatas = json_object_new_array();
  4735. json_object *sampledValues = json_object_new_array();
  4736. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4737. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4738. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4739. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4740. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4741. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4742. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4743. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4744. {
  4745. json_object *transactionData = json_object_new_object();
  4746. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4747. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4748. {
  4749. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4750. {
  4751. json_object *sampledValue = json_object_new_object();
  4752. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4753. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4754. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4755. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4756. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4757. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4758. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4759. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4760. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4761. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4762. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4763. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4764. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4765. json_object_array_add(sampledValues, sampledValue);
  4766. }
  4767. }
  4768. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4769. json_object_array_add(transactionDatas, transactionData);
  4770. }
  4771. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4772. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4773. ,MESSAGE_TYPE_CALL
  4774. ,guid
  4775. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4776. json_object_put(StopTransaction);
  4777. #if 1 // for TempStopTransaction
  4778. //Delete TempStopTransaction
  4779. if((access(TempStopTransaction,F_OK))!=-1)
  4780. {
  4781. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4782. }
  4783. #endif
  4784. #if 1
  4785. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4786. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4787. {
  4788. result = PASS;
  4789. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4790. }
  4791. #endif
  4792. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4793. OCPP_insert_transaction_msg(NO, queuedata);
  4794. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4795. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4796. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4797. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4798. {
  4799. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4800. }
  4801. //for test
  4802. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4803. return result;
  4804. }
  4805. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4806. {
  4807. mtrace();
  4808. int result = FAIL;
  4809. char guid[37]={0};
  4810. char tempdata[65]={0};
  4811. int tempIndex = 0;
  4812. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4813. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4814. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4815. //set value
  4816. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4817. 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) )?
  4818. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4819. -1);
  4820. random_uuid(guid);
  4821. //UTC Date time
  4822. struct timeval tmnow;
  4823. struct tm *tm;
  4824. char buf[28];//, usec_buf[6];
  4825. gettimeofday(&tmnow, NULL);
  4826. time_t t;
  4827. t = time(NULL);
  4828. /*UTC time and date*/
  4829. tm = gmtime(&t);
  4830. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4832. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4833. //********************************(1)Current.Import L1************************************************/
  4834. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4835. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4836. (dataType == ReadingContext_Trigger))
  4837. {
  4838. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4839. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4840. {
  4841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4842. {
  4843. tempIndex = ((gun_index==2) ? 1: 0);
  4844. }
  4845. else
  4846. {
  4847. tempIndex = gun_index;
  4848. }
  4849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4850. {
  4851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4852. {
  4853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4854. }
  4855. }
  4856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4857. }
  4858. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4859. {
  4860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4861. {
  4862. tempIndex = ((gun_index==2) ? 1: 0);
  4863. }
  4864. else
  4865. {
  4866. tempIndex = gun_index;
  4867. }
  4868. for (int index = 0; index < CCS_QUANTITY; index++)
  4869. {
  4870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4871. {
  4872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4873. }
  4874. }
  4875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4876. }
  4877. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4878. {
  4879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4880. {
  4881. tempIndex = ((gun_index==2) ? 1: 0);
  4882. }
  4883. else
  4884. {
  4885. tempIndex = gun_index;
  4886. }
  4887. for (int index = 0; index < GB_QUANTITY; index++)
  4888. {
  4889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4890. {
  4891. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4892. }
  4893. }
  4894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_DO)
  4897. {
  4898. tempIndex = gun_index;
  4899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4904. }
  4905. }
  4906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4907. }
  4908. else
  4909. {
  4910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4911. {
  4912. tempIndex = 2;
  4913. }
  4914. else
  4915. {
  4916. tempIndex = gun_index;
  4917. }
  4918. for (int index = 0; index < AC_QUANTITY; index++)
  4919. {
  4920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4921. {
  4922. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4923. }
  4924. }
  4925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4926. }
  4927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4932. }
  4933. //********************************(2)Energy.Active.Import.Register ************************************************/
  4934. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4935. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4936. (dataType == ReadingContext_Trigger))
  4937. {
  4938. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4940. {
  4941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4942. {
  4943. tempIndex = ((gun_index==2) ? 1: 0);
  4944. }
  4945. else
  4946. {
  4947. tempIndex = gun_index;
  4948. }
  4949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4950. {
  4951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4952. {
  4953. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4954. }
  4955. }
  4956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4957. }
  4958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4959. {
  4960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4961. {
  4962. tempIndex = ((gun_index==2) ? 1: 0);
  4963. }
  4964. else
  4965. {
  4966. tempIndex = gun_index;
  4967. }
  4968. for (int index = 0; index < CCS_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4973. }
  4974. }
  4975. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4976. }
  4977. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4978. {
  4979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4980. {
  4981. tempIndex = ((gun_index==2) ? 1: 0);
  4982. }
  4983. else
  4984. {
  4985. tempIndex = gun_index;
  4986. }
  4987. for (int index = 0; index < GB_QUANTITY; index++)
  4988. {
  4989. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4990. {
  4991. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4992. }
  4993. }
  4994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4995. }
  4996. else if(gunType[gun_index] == GUN_TYPE_DO)
  4997. {
  4998. tempIndex = gun_index;
  4999. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5002. {
  5003. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5004. }
  5005. }
  5006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5007. }
  5008. else
  5009. {
  5010. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5011. {
  5012. tempIndex = 2;
  5013. }
  5014. else
  5015. {
  5016. tempIndex = gun_index;
  5017. }
  5018. for (int index = 0; index < AC_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5021. {
  5022. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5023. }
  5024. }
  5025. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5026. }
  5027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5032. }
  5033. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5034. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5035. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5036. (dataType == ReadingContext_Trigger))
  5037. {
  5038. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5039. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5040. {
  5041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5042. {
  5043. tempIndex = ((gun_index==2) ? 1: 0);
  5044. }
  5045. else
  5046. {
  5047. tempIndex = gun_index;
  5048. }
  5049. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5050. {
  5051. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5052. {
  5053. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5054. }
  5055. } // END OF FOR CHAdeMO_QUANTITY
  5056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5057. }
  5058. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5059. {
  5060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5061. {
  5062. tempIndex = ((gun_index==2) ? 1: 0);
  5063. }
  5064. else
  5065. {
  5066. tempIndex = gun_index;
  5067. }
  5068. for (int index = 0; index < CCS_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5071. {
  5072. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5073. }
  5074. } // END OF CCS_QUANTITY
  5075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5076. }
  5077. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5078. {
  5079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5080. {
  5081. tempIndex = ((gun_index==2) ? 1: 0);
  5082. }
  5083. else
  5084. {
  5085. tempIndex = gun_index;
  5086. }
  5087. for (int index = 0; index < GB_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5090. {
  5091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5092. }
  5093. } // END OF GB_QUANTITY
  5094. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5095. }
  5096. else if(gunType[gun_index] == GUN_TYPE_DO)
  5097. {
  5098. tempIndex = gun_index;
  5099. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5100. {
  5101. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5102. {
  5103. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5104. }
  5105. }
  5106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5107. }
  5108. else
  5109. {
  5110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5111. {
  5112. tempIndex = 2;
  5113. }
  5114. else
  5115. {
  5116. tempIndex = gun_index;
  5117. }
  5118. for (int index = 0; index < AC_QUANTITY; index++)
  5119. {
  5120. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5121. {
  5122. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5123. }
  5124. }
  5125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5126. }
  5127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5128. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5129. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5132. }
  5133. //********************************(4)Power.Active.Import************************************************/
  5134. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5135. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5136. (dataType == ReadingContext_Trigger))
  5137. {
  5138. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5139. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5140. {
  5141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5142. {
  5143. tempIndex = ((gun_index==2) ? 1: 0);
  5144. }
  5145. else
  5146. {
  5147. tempIndex = gun_index;
  5148. }
  5149. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5150. {
  5151. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5152. {
  5153. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5154. }
  5155. } // END OF FOR
  5156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5157. }
  5158. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CCS_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5173. }
  5174. }
  5175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < GB_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5190. {
  5191. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5192. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5193. }
  5194. }
  5195. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5196. }
  5197. else if(gunType[gun_index] == GUN_TYPE_DO)
  5198. {
  5199. tempIndex = gun_index;
  5200. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5201. {
  5202. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5203. {
  5204. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5206. }
  5207. }
  5208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5209. }
  5210. else
  5211. {
  5212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5213. {
  5214. tempIndex = 2;
  5215. }
  5216. else
  5217. {
  5218. tempIndex = gun_index;
  5219. }
  5220. for (int index = 0; index < AC_QUANTITY; index++)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5223. {
  5224. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5225. }
  5226. }
  5227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5228. }
  5229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5234. }
  5235. //***********************************************(5)VOLTAGE L1******************************************************/
  5236. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5237. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5238. (dataType == ReadingContext_Trigger))
  5239. {
  5240. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5241. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5242. {
  5243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5244. {
  5245. tempIndex = ((gun_index==2) ? 1: 0);
  5246. }
  5247. else
  5248. {
  5249. tempIndex = gun_index;
  5250. }
  5251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5252. {
  5253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5254. {
  5255. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5256. }
  5257. }
  5258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5259. }
  5260. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5263. {
  5264. tempIndex = ((gun_index==2) ? 1: 0);
  5265. }
  5266. else
  5267. {
  5268. tempIndex = gun_index;
  5269. }
  5270. for (int index = 0; index < CCS_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5273. {
  5274. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5275. }
  5276. }
  5277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5278. }
  5279. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5280. {
  5281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5282. {
  5283. tempIndex = ((gun_index==2) ? 1: 0);
  5284. }
  5285. else
  5286. {
  5287. tempIndex = gun_index;
  5288. }
  5289. for (int index = 0; index < GB_QUANTITY; index++)
  5290. {
  5291. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5292. {
  5293. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5294. }
  5295. }
  5296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5297. }
  5298. else if(gunType[gun_index] == GUN_TYPE_DO)
  5299. {
  5300. tempIndex = gun_index;
  5301. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5302. {
  5303. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5304. {
  5305. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5306. }
  5307. }
  5308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5309. }
  5310. else
  5311. {
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5313. {
  5314. tempIndex = 2;
  5315. }
  5316. else
  5317. {
  5318. tempIndex = gun_index;
  5319. }
  5320. for (int index = 0; index < AC_QUANTITY; index++)
  5321. {
  5322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5323. {
  5324. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5325. }
  5326. }
  5327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5328. }
  5329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5334. }
  5335. //***********************************************(6)SOC******************************************************/
  5336. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5337. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5338. (dataType == ReadingContext_Trigger))
  5339. {
  5340. 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))
  5341. {
  5342. //idx_sample=5;
  5343. //sampledValue = NULL;
  5344. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5345. {
  5346. tempIndex = ((gun_index==2) ? 1: 0);
  5347. }
  5348. else
  5349. {
  5350. tempIndex = gun_index;
  5351. }
  5352. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5353. {
  5354. //tempIndex = ((gun_index==2) ? 1: 0);
  5355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5356. {
  5357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5358. {
  5359. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5360. }
  5361. }
  5362. }
  5363. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5364. {
  5365. //tempIndex = ((gun_index==2) ? 1: 0);
  5366. for (int index = 0; index < CCS_QUANTITY; index++)
  5367. {
  5368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5369. {
  5370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5371. }
  5372. }
  5373. }
  5374. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5375. {
  5376. //tempIndex = ((gun_index==2) ? 1: 0);
  5377. for (int index = 0; index < GB_QUANTITY; index++)
  5378. {
  5379. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5380. {
  5381. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5382. }
  5383. }
  5384. }
  5385. else if(gunType[gun_index] == GUN_TYPE_DO)
  5386. {
  5387. //tempIndex = ((gun_index==2) ? 1: 0);
  5388. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5389. {
  5390. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5391. {
  5392. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5393. }
  5394. }
  5395. }
  5396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5402. }
  5403. }
  5404. //********************************(7)Current.Import L2************************************************/
  5405. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5406. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5407. (dataType == ReadingContext_Trigger))
  5408. {
  5409. // Only for AC 3 phase
  5410. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5411. {
  5412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5413. {
  5414. tempIndex = 2;
  5415. }
  5416. else
  5417. {
  5418. tempIndex = gun_index;
  5419. }
  5420. for (int index = 0; index < AC_QUANTITY; index++)
  5421. {
  5422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5423. {
  5424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5425. }
  5426. }
  5427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5428. }
  5429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5434. }
  5435. //********************************(8)Current.Import L3************************************************/
  5436. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5437. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5438. (dataType == ReadingContext_Trigger))
  5439. {
  5440. // Only for AC 3 phase
  5441. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5444. {
  5445. tempIndex = 2;
  5446. }
  5447. else
  5448. {
  5449. tempIndex = gun_index;
  5450. }
  5451. for (int index = 0; index < AC_QUANTITY; index++)
  5452. {
  5453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5454. {
  5455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5456. }
  5457. }
  5458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5459. }
  5460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5465. }
  5466. //***********************************************(9)VOLTAGE L2******************************************************/
  5467. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5468. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5469. (dataType == ReadingContext_Trigger))
  5470. {
  5471. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5472. {
  5473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5474. {
  5475. tempIndex = 2;
  5476. }
  5477. else
  5478. {
  5479. tempIndex = gun_index;
  5480. }
  5481. for (int index = 0; index < AC_QUANTITY; index++)
  5482. {
  5483. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5484. {
  5485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5486. }
  5487. }
  5488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5489. }
  5490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5495. }
  5496. //***********************************************(10)VOLTAGE L3******************************************************/
  5497. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5498. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5499. (dataType == ReadingContext_Trigger))
  5500. {
  5501. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5502. {
  5503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5504. {
  5505. tempIndex = 2;
  5506. }
  5507. else
  5508. {
  5509. tempIndex = gun_index;
  5510. }
  5511. for (int index = 0; index < AC_QUANTITY; index++)
  5512. {
  5513. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5514. {
  5515. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5516. }
  5517. }
  5518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5519. }
  5520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5525. }
  5526. // Message create ====================================================================================================
  5527. if(TRUE)
  5528. {
  5529. json_object *MeterValueReq = json_object_new_object();
  5530. json_object *MeterValues = json_object_new_array();
  5531. json_object *sampledValues = json_object_new_array();
  5532. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5533. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5534. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5535. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5536. {
  5537. json_object *MeterValue = json_object_new_object();
  5538. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5539. {
  5540. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5541. {
  5542. json_object *sampledValue = json_object_new_object();
  5543. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5544. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5545. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5546. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5547. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5548. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5549. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5550. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5551. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5552. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5553. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5554. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5555. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5556. json_object_array_add(sampledValues, sampledValue);
  5557. }
  5558. }
  5559. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5560. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5561. json_object_array_add(MeterValues, MeterValue);
  5562. }
  5563. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5564. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5565. ,gun_index + 1
  5566. ,MESSAGE_TYPE_CALL
  5567. ,guid
  5568. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5569. json_object_put(MeterValueReq);
  5570. }
  5571. // Put request guid to hash map
  5572. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5573. 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*/)
  5574. {
  5575. result = PASS;
  5576. //DEBUG_INFO("MeterValues mapitem pass\n");
  5577. }
  5578. if((dataType != ReadingContext_Trigger) &&
  5579. (dataType != ReadingContext_Sample_Clock) &&
  5580. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5581. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5582. else
  5583. {
  5584. if(FirstHeartBeat)
  5585. LWS_Send(queuedata +2);
  5586. }
  5587. return result;
  5588. }
  5589. int sendLogStatusNotificationRequest(char *status)
  5590. {
  5591. mtrace();
  5592. int result = PASS;
  5593. char message[4096]={0};
  5594. char guid[37]={0};
  5595. char tempdata[128]={0};
  5596. json_object *LogStatusNotification = json_object_new_object();
  5597. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5598. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5599. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5600. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5601. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5602. random_uuid(guid);
  5603. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5604. json_object_put(LogStatusNotification);
  5605. LWS_Send(message);
  5606. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5607. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5608. {
  5609. result = PASS;
  5610. }
  5611. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5612. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5613. return result;
  5614. }
  5615. int sendSecurityEventNotificationRequest()
  5616. {
  5617. mtrace();
  5618. int result = PASS;
  5619. char message[4096]={0};
  5620. char guid[37]={0};
  5621. char tempdata[128]={0};
  5622. json_object *SecurityEventNotification = json_object_new_object();
  5623. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5624. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5625. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5626. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5627. random_uuid(guid);
  5628. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5629. json_object_put(SecurityEventNotification);
  5630. LWS_Send(message);
  5631. sprintf(tempdata, "SecurityEventNotification,0");
  5632. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5633. {
  5634. result = PASS;
  5635. }
  5636. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5637. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5638. return result;
  5639. }
  5640. int sendSignCertificateRequest()
  5641. {
  5642. mtrace();
  5643. int result = PASS;
  5644. char message[4096]={0};
  5645. char guid[37]={0};
  5646. char tempdata[128]={0};
  5647. json_object *SignCertificate = json_object_new_object();
  5648. DEBUG_INFO("sendSignCertificateRequest...\n");
  5649. // Read csr file content
  5650. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5651. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5652. char *line = NULL;
  5653. size_t len = 0;
  5654. while(getline(&line, &len, fp) != -1)
  5655. {
  5656. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5657. {
  5658. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5659. }
  5660. }
  5661. fclose(fp);
  5662. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5663. random_uuid(guid);
  5664. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5665. json_object_put(SignCertificate);
  5666. LWS_Send(message);
  5667. sprintf(tempdata, "SignCertificate,0");
  5668. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5669. {
  5670. result = PASS;
  5671. }
  5672. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5673. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5674. return result;
  5675. }
  5676. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5677. {
  5678. mtrace();
  5679. int result = PASS;
  5680. char message[110]={0};
  5681. char guid[37]={0};
  5682. char tempdata[65]={0};
  5683. json_object *FirmwareStatusNotification = json_object_new_object();
  5684. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5685. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5686. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5687. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5688. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5689. random_uuid(guid);
  5690. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5691. json_object_put(FirmwareStatusNotification);
  5692. LWS_Send(message);
  5693. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5694. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5695. {
  5696. result = PASS;
  5697. }
  5698. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5699. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5700. return result;
  5701. }
  5702. //==========================================
  5703. // send confirm routine
  5704. //==========================================
  5705. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5706. {
  5707. mtrace();
  5708. int result = FAIL;
  5709. char message[100]={0};
  5710. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5711. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5712. LWS_Send(message);
  5713. result = TRUE;
  5714. return result;
  5715. }
  5716. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5717. {
  5718. mtrace();
  5719. int result = FAIL;
  5720. char message[100]={0};
  5721. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5722. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5723. LWS_Send(message);
  5724. result = TRUE;
  5725. return result;
  5726. }
  5727. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5728. {
  5729. mtrace();
  5730. int result = FAIL;
  5731. char message[100]={0};
  5732. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5734. LWS_Send(message);
  5735. result = TRUE;
  5736. return result;
  5737. }
  5738. int sendClearCacheConfirmation(char *uuid,char *payload)
  5739. {
  5740. mtrace();
  5741. int result = FAIL;
  5742. char message[500]={0};
  5743. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5744. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5745. LWS_Send(message);
  5746. return result;
  5747. }
  5748. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5749. {
  5750. mtrace();
  5751. int result = FAIL;
  5752. char message[500]={0};
  5753. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5754. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5755. LWS_Send(message);
  5756. return result;
  5757. }
  5758. int sendDataTransferConfirmation(char *uuid,char *payload)
  5759. {
  5760. mtrace();
  5761. char statusStr[20]={0};
  5762. char dataStr[10]={0};
  5763. char sstr[20]={0};
  5764. int c = 0;
  5765. char *loc;
  5766. int result = FAIL;
  5767. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5768. /**********************status**************************/
  5769. loc = strstr(payload, "status");
  5770. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5771. c = 0;
  5772. while (loc[3+strlen("status")+c] != '\"')
  5773. {
  5774. sstr[c] = loc[3+strlen("status")+c];
  5775. c++;
  5776. }
  5777. sstr[c] = '\0';
  5778. strcpy(statusStr, sstr);
  5779. /**********************data**************************/
  5780. loc = strstr(payload, "data");
  5781. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5782. c = 0;
  5783. while (loc[3+strlen("data")+c] != '\"')
  5784. {
  5785. sstr[c] = loc[3+strlen("data")+c];
  5786. c++;
  5787. }
  5788. sstr[c] = '\0';
  5789. strcpy(dataStr, sstr);
  5790. return result;
  5791. }
  5792. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5793. {
  5794. mtrace();
  5795. int result = FAIL;
  5796. char message[1000]={0};
  5797. int CompositeScheduleIndex = 0;
  5798. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5799. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5800. if(nPeriod == 0)
  5801. {
  5802. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5803. {
  5804. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5805. ,MESSAGE_TYPE_CALLRESULT
  5806. ,uuid
  5807. ,payload
  5808. ,connectorIdInt);
  5809. }
  5810. else
  5811. {
  5812. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5813. ,MESSAGE_TYPE_CALLRESULT
  5814. ,uuid
  5815. ,payload
  5816. ,connectorIdInt
  5817. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5818. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5819. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5820. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5821. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5822. }
  5823. }
  5824. else
  5825. {
  5826. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5827. ,MESSAGE_TYPE_CALLRESULT
  5828. ,uuid
  5829. ,payload
  5830. ,connectorIdInt
  5831. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5832. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5833. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5834. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5835. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5836. {
  5837. if (idx_sample == 0)
  5838. {
  5839. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5840. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5841. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5842. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5843. }
  5844. else
  5845. {
  5846. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5847. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5848. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5849. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5850. }
  5851. }
  5852. sprintf(message + strlen(message), "]}}]");
  5853. }
  5854. LWS_Send(message);
  5855. result = TRUE;
  5856. return result;
  5857. }
  5858. int sendGetConfigurationConfirmation(char *uuid)
  5859. {
  5860. mtrace();
  5861. int result = FAIL;
  5862. int MaxKeySupported = 0;
  5863. int sentConfigurationNumber= 0;
  5864. int sentunConfigurationNumber= 0;
  5865. char message[4000]={0};
  5866. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5867. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5868. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5869. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5870. ,MESSAGE_TYPE_CALLRESULT
  5871. ,uuid );
  5872. //configuration key
  5873. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5874. {
  5875. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5876. {
  5877. if (sentConfigurationNumber == 0)
  5878. {
  5879. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5880. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5881. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5882. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5883. }
  5884. else
  5885. {
  5886. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5887. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5888. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5889. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5890. }
  5891. sentConfigurationNumber = sentConfigurationNumber + 1;
  5892. }
  5893. }
  5894. sprintf(message + strlen(message), "]");
  5895. if(UnknownKeynum != 0)
  5896. {
  5897. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5898. //unkown key
  5899. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5900. {
  5901. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5902. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5903. if(sentunConfigurationNumber == 0)
  5904. {
  5905. sprintf(message + strlen(message), "\"%s\""
  5906. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5907. }
  5908. else
  5909. {
  5910. sprintf(message + strlen(message), ",\"%s\""
  5911. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5912. }
  5913. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5914. }
  5915. sprintf(message + strlen(message), "]");
  5916. }
  5917. sprintf(message + strlen(message), "}]");
  5918. LWS_Send(message);
  5919. return result;
  5920. }
  5921. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5922. {
  5923. mtrace();
  5924. int result = FAIL;
  5925. char message[400]={0};
  5926. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5927. if(strcmp(payload,"")==0)
  5928. {
  5929. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5930. }
  5931. else
  5932. {
  5933. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5934. }
  5935. LWS_Send(message);
  5936. result = TRUE;
  5937. return result;
  5938. }
  5939. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5940. {
  5941. mtrace();
  5942. int result = FAIL;
  5943. char message[80]={0};
  5944. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5945. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5946. LWS_Send(message);
  5947. result = TRUE;
  5948. return result;
  5949. }
  5950. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5951. {
  5952. mtrace();
  5953. int result = FAIL;
  5954. char message[80]={0};
  5955. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5957. LWS_Send(message);
  5958. result = TRUE;
  5959. return result;
  5960. }
  5961. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5962. {
  5963. mtrace();
  5964. int result = FAIL;
  5965. char message[80]={0};
  5966. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5968. LWS_Send(message);
  5969. result = TRUE;
  5970. return result;
  5971. }
  5972. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5973. {
  5974. mtrace();
  5975. int result = FAIL;
  5976. char message[80]={0};
  5977. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5978. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5979. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5980. LWS_Send(message);
  5981. result = TRUE;
  5982. return result;
  5983. }
  5984. int sendResetConfirmation(char *uuid,char *payload)
  5985. {
  5986. mtrace();
  5987. int result = FAIL;
  5988. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5989. char message[80]={0};
  5990. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5991. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5992. LWS_Send(message);
  5993. result = TRUE;
  5994. return result;
  5995. }
  5996. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5997. {
  5998. mtrace();
  5999. int result = FAIL;
  6000. char message[500]={0};
  6001. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6002. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6003. LWS_Send(message);
  6004. result = TRUE;
  6005. return result;
  6006. }
  6007. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6008. {
  6009. mtrace();
  6010. int result = FAIL;
  6011. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6012. char message[80]={0};
  6013. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6014. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6015. LWS_Send(message);
  6016. result = TRUE;
  6017. return result;
  6018. }
  6019. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6020. {
  6021. mtrace();
  6022. int result = FAIL;
  6023. char message[80]={0};
  6024. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6025. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6026. LWS_Send(message);
  6027. result = TRUE;
  6028. return result;
  6029. }
  6030. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6031. {
  6032. mtrace();
  6033. int result = FAIL;
  6034. char message[80]={0};
  6035. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6036. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6037. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6038. LWS_Send(message);
  6039. result = TRUE;
  6040. return result;
  6041. }
  6042. int sendUpdateFirmwareConfirmation(char *uuid)
  6043. {
  6044. mtrace();
  6045. int result = FAIL;
  6046. char message[60]={0};
  6047. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6048. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6049. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6050. LWS_Send(message);
  6051. result = TRUE;
  6052. return result;
  6053. }
  6054. int sendCertificateSignedConfirmation(char *uuid)
  6055. {
  6056. mtrace();
  6057. int result = PASS;
  6058. char message[4096]={0};
  6059. json_object *CertificateSigned = json_object_new_object();
  6060. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6061. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6062. sprintf(message,"[%d,\"%s\",%s]"
  6063. ,MESSAGE_TYPE_CALLRESULT
  6064. ,uuid
  6065. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6066. json_object_put(CertificateSigned);
  6067. LWS_Send(message);
  6068. return result;
  6069. }
  6070. int sendDeleteCertificateConfirmation(char *uuid)
  6071. {
  6072. mtrace();
  6073. int result = PASS;
  6074. char message[4096]={0};
  6075. json_object *DeleteCertificate = json_object_new_object();
  6076. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6077. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6078. sprintf(message,"[%d,\"%s\",%s]"
  6079. ,MESSAGE_TYPE_CALLRESULT
  6080. ,uuid
  6081. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6082. json_object_put(DeleteCertificate);
  6083. LWS_Send(message);
  6084. return result;
  6085. }
  6086. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6087. {
  6088. mtrace();
  6089. int result = PASS;
  6090. char message[4096]={0};
  6091. json_object *ExtendedTriggerMessage = json_object_new_object();
  6092. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6093. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6094. sprintf(message,"[%d,\"%s\",%s]"
  6095. ,MESSAGE_TYPE_CALLRESULT
  6096. ,uuid
  6097. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6098. json_object_put(ExtendedTriggerMessage);
  6099. LWS_Send(message);
  6100. return result;
  6101. }
  6102. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6103. {
  6104. mtrace();
  6105. int result = PASS;
  6106. char message[4096]={0};
  6107. json_object *GetInstalledCertificateIds = json_object_new_object();
  6108. json_object *certificateHashDataDatas = json_object_new_array();
  6109. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6110. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6111. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6112. {
  6113. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6114. {
  6115. json_object *certificateHashData = json_object_new_object();
  6116. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6117. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6118. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6119. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6120. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6121. }
  6122. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6123. }
  6124. else
  6125. {
  6126. json_object_put(certificateHashDataDatas);
  6127. }
  6128. sprintf(message,"[%d,\"%s\",%s]"
  6129. ,MESSAGE_TYPE_CALLRESULT
  6130. ,uuid
  6131. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6132. json_object_put(GetInstalledCertificateIds);
  6133. LWS_Send(message);
  6134. return result;
  6135. }
  6136. int sendGetLogConfirmation(char *uuid)
  6137. {
  6138. mtrace();
  6139. int result = PASS;
  6140. char message[4096]={0};
  6141. json_object *GetLog = json_object_new_object();
  6142. DEBUG_INFO("sendGetLogConfirmation...\n");
  6143. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6144. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6145. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6146. sprintf(message,"[%d,\"%s\",%s]"
  6147. ,MESSAGE_TYPE_CALLRESULT
  6148. ,uuid
  6149. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6150. json_object_put(GetLog);
  6151. LWS_Send(message);
  6152. return result;
  6153. }
  6154. int sendInstallCertificateConfirmation(char *uuid)
  6155. {
  6156. mtrace();
  6157. int result = PASS;
  6158. char message[4096]={0};
  6159. json_object *InstallCertificate = json_object_new_object();
  6160. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6161. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6162. sprintf(message,"[%d,\"%s\",%s]"
  6163. ,MESSAGE_TYPE_CALLRESULT
  6164. ,uuid
  6165. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6166. json_object_put(InstallCertificate);
  6167. LWS_Send(message);
  6168. return result;
  6169. }
  6170. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6171. {
  6172. mtrace();
  6173. int result = PASS;
  6174. char message[4096]={0};
  6175. json_object *SignedUpdateFirmware = json_object_new_object();
  6176. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6177. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6178. sprintf(message,"[%d,\"%s\",%s]"
  6179. ,MESSAGE_TYPE_CALLRESULT
  6180. ,uuid
  6181. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6182. json_object_put(SignedUpdateFirmware);
  6183. LWS_Send(message);
  6184. return result;
  6185. }
  6186. int sendUnknownConfirmation(char *uuid)
  6187. {
  6188. mtrace();
  6189. int result = PASS;
  6190. char message[256]={0};
  6191. DEBUG_INFO("sendUnknownConfirmation...\n");
  6192. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6193. LWS_Send(message);
  6194. return result;
  6195. }
  6196. //==========================================
  6197. // Handle server request routine Start
  6198. //==========================================
  6199. int handleCancelReservationRequest(char *uuid, char *payload)
  6200. {
  6201. mtrace();
  6202. int result = FAIL;
  6203. int gunNO = 0;
  6204. int reservationIdInt = -1;
  6205. char comfirmstr[20];
  6206. DEBUG_INFO("handleCancelReservationRequest...\n");
  6207. json_object *CancelReservation;
  6208. CancelReservation = json_tokener_parse(payload);
  6209. if(!is_error(CancelReservation))
  6210. {
  6211. // Required data
  6212. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6213. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6214. }
  6215. json_object_put(CancelReservation);
  6216. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6217. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6218. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6219. if(reservationIdInt != -1)
  6220. {
  6221. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6222. //check Transaction active
  6223. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6224. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6227. {
  6228. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6229. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6230. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6231. {
  6232. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6233. }
  6234. else
  6235. {
  6236. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6237. }
  6238. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6239. goto end;
  6240. }
  6241. }
  6242. for (int index = 0; index < CCS_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6245. {
  6246. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6247. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6248. if(gunType[2] == GUN_TYPE_CCS)
  6249. {
  6250. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6251. }
  6252. else
  6253. {
  6254. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6255. }
  6256. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6257. goto end;
  6258. }
  6259. }
  6260. for (int index = 0; index < GB_QUANTITY; index++)
  6261. {
  6262. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6263. {
  6264. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6265. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6266. if(gunType[2] == GUN_TYPE_GBT)
  6267. {
  6268. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6269. }
  6270. else
  6271. {
  6272. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6273. }
  6274. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6275. goto end;
  6276. }
  6277. }
  6278. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6279. {
  6280. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6281. {
  6282. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6283. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6284. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6285. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6286. goto end;
  6287. }
  6288. }
  6289. for (int index = 0; index < AC_QUANTITY; index++)
  6290. {
  6291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6292. {
  6293. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6294. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6296. {
  6297. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6298. }
  6299. else
  6300. {
  6301. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6302. }
  6303. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6304. goto end;
  6305. }
  6306. }
  6307. }
  6308. //The reservationId does NOT match the reservationId
  6309. sendCancelReservationConfirmation(uuid, comfirmstr);
  6310. end:
  6311. // Fill in ocpp packet uuid
  6312. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6313. return result;
  6314. }
  6315. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6316. {
  6317. mtrace();
  6318. int result = FAIL;
  6319. int gunIndex = 0;
  6320. char typeStr[16]={0};
  6321. char comfirmstr[20];
  6322. int specificId = FALSE;
  6323. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6324. json_object *ChangeAvailability;
  6325. ChangeAvailability = json_tokener_parse(payload);
  6326. if(!is_error(ChangeAvailability))
  6327. {
  6328. // Required data
  6329. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6330. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6331. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6332. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6333. }
  6334. json_object_put(ChangeAvailability);
  6335. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6336. {
  6337. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6338. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6339. }
  6340. else if(gunIndex == 0)
  6341. {
  6342. for(int i=0; i < gunTotalNumber; i++)
  6343. {
  6344. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6345. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6346. }
  6347. }
  6348. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6349. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6350. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6351. {
  6352. specificId = TRUE;
  6353. }
  6354. if(specificId == FALSE)
  6355. goto end;
  6356. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6357. {
  6358. //----------------------gunIndex is 0 ------------------------------------------------//
  6359. if(gunIndex == 0)
  6360. {
  6361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6362. {
  6363. for(int i=0; i < gunTotalNumber; i++)
  6364. {
  6365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6366. {
  6367. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6368. {
  6369. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6370. {
  6371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6372. goto end;
  6373. }
  6374. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6375. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6377. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6379. {
  6380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6381. goto end;
  6382. }
  6383. }
  6384. }//END FOR CHAdeMO_QUANTITY
  6385. for (int index = 0; index < CCS_QUANTITY; index++)
  6386. {
  6387. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6388. {
  6389. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6390. {
  6391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6392. goto end;
  6393. }
  6394. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6395. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6397. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6398. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6399. {
  6400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6401. goto end;
  6402. }
  6403. }
  6404. }//END FOR CCS_QUANTITY
  6405. for (int index = 0; index < GB_QUANTITY; index++)
  6406. {
  6407. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6408. {
  6409. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6410. {
  6411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6412. goto end;
  6413. }
  6414. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6415. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6417. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6418. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6419. {
  6420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6421. goto end;
  6422. }
  6423. }
  6424. }// END FOR GB_QUANTITY
  6425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6426. {
  6427. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6428. {
  6429. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6430. {
  6431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6432. goto end;
  6433. }
  6434. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6436. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6437. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6438. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6439. {
  6440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6441. goto end;
  6442. }
  6443. }
  6444. }// END FOR GENERAL_GUN_QUANTITY
  6445. for (int index = 0; index < AC_QUANTITY; index++)
  6446. {
  6447. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6448. {
  6449. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6450. {
  6451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6452. goto end;
  6453. }
  6454. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6456. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6458. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6459. {
  6460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6461. goto end;
  6462. }
  6463. }
  6464. }//END FOR AC_QUANTITY
  6465. }// END FOR gunTotalNumber
  6466. }
  6467. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6468. {
  6469. for(int i=0; i < gunTotalNumber; i++)
  6470. {
  6471. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6472. {
  6473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6474. goto end;
  6475. }
  6476. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6477. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6478. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6479. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6480. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6481. {
  6482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6483. goto end;
  6484. }
  6485. }
  6486. }
  6487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6488. goto end;
  6489. }
  6490. //----------------------gunIndex is not 0 ------------------------------------------------//
  6491. //check Transaction active
  6492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6493. {
  6494. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6495. {
  6496. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6497. {
  6498. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6499. goto end;
  6500. }
  6501. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6502. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6503. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6504. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6505. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6506. {
  6507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6508. goto end;
  6509. }
  6510. else
  6511. {
  6512. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6514. goto end;
  6515. }
  6516. }
  6517. }//END FOR CHAdeMO_QUANTITY
  6518. for (int index = 0; index < CCS_QUANTITY; index++)
  6519. {
  6520. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6521. {
  6522. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6523. {
  6524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6525. goto end;
  6526. }
  6527. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6528. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6529. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6530. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6531. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6532. {
  6533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6534. goto end;
  6535. }
  6536. else
  6537. {
  6538. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6540. goto end;
  6541. }
  6542. }
  6543. }//END FOR CCS_QUANTITY
  6544. for (int index = 0; index < GB_QUANTITY; index++)
  6545. {
  6546. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6547. {
  6548. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6549. {
  6550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6551. goto end;
  6552. }
  6553. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6554. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6555. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6556. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6557. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6558. {
  6559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6560. goto end;
  6561. }
  6562. else
  6563. {
  6564. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6566. goto end;
  6567. }
  6568. }
  6569. }// END FOR GB_QUANTITY
  6570. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6571. {
  6572. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6573. {
  6574. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6575. {
  6576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6577. goto end;
  6578. }
  6579. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6580. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6581. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6582. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6583. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6584. {
  6585. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6586. goto end;
  6587. }
  6588. else
  6589. {
  6590. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6592. goto end;
  6593. }
  6594. }
  6595. }// END FOR GENERAL_GUN_QUANTITY
  6596. for (int index = 0; index < AC_QUANTITY; index++)
  6597. {
  6598. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6599. {
  6600. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6601. {
  6602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6603. goto end;
  6604. }
  6605. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6606. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6607. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6608. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6609. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6610. {
  6611. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6612. goto end;
  6613. }
  6614. else
  6615. {
  6616. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6618. goto end;
  6619. }
  6620. }
  6621. }//END FOR AC_QUANTITY
  6622. }//END FOR AvailabilityTypeStr[Inoperative]
  6623. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6624. {
  6625. //----------------------gunIndex is 0 ------------------------------------------------//
  6626. if(gunIndex == 0)
  6627. {
  6628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6629. {
  6630. for(int i=0; i < gunTotalNumber; i++)
  6631. {
  6632. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6633. {
  6634. 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
  6635. {
  6636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6637. goto end;
  6638. }
  6639. }//END FOR CHAdeMO_QUANTITY
  6640. for (int index = 0; index < CCS_QUANTITY; index++)
  6641. {
  6642. 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
  6643. {
  6644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6645. goto end;
  6646. }
  6647. }//END FOR CCS_QUANTITY
  6648. for (int index = 0; index < GB_QUANTITY; index++)
  6649. {
  6650. 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
  6651. {
  6652. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6654. goto end;
  6655. }
  6656. }// END FOR GB_QUANTITY
  6657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6658. {
  6659. 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
  6660. {
  6661. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6662. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6663. goto end;
  6664. }
  6665. }// END FOR GENERAL_GUN_QUANTITY
  6666. for (int index = 0; index < AC_QUANTITY; index++)
  6667. {
  6668. 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
  6669. {
  6670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6671. goto end;
  6672. }
  6673. }//END FOR CHAdeMO_QUANTITY
  6674. }// END FOR gunTotalNumber
  6675. }
  6676. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6677. {
  6678. for(int i=0; i < gunTotalNumber; i++)
  6679. {
  6680. for (int index = 0; index < AC_QUANTITY; index++)
  6681. {
  6682. 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
  6683. {
  6684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6685. goto end;
  6686. }
  6687. }//END FOR CHAdeMO_QUANTITY
  6688. } // END FOR gunTotalNumber
  6689. }
  6690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6691. goto end;
  6692. }
  6693. //----------------------gunIndex is not 0 ------------------------------------------------//
  6694. //check Transaction active
  6695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6696. {
  6697. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6698. {
  6699. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6700. goto end;
  6701. }
  6702. }//END FOR CHAdeMO_QUANTITY
  6703. for (int index = 0; index < CCS_QUANTITY; index++)
  6704. {
  6705. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6706. {
  6707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6708. goto end;
  6709. }
  6710. }//END FOR CCS_QUANTITY
  6711. for (int index = 0; index < GB_QUANTITY; index++)
  6712. {
  6713. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6714. {
  6715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6716. goto end;
  6717. }
  6718. }// END FOR GB_QUANTITY
  6719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6720. {
  6721. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6722. {
  6723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6724. goto end;
  6725. }
  6726. }// END FOR GENERAL_GUN_QUANTITY
  6727. for (int index = 0; index < AC_QUANTITY; index++)
  6728. {
  6729. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6730. {
  6731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6732. goto end;
  6733. }
  6734. }//END FOR AC_QUANTITY
  6735. }//END FOR AvailabilityTypeStr[Operative]
  6736. end:
  6737. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6738. {
  6739. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6740. }
  6741. else
  6742. {
  6743. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6744. }
  6745. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6746. {
  6747. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6748. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6749. }
  6750. else if(gunIndex == 0)
  6751. {
  6752. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6753. {
  6754. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6755. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6756. }
  6757. }
  6758. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6759. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6760. return result;
  6761. }
  6762. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6763. {
  6764. mtrace();
  6765. int result = FAIL;
  6766. char keystr[40]={0};
  6767. char valuestr[256]={0};
  6768. char comfirmstr[20]={0};
  6769. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6770. json_object *ChangeConfiguration;
  6771. ChangeConfiguration = json_tokener_parse(payload);
  6772. if(!is_error(ChangeConfiguration))
  6773. {
  6774. // Required data
  6775. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6776. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6777. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6778. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6779. }
  6780. json_object_put(ChangeConfiguration);
  6781. if((uuid==NULL) || (payload ==NULL) )
  6782. {
  6783. DEBUG_ERROR("Payload is null\n");
  6784. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6785. }
  6786. else
  6787. {
  6788. int status = setKeyValue(keystr, valuestr);
  6789. switch(status)
  6790. {
  6791. case ConfigurationStatus_Accepted:
  6792. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6793. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6794. StoreConfigurationTable();
  6795. break;
  6796. case RebootRequired:
  6797. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6798. StoreConfigurationTable();
  6799. break;
  6800. case NotSupported:
  6801. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6802. break;
  6803. case ConfigurationStatus_Rejected:
  6804. default:
  6805. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6806. break;
  6807. }
  6808. }
  6809. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6810. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6811. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6812. {
  6813. ChageWebSocketPingInterval(atoi(valuestr));
  6814. }
  6815. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6816. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6817. {
  6818. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6819. SetOcppConnStatus(FALSE);
  6820. }
  6821. return result;
  6822. }
  6823. int handleClearCacheRequest(char *uuid, char *payload)
  6824. {
  6825. mtrace();
  6826. int result = FAIL;
  6827. char comfirmstr[20];
  6828. char rmFileCmd[100]={0};
  6829. struct stat stats;
  6830. DEBUG_INFO("handleClearCacheRequest...\n");
  6831. stat("/Storage/OCPP", &stats);
  6832. // Check for directory existence
  6833. if (S_ISDIR(stats.st_mode) == 1)
  6834. {}
  6835. else
  6836. {
  6837. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6838. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6839. system(rmFileCmd);
  6840. }
  6841. if(OCPP_cleanLocalCache())
  6842. {
  6843. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6844. }
  6845. else
  6846. {
  6847. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6848. }
  6849. sendClearCacheConfirmation(uuid, comfirmstr);
  6850. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6851. return result;
  6852. }
  6853. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6854. {
  6855. mtrace();
  6856. int result = FAIL;
  6857. int resultRename;
  6858. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6859. char chargingProfilePurposeStr[26]={0};
  6860. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6861. char tempchargingProfilePurposeStr[26]={0};
  6862. char str[100]={0};
  6863. char fname[200]={0};
  6864. char comfirmstr[20]={0};
  6865. char word[1600]={0};
  6866. int clearflag = FALSE;
  6867. int chargingProfileIdIsNULL = FALSE;
  6868. int connectorIsNULL = FALSE;
  6869. int chargingProfilePurposeIsNULL = FALSE;
  6870. int stackLevelIsNULL = FALSE;
  6871. //int GotoEnd = FALSE;
  6872. FILE *fptr1, *fptr2;
  6873. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6874. int n_chargingProfile=0;
  6875. int isEmptyFile = FALSE;
  6876. char sLineWord[1600]={0};
  6877. char chargingProfiles[10][100]={0};
  6878. int ChargeProfileCount = 0;
  6879. int ch;
  6880. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6881. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6882. json_object *ClearChargingProfile;
  6883. ClearChargingProfile = json_tokener_parse(payload);
  6884. if(!is_error(ClearChargingProfile))
  6885. {
  6886. // Optional data
  6887. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6888. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6889. else
  6890. chargingProfileIdIsNULL = TRUE;
  6891. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6892. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6893. else
  6894. connectorIsNULL = TRUE;
  6895. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6896. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6897. else
  6898. chargingProfilePurposeIsNULL = TRUE;
  6899. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6900. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6901. else
  6902. stackLevelIsNULL = TRUE;
  6903. }
  6904. json_object_put(ClearChargingProfile);
  6905. if(connectorIsNULL == FALSE)
  6906. {
  6907. switch(connectorIdInt)
  6908. {
  6909. case 0:
  6910. if(chargingProfilePurposeIsNULL == TRUE)
  6911. {
  6912. int l = 0;
  6913. strcpy(fname, ChargePointMaxProfile_JSON);
  6914. if((access(fname,F_OK))!=-1)
  6915. {
  6916. strcpy(chargingProfiles[l], fname);
  6917. l = l + 1;
  6918. }
  6919. strcpy(fname, TxDefaultProfile_0_JSON);
  6920. if((access(fname,F_OK))!=-1)
  6921. {
  6922. strcpy(chargingProfiles[l], fname);
  6923. l = l + 1;
  6924. }
  6925. ChargeProfileCount = l;
  6926. }
  6927. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6928. {
  6929. strcpy(fname, ChargePointMaxProfile_JSON);
  6930. if((access(fname,F_OK))!=-1)
  6931. {
  6932. strcpy(chargingProfiles[0], fname);
  6933. ChargeProfileCount = 1;
  6934. }
  6935. }
  6936. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6937. {
  6938. strcpy(fname, TxDefaultProfile_0_JSON);
  6939. if((access(fname,F_OK))!=-1)
  6940. {
  6941. strcpy(chargingProfiles[0], fname);
  6942. ChargeProfileCount = 1;
  6943. }
  6944. }
  6945. break;
  6946. default:
  6947. if(chargingProfilePurposeIsNULL == TRUE)
  6948. {
  6949. int m = 0;
  6950. memset(fname, 0, ARRAY_SIZE(fname));
  6951. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6952. if((access(fname,F_OK))!=-1)
  6953. {
  6954. strcpy(chargingProfiles[m], fname);
  6955. m = m + 1;
  6956. }
  6957. memset(fname, 0, ARRAY_SIZE(fname));
  6958. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6959. if((access(fname,F_OK))!=-1)
  6960. {
  6961. strcpy(chargingProfiles[m], fname);
  6962. m = m + 1;
  6963. }
  6964. ChargeProfileCount = m;
  6965. }
  6966. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6967. {
  6968. //strcpy(fname, TxDefaultProfile_1_JSON);
  6969. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6970. if((access(fname,F_OK))!=-1)
  6971. {
  6972. strcpy(chargingProfiles[0], fname);
  6973. ChargeProfileCount = 1;
  6974. }
  6975. }
  6976. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6977. {
  6978. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6979. if((access(fname,F_OK))!=-1)
  6980. {
  6981. strcpy(chargingProfiles[0], fname);
  6982. ChargeProfileCount = 1;
  6983. }
  6984. //strcpy(fname, TxProfile_1_JSON);
  6985. }
  6986. //strcpy(fname, ChargePointMaxProfile_JSON );
  6987. break;
  6988. }
  6989. }
  6990. else // Check all Charging Profiles
  6991. {
  6992. int i = 0;
  6993. char fnametemp[200]={0};
  6994. ChargeProfileCount = 0;
  6995. //Check ChargePointMaxProfile.json exit
  6996. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6997. {
  6998. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6999. i = i + 1;
  7000. }
  7001. //Check TxDefaultProfile_0.json exit
  7002. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7003. {
  7004. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7005. i = i + 1;
  7006. }
  7007. //Check TxDefaultProfile_%d.json
  7008. for(int j=1; j <= gunTotalNumber; j++)
  7009. {
  7010. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7011. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7012. if((access(fnametemp,F_OK))!=-1)
  7013. {
  7014. strcpy(chargingProfiles[i], fnametemp);
  7015. i = i + 1;
  7016. }
  7017. }
  7018. //Check TxProfile_%d.json
  7019. for(int j=1; j <= gunTotalNumber; j++)
  7020. {
  7021. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7022. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7023. if((access(fnametemp,F_OK))!=-1)
  7024. {
  7025. strcpy(chargingProfiles[i], fnametemp);
  7026. i = i + 1;
  7027. }
  7028. }
  7029. ChargeProfileCount = i;
  7030. }// End connectorIsNULL is TRUE
  7031. if(ChargeProfileCount == 0)
  7032. {
  7033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7034. goto end;
  7035. }
  7036. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7037. {
  7038. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7039. goto end;
  7040. }
  7041. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7042. {
  7043. memset(str, 0, ARRAY_SIZE(str));
  7044. // clear temp file
  7045. sprintf(str,"rm -f %s",temp);
  7046. system(str);
  7047. for(int k=0; k < ChargeProfileCount; k++)
  7048. {
  7049. memset(str, 0, ARRAY_SIZE(str));
  7050. //clear file in C
  7051. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7052. system(str);
  7053. }
  7054. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7055. goto end;
  7056. }
  7057. else if(connectorIsNULL == TRUE)
  7058. {
  7059. for(int k=0; k < ChargeProfileCount; k++)
  7060. {
  7061. fptr1 = fopen(chargingProfiles[k], "r");
  7062. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7063. //Check Charging Profile Count
  7064. while(fscanf(fptr1, "%s", word) != EOF)
  7065. {
  7066. //DEBUG_INFO("word=%s\n",word);
  7067. if(strstr(word, "chargingProfileId")!= NULL)
  7068. {
  7069. //DEBUG_INFO("test chargingProfileId \n");
  7070. n_chargingProfile = n_chargingProfile + 1;
  7071. //DEBUG_INFO("chargingProfileId Found\n");
  7072. }
  7073. }
  7074. rewind(fptr1);
  7075. //search Charging Profile Element
  7076. //int i= 0;
  7077. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7078. {
  7079. json_object *tmpProfilee;
  7080. tmpProfilee = json_tokener_parse(sLineWord);
  7081. if(!is_error(tmpProfilee))
  7082. {
  7083. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7084. {
  7085. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7086. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7087. }
  7088. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7089. {
  7090. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7091. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7092. }
  7093. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7094. {
  7095. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7096. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7097. }
  7098. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7099. {
  7100. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7101. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7102. }
  7103. }
  7104. json_object_put(tmpProfilee);
  7105. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7106. {
  7107. //------- not write to fptr2-------//
  7108. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7109. //clearflag = TRUE;
  7110. }
  7111. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7112. {
  7113. //------- not write to fptr2-------//
  7114. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7115. }
  7116. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7117. {
  7118. //------- not write to fptr2-------//
  7119. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7120. }
  7121. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7122. {
  7123. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7124. }
  7125. else
  7126. {
  7127. fprintf(fptr2, sLineWord);//writing data into file
  7128. }
  7129. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7130. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7131. if(clearflag == TRUE)
  7132. {
  7133. fclose(fptr1);
  7134. fclose(fptr2);
  7135. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7136. system(str);
  7137. // clear temp file
  7138. sprintf(str,"rm -f %s",temp);
  7139. system(str);
  7140. }
  7141. else
  7142. {
  7143. fclose(fptr1);
  7144. fclose(fptr2);
  7145. memset(str, 0, ARRAY_SIZE(str));
  7146. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7147. system(str);
  7148. resultRename = rename(temp, chargingProfiles[k]);
  7149. if(resultRename == 0)
  7150. {
  7151. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7152. }
  7153. else
  7154. {
  7155. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7156. }
  7157. if(comfirmstr[0]== 0)
  7158. {
  7159. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7160. }
  7161. //Check chargingProfile is empty file
  7162. /*------ Read the file ----------------*/
  7163. fptr1=fopen(chargingProfiles[k],"r");
  7164. ch=fgetc(fptr1);
  7165. rewind(fptr1);
  7166. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7167. if(ch!=EOF)
  7168. {
  7169. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7170. {
  7171. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7172. if(sLineWord[0]=='\0')
  7173. {
  7174. isEmptyFile = TRUE;
  7175. break;
  7176. }
  7177. else
  7178. {
  7179. isEmptyFile = FALSE;
  7180. break;
  7181. }
  7182. }
  7183. }
  7184. else
  7185. isEmptyFile = TRUE;
  7186. fclose(fptr1);
  7187. if(isEmptyFile == TRUE)
  7188. {
  7189. memset(str, 0, ARRAY_SIZE(str));
  7190. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7191. system(str);
  7192. }
  7193. }
  7194. }// End of while(int k=0; k < ChargePointCount; k++)
  7195. }
  7196. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7197. {
  7198. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7199. for(int k=0; k < ChargeProfileCount; k++)
  7200. {
  7201. fptr1 = fopen(chargingProfiles[k], "r");
  7202. fptr2 = fopen(temp, "w+");
  7203. //Check Charging Profile Count
  7204. while(fscanf(fptr1, "%s", word) != EOF)
  7205. {
  7206. //DEBUG_INFO("word=%s\n",word);
  7207. if(strstr(word, "chargingProfileId")!= NULL)
  7208. {
  7209. n_chargingProfile = n_chargingProfile + 1;
  7210. }
  7211. }
  7212. rewind(fptr1);
  7213. //search Charging Profile Element
  7214. //int i= 0;
  7215. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7216. {
  7217. json_object *tmpProfilee;
  7218. tmpProfilee = json_tokener_parse(sLineWord);
  7219. if(!is_error(tmpProfilee))
  7220. {
  7221. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7222. {
  7223. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7224. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7225. }
  7226. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7227. {
  7228. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7229. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7230. }
  7231. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7232. {
  7233. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7234. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7235. }
  7236. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7237. {
  7238. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7239. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7240. }
  7241. }
  7242. json_object_put(tmpProfilee);
  7243. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7244. {
  7245. //------- not write to fptr2-------//
  7246. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7247. //clearflag = TRUE;
  7248. }
  7249. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7250. {
  7251. //------- not write to fptr2-------//
  7252. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7253. }
  7254. else if(stackLevelIsNULL == TRUE)
  7255. {
  7256. //Clear Whole File
  7257. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7258. clearflag = TRUE;
  7259. break;
  7260. }
  7261. else
  7262. {
  7263. fprintf(fptr2, sLineWord);//writing data into file
  7264. }
  7265. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7266. }
  7267. if(clearflag == TRUE)
  7268. {
  7269. fclose(fptr1);
  7270. fclose(fptr2);
  7271. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7272. system(str);
  7273. // clear temp file
  7274. sprintf(str,"rm -f %s",temp);
  7275. system(str);
  7276. }
  7277. else
  7278. {
  7279. fclose(fptr1);
  7280. fclose(fptr2);
  7281. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7282. system(str);
  7283. resultRename = rename(temp, chargingProfiles[k]);
  7284. if(resultRename == 0)
  7285. {
  7286. DEBUG_INFO("File ChargingProfile renamed successfully");
  7287. }
  7288. else
  7289. {
  7290. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7291. }
  7292. if(comfirmstr[0]== 0)
  7293. {
  7294. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7295. }
  7296. //Check chargingProfile is empty file
  7297. /*------ Read the file ----------------*/
  7298. fptr1=fopen(chargingProfiles[k],"r");
  7299. ch=fgetc(fptr1);
  7300. rewind(fptr1);
  7301. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7302. if(ch!=EOF)
  7303. {
  7304. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7305. {
  7306. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7307. if(sLineWord[0]=='\0')
  7308. {
  7309. isEmptyFile = TRUE;
  7310. break;
  7311. }
  7312. else
  7313. {
  7314. isEmptyFile = FALSE;
  7315. break;
  7316. }
  7317. }
  7318. }
  7319. else
  7320. isEmptyFile = TRUE;
  7321. fclose(fptr1);
  7322. if(isEmptyFile == TRUE)
  7323. {
  7324. memset(str, 0, ARRAY_SIZE(str));
  7325. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7326. system(str);
  7327. }
  7328. /*------- End of reading ---------------*/
  7329. }
  7330. } // while(int k=0; k < ChargeProfileCount; k++)
  7331. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7332. end:
  7333. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7334. {
  7335. if(connectorIdInt == 0)
  7336. {
  7337. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7338. {
  7339. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7340. }
  7341. }
  7342. else
  7343. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7344. }
  7345. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7346. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7347. return result;
  7348. }
  7349. void createFirmwareVersionByDataTransfer(void)
  7350. {
  7351. json_object *FirmwareDataTransfer = json_object_new_object();
  7352. // AC & DC model
  7353. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7354. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7355. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7356. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7357. // DC model
  7358. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7359. {
  7360. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7361. {
  7362. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7363. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7364. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7365. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7366. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7367. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7368. }
  7369. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7370. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7371. {
  7372. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7373. }
  7374. }
  7375. else
  7376. {
  7377. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7378. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  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. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7382. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7383. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7384. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7387. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7390. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7391. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7392. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7393. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7394. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7395. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7396. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7397. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7398. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7399. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7400. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7401. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7402. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7403. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7404. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7405. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7406. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7407. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7408. }
  7409. // 4G model
  7410. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7411. {
  7412. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7413. }
  7414. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7415. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7416. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7417. json_object_put(FirmwareDataTransfer);
  7418. }
  7419. int handleDataTransferRequest(char *uuid, char *payload)
  7420. {
  7421. mtrace();
  7422. json_object *response = json_object_new_object();
  7423. int result = FAIL;
  7424. char tempvendorId[255]={0};
  7425. char tempmessageId[50]={0};
  7426. char tempdata[512]={0};
  7427. char message[2048]={0};
  7428. DEBUG_INFO("handleDataTransferRequest...\n");
  7429. if((uuid != NULL) && (payload != NULL))
  7430. {
  7431. json_object *DataTransfer;
  7432. DataTransfer = json_tokener_parse(payload);
  7433. if(!is_error(DataTransfer))
  7434. {
  7435. // Required data
  7436. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7437. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7438. // Optional data
  7439. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7440. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7441. if(json_object_object_get(DataTransfer, "data") != NULL)
  7442. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7443. result = PASS;
  7444. }
  7445. json_object_put(DataTransfer);
  7446. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7447. {
  7448. // Send all moudle firmware version on EVSE
  7449. createFirmwareVersionByDataTransfer();
  7450. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7451. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7452. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7453. json_object_put(response);
  7454. }
  7455. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7456. {
  7457. system("/usr/bin/run_tmate_restart.sh &");
  7458. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7459. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7460. json_object_put(response);
  7461. }
  7462. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7463. {
  7464. json_object *data;
  7465. data = json_tokener_parse(tempdata);
  7466. if(!is_error(data))
  7467. {
  7468. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7469. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7470. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7471. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7472. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7473. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7474. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7475. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7476. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7477. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7478. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7479. }
  7480. else
  7481. {
  7482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7483. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7484. }
  7485. json_object_put(data);
  7486. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7487. json_object_put(response);
  7488. }
  7489. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7490. {
  7491. json_object *data;
  7492. data = json_tokener_parse(tempdata);
  7493. if(!is_error(data))
  7494. {
  7495. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7496. if(json_object_object_get(data, "idToken") != NULL)
  7497. {
  7498. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7499. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7500. }
  7501. if(json_object_object_get(data, "price") != NULL)
  7502. {
  7503. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7504. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7505. }
  7506. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7507. }
  7508. else
  7509. {
  7510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7511. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7512. }
  7513. json_object_put(data);
  7514. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7515. json_object_put(response);
  7516. }
  7517. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7518. {
  7519. json_object *data;
  7520. data = json_tokener_parse(tempdata);
  7521. if(!is_error(data))
  7522. {
  7523. if(json_object_object_get(data, "txId") != NULL)
  7524. {
  7525. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7526. for(int idx = 0;idx<gunTotalNumber;idx++)
  7527. {
  7528. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7529. {
  7530. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7531. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7532. if(json_object_object_get(data, "description") != NULL)
  7533. {
  7534. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7535. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7536. }
  7537. }
  7538. }
  7539. }
  7540. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7541. }
  7542. else
  7543. {
  7544. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7545. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7546. }
  7547. json_object_put(data);
  7548. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7549. json_object_put(response);
  7550. }
  7551. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7552. {
  7553. json_object *data;
  7554. data = json_tokener_parse(tempdata);
  7555. if(!is_error(data))
  7556. {
  7557. if(json_object_object_get(data, "txId") != NULL)
  7558. {
  7559. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7560. for(int idx = 0;idx<gunTotalNumber;idx++)
  7561. {
  7562. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7563. {
  7564. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7565. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7566. if(json_object_object_get(data, "description") != NULL)
  7567. {
  7568. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7569. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7570. }
  7571. }
  7572. }
  7573. }
  7574. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7575. }
  7576. else
  7577. {
  7578. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7579. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7580. }
  7581. json_object_put(data);
  7582. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7583. json_object_put(response);
  7584. }
  7585. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7586. {
  7587. json_object *data;
  7588. data = json_tokener_parse(tempdata);
  7589. if(!is_error(data))
  7590. {
  7591. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7592. if(json_object_object_get(data, "Content_Type") != NULL)
  7593. {
  7594. 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))
  7595. {
  7596. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7597. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7598. {
  7599. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7600. }
  7601. }
  7602. else
  7603. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7604. }
  7605. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7606. }
  7607. else
  7608. {
  7609. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7610. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7611. }
  7612. json_object_put(data);
  7613. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7614. json_object_put(response);
  7615. }
  7616. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7617. {
  7618. json_object *data;
  7619. data = json_tokener_parse(tempdata);
  7620. if(!is_error(data))
  7621. {
  7622. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7623. if(json_object_object_get(data, "Page_Index") != NULL)
  7624. {
  7625. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7626. }
  7627. if(json_object_object_get(data, "Duration") != NULL)
  7628. {
  7629. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7630. }
  7631. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7632. }
  7633. else
  7634. {
  7635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7636. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7637. }
  7638. json_object_put(data);
  7639. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7640. json_object_put(response);
  7641. }
  7642. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7643. {
  7644. json_object *data;
  7645. data = json_tokener_parse(tempdata);
  7646. if(!is_error(data))
  7647. {
  7648. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7649. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7650. {
  7651. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7652. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7653. else
  7654. {
  7655. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7656. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7657. }
  7658. }
  7659. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7660. {
  7661. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7662. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7663. else
  7664. {
  7665. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7666. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7667. }
  7668. }
  7669. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7670. {
  7671. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7672. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7673. else
  7674. {
  7675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7676. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7677. }
  7678. }
  7679. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7680. {
  7681. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7682. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7683. else
  7684. {
  7685. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7686. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7687. }
  7688. }
  7689. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7690. {
  7691. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7692. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7693. else
  7694. {
  7695. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7696. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7697. }
  7698. }
  7699. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7700. {
  7701. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7702. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7703. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7704. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7705. else
  7706. {
  7707. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7708. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7709. }
  7710. }
  7711. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7712. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7713. }
  7714. else
  7715. {
  7716. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7717. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7718. }
  7719. json_object_put(data);
  7720. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7721. json_object_put(response);
  7722. }
  7723. else
  7724. {
  7725. // Can not find valid message id
  7726. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7727. }
  7728. }
  7729. else
  7730. {
  7731. // Payload is null
  7732. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7733. }
  7734. LWS_Send(message);
  7735. return result;
  7736. }
  7737. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7738. {
  7739. mtrace();
  7740. int result = FAIL;
  7741. int connectorIdInt, durationInt;
  7742. char chargingRateUnitStr[4]={0};
  7743. char comfirmstr[20];
  7744. int confirmPeriods = 0;
  7745. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7746. json_object *GetCompositeSchedule;
  7747. GetCompositeSchedule = json_tokener_parse(payload);
  7748. if(!is_error(GetCompositeSchedule))
  7749. {
  7750. // Required data
  7751. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7752. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7753. else
  7754. connectorIdInt = -1;
  7755. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7756. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7757. else
  7758. durationInt = 86400;
  7759. // Optional data
  7760. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7761. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7762. }
  7763. json_object_put(GetCompositeSchedule);
  7764. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7765. if((connectorIdInt == 0) ||
  7766. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7767. {
  7768. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7769. struct StructChargingProfile tmpProfile[1];
  7770. if(strstr(chargingRateUnitStr, "W") != NULL)
  7771. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7772. else
  7773. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7774. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7775. {
  7776. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7777. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7778. }
  7779. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7780. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7781. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7782. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7783. {
  7784. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7785. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7786. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7787. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7788. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7789. {
  7790. confirmPeriods = idx;
  7791. break;
  7792. }
  7793. }
  7794. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7795. {
  7796. confirmPeriods += 1;
  7797. }
  7798. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7799. }
  7800. else
  7801. {
  7802. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7803. }
  7804. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7805. return result;
  7806. }
  7807. int handleGetConfigurationRequest(char *uuid, char *payload)
  7808. {
  7809. mtrace();
  7810. int result = FAIL;
  7811. int MaxKeySupported = 0;
  7812. int n_keys = 0;
  7813. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7814. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7815. json_object *GetConfiguration;
  7816. GetConfiguration = json_tokener_parse(payload);
  7817. if(!is_error(GetConfiguration))
  7818. {
  7819. // Optional data
  7820. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7821. {
  7822. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7823. {
  7824. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7825. n_keys = idx + 1;
  7826. }
  7827. }
  7828. }
  7829. json_object_put(GetConfiguration);
  7830. UnknownKeynum = 0;
  7831. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7832. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7833. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7834. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7835. if(n_keys != 0)
  7836. {
  7837. for(int i=0;i<n_keys;i++)
  7838. {
  7839. getKeyValue(requestKey[i]);
  7840. }
  7841. }
  7842. else
  7843. {
  7844. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7845. getKeyValue("");
  7846. }
  7847. processUnkownKey();
  7848. sendGetConfigurationConfirmation(uuid);
  7849. return result;
  7850. }
  7851. static char fnamePlusPath[100]={0};
  7852. static char fnamePWithNoPath[60]={0};
  7853. void checkUploadLog(void)
  7854. {
  7855. FILE *fp;
  7856. /* Open the command for reading. */
  7857. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7858. if (fp == NULL) {
  7859. printf("Failed to run command\n" );
  7860. exit(1);
  7861. }
  7862. int ftppathlen = 0;
  7863. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7864. int i = 0;
  7865. /* Read the output a line at a time - output it. */
  7866. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7867. if(i==0)
  7868. {
  7869. ftppathlen = strlen(fnamePlusPath);
  7870. printf("%s\n", fnamePlusPath);
  7871. fnamePlusPath[ftppathlen]='\0';
  7872. break;
  7873. }
  7874. i= i+1;
  7875. }
  7876. /* close */
  7877. pclose(fp);
  7878. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7879. {
  7880. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7881. {
  7882. fnamePlusPath[k]='\0';
  7883. }
  7884. }
  7885. i=1;
  7886. //char fname[60]={0};
  7887. while(i < ftppathlen)
  7888. {
  7889. int len=ftppathlen-i;
  7890. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7891. {
  7892. printf("compare '/' all right\n");
  7893. break;
  7894. }
  7895. i=i+1;
  7896. }
  7897. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7898. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7899. fnamePWithNoPath[i+1] = '\0';
  7900. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7901. {
  7902. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7903. {
  7904. fnamePWithNoPath[j]='\0';
  7905. }
  7906. }
  7907. FILE* fp1 = fopen(fnamePlusPath, "r");
  7908. if (fp1)
  7909. {
  7910. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7911. // file exists
  7912. fclose(fp1);
  7913. }
  7914. else
  7915. {
  7916. // file doesn't exist
  7917. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7918. }
  7919. }
  7920. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7921. {
  7922. mtrace();
  7923. int result = FAIL;
  7924. time_t CurrentTime;
  7925. struct tm *tm;
  7926. pthread_t th_Status;
  7927. CurrentTime = time(NULL);
  7928. tm = localtime(&CurrentTime);
  7929. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7930. 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);
  7931. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7932. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7933. return result;
  7934. }
  7935. void* GetDiagnosticsProcess(void* data)
  7936. {
  7937. pthread_detach(pthread_self());
  7938. mtrace();
  7939. int retriesInt=0, retryIntervalInt=0;
  7940. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7941. 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};
  7942. int port=0;
  7943. int isSuccess = FALSE;
  7944. char cmdBuf[2048];
  7945. struct tm *tmNow;
  7946. time_t CurrentTime;
  7947. struct tm tmStart;
  7948. struct tm tmStop;
  7949. CurrentTime = time(NULL);
  7950. tmNow=localtime(&CurrentTime);
  7951. uint16_t targetYear, targetMonth;
  7952. json_object *GetDiagnostics;
  7953. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7954. GetDiagnostics = json_tokener_parse(data);
  7955. if(!is_error(GetDiagnostics))
  7956. {
  7957. // Required data
  7958. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7959. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7960. // Optional data
  7961. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7962. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7963. else
  7964. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7965. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7966. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7967. else
  7968. retryIntervalInt = 30;
  7969. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7970. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7971. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7972. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7973. }
  7974. json_object_put(GetDiagnostics);
  7975. // Pack log to compress file
  7976. 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) &&
  7977. (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))
  7978. {
  7979. // Pack system log
  7980. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7981. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7982. targetYear = tmStart.tm_year;
  7983. targetMonth = tmStart.tm_mon;
  7984. do
  7985. {
  7986. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7987. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7988. if(targetMonth+1>=13)
  7989. {
  7990. targetYear += 1;
  7991. targetMonth = 1;
  7992. }
  7993. else
  7994. {
  7995. targetMonth += 1;
  7996. }
  7997. }while((targetYear < (tmNow->tm_year+1900)) ||
  7998. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7999. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8000. system(cmdBuf);
  8001. // Pack charging & event log
  8002. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8003. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8004. targetYear = tmStart.tm_year;
  8005. targetMonth = tmStart.tm_mon;
  8006. do
  8007. {
  8008. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8009. if(targetMonth+1>=13)
  8010. {
  8011. targetYear += 1;
  8012. targetMonth = 1;
  8013. }
  8014. else
  8015. {
  8016. targetMonth += 1;
  8017. }
  8018. }while((targetYear < (tmNow->tm_year+1900)) ||
  8019. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8020. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8021. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8022. system(cmdBuf);
  8023. // Combine log file
  8024. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8025. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8026. }
  8027. else
  8028. {
  8029. system("exec /root/logPackTools 'log' 6");
  8030. }
  8031. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8032. system(cmdBuf);
  8033. checkUploadLog();
  8034. //****************location*******************/
  8035. if(strcmp(locationstr,"")==0)
  8036. {
  8037. DEBUG_INFO("location is <Empty>!\n");
  8038. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8039. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8040. goto end;
  8041. }
  8042. memset(protocol, 0, ARRAY_SIZE(protocol));
  8043. memset(user, 0, ARRAY_SIZE(user) );
  8044. memset(password, 0, ARRAY_SIZE(password));
  8045. memset(host, 0, ARRAY_SIZE(host));
  8046. memset(path, 0, ARRAY_SIZE(path));
  8047. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8048. memset(host1, 0, ARRAY_SIZE(host1));
  8049. memset(path1, 0, ARRAY_SIZE(path1));
  8050. /*location: ftp://user:password@host:port/path*/
  8051. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8052. if((access(fnamePlusPath,F_OK))!=-1)
  8053. {
  8054. DEBUG_INFO("fnamePlusPath exist.\n");
  8055. }
  8056. else
  8057. {
  8058. DEBUG_INFO("fnamePlusPath not exist!\n");
  8059. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8060. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8061. goto end;
  8062. }
  8063. if(strchr(locationstr,'@')==NULL)
  8064. {
  8065. sscanf(locationstr,
  8066. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8067. protocol, host, &port, path);
  8068. strcpy(user,"anonymous");
  8069. strcpy(password,"");
  8070. }
  8071. else
  8072. {
  8073. //DEBUG_INFO("pch=%s\n", pch);
  8074. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8075. protocol, user, password, host, &port, path);
  8076. }
  8077. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8078. {
  8079. DEBUG_INFO("protocol is not ftp/http ! \n");
  8080. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8081. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8082. goto end;
  8083. }
  8084. if(strncmp(locationstr,"http", 4) == 0)
  8085. {
  8086. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8087. sprintf(ftppath,"/%s", path);
  8088. do
  8089. {
  8090. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8091. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8092. sleep(3);
  8093. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8094. if(!isSuccess)
  8095. {
  8096. DEBUG_INFO("Diagnostics fail.\n");
  8097. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8098. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8099. sleep(retryIntervalInt);
  8100. }
  8101. else
  8102. {
  8103. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8104. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8105. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8106. }
  8107. retriesInt--;
  8108. }while((isSuccess == 0)&&(retriesInt >= 0));
  8109. }
  8110. else
  8111. {
  8112. sscanf(host,"%[^/]%s",host1, path1);
  8113. if(strlen(path) > 0)
  8114. sprintf(ftppath,"/%s", path);
  8115. else
  8116. sprintf(ftppath,"/%s", path1);
  8117. int ftppathlen=strlen(ftppath);
  8118. int i=1;
  8119. char filenametemp[50];
  8120. while(i < ftppathlen)
  8121. {
  8122. int len=ftppathlen-i;
  8123. if(ftppath[len]== 47) // '/' ascll code: 47
  8124. {
  8125. DEBUG_INFO("find '/' all right\n");
  8126. break;
  8127. }
  8128. i=i+1;
  8129. }
  8130. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8131. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8132. filenametemp[i+1] = 0;
  8133. if(port == 0)
  8134. port = 21;
  8135. do
  8136. {
  8137. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8138. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8139. sleep(3);
  8140. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8141. if(!isSuccess)
  8142. {
  8143. DEBUG_INFO("Diagnostics fail.\n");
  8144. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8145. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8146. sleep(retryIntervalInt);
  8147. }
  8148. else
  8149. {
  8150. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8151. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8152. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8153. }
  8154. retriesInt--;
  8155. }while((!isSuccess)&&(retriesInt >= 0));
  8156. }
  8157. end:
  8158. system("rm -f /mnt/*");
  8159. sleep(5);
  8160. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8161. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8162. pthread_exit(NULL);
  8163. }
  8164. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8165. {
  8166. mtrace();
  8167. int result = FAIL;
  8168. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8169. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8170. {
  8171. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8172. localversion = -1;
  8173. }
  8174. else
  8175. {
  8176. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8177. OCPP_getListVerion();
  8178. }
  8179. //from db.OCPP_getListVerion
  8180. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  8181. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8182. sendGetLocalListVersionConfirmation(uuid,"");
  8183. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8184. return result;
  8185. }
  8186. int handleRemoteStartRequest(char *uuid, char *payload)
  8187. {
  8188. mtrace();
  8189. int result = FAIL;
  8190. int connectorIdInt=0;
  8191. int tempIndex = 0;
  8192. int connectorIdIsNULL, chargingProfileIsNULL;
  8193. char comfirmstr[20]={0};
  8194. char cmdBuf[512];
  8195. json_object *RemoteStartTransaction;
  8196. FILE *fp;
  8197. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8198. if(server_pending == TRUE)
  8199. {
  8200. return 0;
  8201. }
  8202. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8203. RemoteStartTransaction = json_tokener_parse(payload);
  8204. if(!is_error(RemoteStartTransaction))
  8205. {
  8206. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8207. {
  8208. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8209. if(connectorIdInt <= gunTotalNumber)
  8210. {
  8211. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8212. // Required data
  8213. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8214. // Optional data
  8215. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8216. {
  8217. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8218. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8219. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8220. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8221. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8222. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8223. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8224. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8225. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8226. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8227. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8228. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8229. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8230. {
  8231. 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")));
  8232. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8233. 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"));
  8234. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8235. 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"));
  8236. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8237. 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")));
  8238. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8239. {
  8240. 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++)
  8241. {
  8242. 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"));
  8243. 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"));
  8244. 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)
  8245. 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"));
  8246. }
  8247. }
  8248. }
  8249. }
  8250. else
  8251. chargingProfileIsNULL = TRUE;
  8252. }
  8253. }
  8254. else
  8255. connectorIdIsNULL = TRUE;
  8256. }
  8257. else
  8258. connectorIdIsNULL = TRUE;
  8259. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8260. {
  8261. DEBUG_WARN("Connector id is NULL\n.");
  8262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8263. goto end;
  8264. }
  8265. /*
  8266. enum _SYSTEM_STATUS
  8267. {
  8268. S_BOOTING = 0,
  8269. S_IDLE, = 1
  8270. S_AUTHORIZING, = 2
  8271. S_REASSIGN_CHECK, = 3
  8272. S_REASSIGN, = 4
  8273. S_PRECHARGE, = 5
  8274. S_PREPARING_FOR_EV, = 6
  8275. S_PREPARING_FOR_EVSE, = 7
  8276. S_CHARGING, = 8
  8277. S_TERMINATING, = 9
  8278. S_COMPLETE, = 10
  8279. S_ALARM, = 11
  8280. S_FAULT = 12
  8281. }
  8282. */
  8283. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8284. {
  8285. //check Transaction active
  8286. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8287. {
  8288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8289. {
  8290. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8291. }
  8292. else
  8293. {
  8294. tempIndex = connectorIdInt -1;
  8295. }
  8296. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8297. {
  8298. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8299. {
  8300. 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))
  8301. {
  8302. //Reserved
  8303. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8304. }
  8305. 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))
  8306. {
  8307. //Reserved
  8308. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8309. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8310. goto end;
  8311. }
  8312. else
  8313. {
  8314. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8315. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8316. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8317. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8318. {
  8319. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8320. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8321. goto end;
  8322. }
  8323. }//END FOR ELSE
  8324. }
  8325. }// END FOR CHAdeMO_QUANTITY
  8326. }
  8327. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8328. {
  8329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8330. {
  8331. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8332. }
  8333. else
  8334. {
  8335. tempIndex = connectorIdInt -1;
  8336. }
  8337. for (int index = 0; index < CCS_QUANTITY; index++)
  8338. {
  8339. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8340. {
  8341. 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))
  8342. {
  8343. //Reserved
  8344. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8345. }
  8346. 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))
  8347. {
  8348. //Reserved
  8349. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8350. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8351. goto end;
  8352. }
  8353. else
  8354. {
  8355. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8356. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8357. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8358. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8359. {
  8360. DEBUG_WARN("CCS connector not allow start\n.");
  8361. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8362. goto end;
  8363. }
  8364. }// END FOR ELSE
  8365. }
  8366. }// END FOR CCS_QUANTITY
  8367. }
  8368. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8369. {
  8370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8371. {
  8372. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8373. }
  8374. else
  8375. {
  8376. tempIndex = connectorIdInt -1;
  8377. }
  8378. for (int index = 0; index < GB_QUANTITY; index++)
  8379. {
  8380. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8381. {
  8382. 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))
  8383. {
  8384. //Reserved
  8385. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8386. }
  8387. 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))
  8388. {
  8389. //Reserved
  8390. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8391. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8392. goto end;
  8393. }
  8394. else
  8395. {
  8396. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8397. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8398. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8399. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8400. {
  8401. DEBUG_WARN("GB connector not allow start\n.");
  8402. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8403. goto end;
  8404. }
  8405. }// END FOR ELSE
  8406. }
  8407. } // END FOR GB_QUANTITY
  8408. }
  8409. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8410. {
  8411. tempIndex = connectorIdInt -1;
  8412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8413. {
  8414. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8415. {
  8416. 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))
  8417. {
  8418. //Reserved
  8419. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8420. }
  8421. 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))
  8422. {
  8423. //Reserved
  8424. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8425. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8426. goto end;
  8427. }
  8428. else
  8429. {
  8430. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8431. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8432. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8433. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8434. {
  8435. DEBUG_WARN("GB connector not allow start\n.");
  8436. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8437. goto end;
  8438. }
  8439. }// END FOR ELSE
  8440. }
  8441. } // END FOR GB_QUANTITY
  8442. }
  8443. else
  8444. {
  8445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8446. {
  8447. tempIndex = 2;
  8448. }
  8449. else
  8450. {
  8451. tempIndex = connectorIdInt -1;
  8452. }
  8453. for (int index = 0; index < AC_QUANTITY; index++)
  8454. {
  8455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8456. {
  8457. 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))
  8458. {
  8459. //Reserved
  8460. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8461. }
  8462. 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))
  8463. {
  8464. //Reserved
  8465. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8466. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8467. goto end;
  8468. }
  8469. else
  8470. {
  8471. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8472. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8473. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8474. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8475. {
  8476. DEBUG_WARN("AC connector not allow start\n.");
  8477. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8478. goto end;
  8479. }
  8480. }//END FOR ELSE
  8481. }
  8482. }// END FOR AC_QUANTITY
  8483. }
  8484. if(chargingProfileIsNULL == FALSE)
  8485. {
  8486. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8487. {
  8488. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8489. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8490. //memset idTag
  8491. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8492. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8493. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8494. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8495. // Save profile to file
  8496. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8497. system(cmdBuf);
  8498. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8499. fp = fopen(cmdBuf, "w");
  8500. 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));
  8501. fclose(fp);
  8502. }
  8503. else
  8504. {
  8505. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8506. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8507. }
  8508. }
  8509. else
  8510. {
  8511. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8512. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8513. //memset idTag
  8514. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8515. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8516. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8517. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8518. }
  8519. }
  8520. else
  8521. {
  8522. DEBUG_WARN("Connector id over\n.");
  8523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8524. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8525. }
  8526. end:
  8527. json_object_put(RemoteStartTransaction);
  8528. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8529. {
  8530. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8531. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8532. }
  8533. //OCPP send RemoteStartConfirmation by first.
  8534. sendRemoteStartConfirmation(uuid, comfirmstr);
  8535. return result;
  8536. }
  8537. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8538. {
  8539. mtrace();
  8540. int result = FAIL;
  8541. int match = FALSE;
  8542. int GunNO = 0;
  8543. int tempIndex = 0;
  8544. int transactionIdInt=0;
  8545. int transactionIdIsNULL= TRUE;
  8546. char comfirmstr[20];
  8547. json_object *RemoteStopTransaction;
  8548. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8549. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8550. if(server_pending == TRUE)
  8551. {
  8552. return 0;
  8553. }
  8554. RemoteStopTransaction = json_tokener_parse(payload);
  8555. if(!is_error(RemoteStopTransaction))
  8556. {
  8557. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8558. {
  8559. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8560. transactionIdIsNULL = FALSE;
  8561. }
  8562. }
  8563. json_object_put(RemoteStopTransaction);
  8564. if(transactionIdIsNULL == FALSE)
  8565. {
  8566. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8567. {
  8568. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8569. {
  8570. //check Transaction active
  8571. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8572. {
  8573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8574. {
  8575. tempIndex = ((gun_index==2) ? 1: 0);
  8576. }
  8577. else
  8578. {
  8579. tempIndex = gun_index;
  8580. }
  8581. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8582. {
  8583. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8584. {
  8585. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8586. {
  8587. match = TRUE;
  8588. GunNO = gun_index;
  8589. }
  8590. }
  8591. }// END FOR CHAdeMO_QUANTITY
  8592. }
  8593. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8594. {
  8595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8596. {
  8597. tempIndex = ((gun_index==2) ? 1: 0);
  8598. }
  8599. else
  8600. {
  8601. tempIndex = gun_index;
  8602. }
  8603. for (int index = 0; index < CCS_QUANTITY; index++)
  8604. {
  8605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8606. {
  8607. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8608. {
  8609. match = TRUE;
  8610. GunNO = gun_index;
  8611. }
  8612. }
  8613. }// END FOR CCS_QUANTITY
  8614. }
  8615. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8616. {
  8617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8618. {
  8619. tempIndex = ((gun_index==2) ? 1: 0);
  8620. }
  8621. else
  8622. {
  8623. tempIndex = gun_index;
  8624. }
  8625. for (int index = 0; index < GB_QUANTITY; index++)
  8626. {
  8627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8628. {
  8629. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8630. {
  8631. match = TRUE;
  8632. GunNO = gun_index;
  8633. }
  8634. }
  8635. }// END FOR GB_QUANTITY
  8636. }
  8637. else if(gunType[gun_index] == GUN_TYPE_DO)
  8638. {
  8639. tempIndex = gun_index;
  8640. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8641. {
  8642. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8643. {
  8644. 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
  8645. {
  8646. match = TRUE;
  8647. GunNO = gun_index;
  8648. }
  8649. }
  8650. }// END FOR GB_QUANTITY
  8651. }
  8652. else
  8653. {
  8654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8655. {
  8656. tempIndex = 2;
  8657. }
  8658. else
  8659. {
  8660. tempIndex = gun_index;
  8661. }
  8662. for (int index = 0; index < AC_QUANTITY; index++)
  8663. {
  8664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8665. {
  8666. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8667. {
  8668. match = TRUE;
  8669. GunNO = gun_index;
  8670. }
  8671. }
  8672. }// END FOR CHAdeMO_QUANTITY
  8673. } // END FOR AC ELSE
  8674. }// CHECK IF ResponseTransactionId == transactionIdInt
  8675. }//END FOR
  8676. if( match == TRUE)
  8677. {
  8678. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8680. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8681. }
  8682. else
  8683. {
  8684. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8685. }
  8686. }
  8687. else
  8688. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8689. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8690. return result;
  8691. }
  8692. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8693. {
  8694. mtrace();
  8695. int result = FAIL;
  8696. int connectorIdInt=0, reservationIdInt=0;
  8697. int tempIndex = 0;
  8698. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8699. char comfirmstr[20]={0};
  8700. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8701. int c = 0;
  8702. char *loc;
  8703. //char *ptr;
  8704. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8705. strcpy(sstrtemp, stringtrimspace(payload));
  8706. //***(1)connectorId ****/
  8707. c=0;
  8708. loc = strstr(sstrtemp, "connectorId");
  8709. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8710. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8711. {
  8712. sstr[c] = loc[strlen("connectorId")+2+c];
  8713. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8714. c++;
  8715. }
  8716. sstr[c] = '\0';
  8717. connectorIdInt = atoi(sstr);
  8718. //***(2)expiryDate ****/
  8719. loc = strstr(sstrtemp, "expiryDate");
  8720. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8721. c = 0;
  8722. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8723. {
  8724. sstr[c] = loc[3+strlen("expiryDate")+c];
  8725. c++;
  8726. }
  8727. sstr[c] = '\0';
  8728. strcpy(expiryDatestr, sstr);
  8729. //***(3)idTag ****/
  8730. loc = strstr(sstrtemp, "idTag");
  8731. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8732. c = 0;
  8733. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8734. {
  8735. sstr[c] = loc[3+strlen("idTag")+c];
  8736. c++;
  8737. }
  8738. sstr[c] = '\0';
  8739. strcpy(idTagstr, sstr);
  8740. //***(4)parentIdTag ****/
  8741. loc = strstr(sstrtemp, "parentIdTag");
  8742. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8743. c = 0;
  8744. if(loc == NULL)
  8745. {
  8746. strcpy(parentIdTagstr, "");
  8747. }
  8748. else
  8749. {
  8750. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8751. {
  8752. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8753. c++;
  8754. }
  8755. sstr[c] = '\0';
  8756. strcpy(parentIdTagstr, sstr);
  8757. }
  8758. //***(5)reservationId ****/
  8759. c=0;
  8760. loc = strstr(sstrtemp, "reservationId");
  8761. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8762. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8763. {
  8764. sstr[c] = loc[strlen("reservationId")+2+c];
  8765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8766. c++;
  8767. }
  8768. sstr[c] = '\0';
  8769. reservationIdInt = atoi(sstr);
  8770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8771. /*
  8772. enum SYSTEM_STATUS
  8773. {
  8774. SYS_MODE_BOOTING = 0,
  8775. SYS_MODE_IDLE = 1,
  8776. SYS_MODE_AUTHORIZING = 2,
  8777. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8778. SYS_MODE_REASSIGN = 4,
  8779. SYS_MODE_PREPARING = 5,
  8780. SYS_MODE_PREPARE_FOR_EV = 6,
  8781. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8782. SYS_MODE_CHARGING = 8,
  8783. SYS_MODE_TERMINATING = 9,
  8784. SYS_MODE_COMPLETE = 10,
  8785. SYS_MODE_ALARM = 11,
  8786. SYS_MODE_FAULT = 12,
  8787. SYS_MODE_RESERVATION = 13,
  8788. SYS_MODE_BOOKING = 14,
  8789. SYS_MODE_MAINTAIN = 15,
  8790. SYS_MODE_DEBUG = 16,
  8791. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8792. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8793. SYS_MODE_UPDATE = 19
  8794. };
  8795. */
  8796. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8797. {
  8798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8799. goto end;
  8800. }
  8801. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8802. {
  8803. //check Transaction active
  8804. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8805. {
  8806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8807. {
  8808. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8809. }
  8810. else
  8811. {
  8812. tempIndex = connectorIdInt -1;
  8813. }
  8814. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8815. {
  8816. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8817. {
  8818. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8819. {
  8820. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8821. {
  8822. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8823. {
  8824. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8826. }
  8827. 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'))
  8828. {
  8829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8830. }
  8831. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8832. {
  8833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8834. }
  8835. else
  8836. {
  8837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8838. }
  8839. }
  8840. 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
  8841. {
  8842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8843. }
  8844. }
  8845. else
  8846. {
  8847. //replace reservation
  8848. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8850. }
  8851. }
  8852. } // END FOR CHAdeMO_QUANTITY
  8853. }
  8854. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8855. {
  8856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8857. {
  8858. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8859. }
  8860. else
  8861. {
  8862. tempIndex = connectorIdInt -1;
  8863. }
  8864. for (int index = 0; index < CCS_QUANTITY; index++)
  8865. {
  8866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8867. {
  8868. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8869. {
  8870. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8871. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8872. {
  8873. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8874. {
  8875. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8877. }
  8878. 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'))
  8879. {
  8880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8881. }
  8882. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8883. {
  8884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8885. }
  8886. else
  8887. {
  8888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8889. }
  8890. }
  8891. 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
  8892. {
  8893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8894. }
  8895. }
  8896. else
  8897. {
  8898. //replace reservation
  8899. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8901. }
  8902. }
  8903. } // END FOR CCS_QUANTITY
  8904. }
  8905. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8906. {
  8907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8908. {
  8909. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8910. }
  8911. else
  8912. {
  8913. tempIndex = connectorIdInt -1;
  8914. }
  8915. for (int index = 0; index < GB_QUANTITY; index++)
  8916. {
  8917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8918. {
  8919. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8920. {
  8921. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8922. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8923. {
  8924. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8925. {
  8926. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8928. }
  8929. 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'))
  8930. {
  8931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8932. }
  8933. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8934. {
  8935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8936. }
  8937. else
  8938. {
  8939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8940. }
  8941. }
  8942. 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
  8943. {
  8944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8945. }
  8946. }
  8947. else
  8948. {
  8949. //replace reservation
  8950. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8952. }
  8953. }
  8954. }// END FOR GB_QUANTITY
  8955. }
  8956. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8957. {
  8958. tempIndex = connectorIdInt -1;
  8959. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8960. {
  8961. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8962. {
  8963. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8964. {
  8965. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8966. 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
  8967. {
  8968. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8969. {
  8970. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8972. }
  8973. 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'))
  8974. {
  8975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8976. }
  8977. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8978. {
  8979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8980. }
  8981. else
  8982. {
  8983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8984. }
  8985. }
  8986. 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
  8987. {
  8988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8989. }
  8990. }
  8991. else
  8992. {
  8993. //replace reservation
  8994. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8996. }
  8997. }
  8998. }// END FOR GB_QUANTITY
  8999. }
  9000. else
  9001. {
  9002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9003. {
  9004. tempIndex = 2;
  9005. }
  9006. else
  9007. {
  9008. tempIndex = (connectorIdInt -1);
  9009. }
  9010. for (int index = 0; index < AC_QUANTITY; index++)
  9011. {
  9012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9013. {
  9014. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9015. {
  9016. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9017. {
  9018. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9019. {
  9020. 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))
  9021. {
  9022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9023. }
  9024. else
  9025. {
  9026. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9028. }
  9029. }
  9030. 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'))
  9031. {
  9032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9033. }
  9034. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9035. {
  9036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9037. }
  9038. else
  9039. {
  9040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9041. }
  9042. }
  9043. 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
  9044. {
  9045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9046. }
  9047. }
  9048. else
  9049. {
  9050. //replace reservation
  9051. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9053. }
  9054. }
  9055. } // END FOR AC_QUANTITY
  9056. }
  9057. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9058. }
  9059. else if(connectorIdInt == 0)
  9060. {
  9061. //check Transaction active
  9062. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9063. {
  9064. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9065. {
  9066. 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'))
  9067. {
  9068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9069. goto end;
  9070. }
  9071. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9072. {
  9073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9074. goto end;
  9075. }
  9076. 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
  9077. {
  9078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9079. goto end;
  9080. }
  9081. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9082. {
  9083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9084. goto end;
  9085. }
  9086. }
  9087. }// END FOR CHAdeMO_QUANTITY
  9088. for (int index = 0; index < CCS_QUANTITY; index++)
  9089. {
  9090. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9091. {
  9092. 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'))
  9093. {
  9094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9095. goto end;
  9096. }
  9097. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9098. {
  9099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9100. goto end;
  9101. }
  9102. 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
  9103. {
  9104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9105. goto end;
  9106. }
  9107. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9108. {
  9109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9110. goto end;
  9111. }
  9112. }
  9113. } // END FOR CCS_QUANTITY
  9114. for (int index = 0; index < GB_QUANTITY; index++)
  9115. {
  9116. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9117. {
  9118. 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'))
  9119. {
  9120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9121. goto end;
  9122. }
  9123. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9124. {
  9125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9126. goto end;
  9127. }
  9128. 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
  9129. {
  9130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9131. goto end;
  9132. }
  9133. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9134. {
  9135. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9136. goto end;
  9137. }
  9138. }
  9139. } // END FOR GB_QUANTITY
  9140. for (int index = 0; index < AC_QUANTITY; index++)
  9141. {
  9142. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9143. {
  9144. 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'))
  9145. {
  9146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9147. goto end;
  9148. }
  9149. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9150. {
  9151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9152. goto end;
  9153. }
  9154. 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
  9155. {
  9156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9157. goto end;
  9158. }
  9159. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9160. {
  9161. 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))
  9162. {
  9163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9164. goto end;
  9165. }
  9166. }
  9167. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9168. {
  9169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9170. goto end;
  9171. }
  9172. }
  9173. }// END FOR AC_QUANTITY
  9174. //The connectorId is 0
  9175. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9177. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9178. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9179. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9180. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9181. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9182. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9183. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9184. result = TRUE;
  9185. return result;
  9186. }
  9187. else
  9188. {
  9189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9190. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9191. }
  9192. if(strcmp(comfirmstr,"Accepted") == 0)
  9193. {
  9194. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9195. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9196. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9197. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9198. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9199. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9200. result = TRUE;
  9201. return result;
  9202. }
  9203. end:
  9204. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9205. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9206. return result;
  9207. }
  9208. int handleResetRequest(char *uuid, char *payload)
  9209. {
  9210. mtrace();
  9211. int result = FAIL;
  9212. char sstr[10]={0},sstrtemp[30]={ 0 };
  9213. char typestr[10]={0};
  9214. char comfirmstr[20]={0};
  9215. int c = 0;
  9216. char *loc;
  9217. DEBUG_INFO("handleResetRequest...\n");
  9218. strcpy(sstrtemp, stringtrimspace(payload));
  9219. loc = strstr(sstrtemp, "type");
  9220. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9221. c = 0;
  9222. while (loc[3+strlen("type")+c] != '\"')
  9223. {
  9224. sstr[c] = loc[3+strlen("type")+c];
  9225. c++;
  9226. }
  9227. sstr[c] = '\0';
  9228. strcpy(typestr,sstr);
  9229. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9230. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9231. {
  9232. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9233. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9234. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9235. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9236. }
  9237. else
  9238. {
  9239. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9240. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9241. result = PASS;
  9242. }
  9243. sendResetConfirmation(uuid, comfirmstr);
  9244. return result;
  9245. }
  9246. int handleSendLocalListRequest(char *uuid, char *payload)
  9247. {
  9248. mtrace();
  9249. int result = FAIL;
  9250. int listVersionInt;
  9251. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9252. char listsearch[]="listVersion";
  9253. char updateTypesearch[]="updateType";
  9254. char localAuthorizationListsearch[]="localAuthorizationList";
  9255. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9256. char CardList[500][160]={0};
  9257. char updateTypestr[15]={0};
  9258. char idTagstr[20]={0};
  9259. char parentIdTag[20]={0};
  9260. char expiryDate[30]={0};
  9261. char idTagstatus[16]={0};
  9262. int c = 0;
  9263. int i = 0;
  9264. char *delim1 = "}";
  9265. char * pch;
  9266. char *loc;
  9267. //char *ptr;
  9268. char comfirmstr[20];
  9269. //int n_localAuthorizations = 0;
  9270. int checkState_Faulted = FALSE;
  9271. DEBUG_INFO("handleSendLocalListRequest...\n");
  9272. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9273. {
  9274. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9275. goto end;
  9276. }
  9277. //check Charge Point state
  9278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9279. {
  9280. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9281. {
  9282. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9283. }
  9284. }
  9285. for (int index = 0; index < CCS_QUANTITY; index++)
  9286. {
  9287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9288. {
  9289. checkState_Faulted = TRUE; //OCPP Status
  9290. }
  9291. }
  9292. for (int index = 0; index < GB_QUANTITY; index++)
  9293. {
  9294. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9295. {
  9296. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9297. }
  9298. }
  9299. //check Charge Point state
  9300. for (int index = 0; index < AC_QUANTITY; index++)
  9301. {
  9302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9303. {
  9304. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9305. }
  9306. }
  9307. if(checkState_Faulted == TRUE)
  9308. {
  9309. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9310. goto end;
  9311. }
  9312. //Filter payload space
  9313. strcpy(sstrtemp, stringtrimspace(payload));
  9314. //listVersion
  9315. c = 0;
  9316. loc = strstr(sstrtemp, listsearch);
  9317. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9318. {
  9319. sstr[c] = loc[strlen("listVersion")+2+c];
  9320. c++;
  9321. }
  9322. sstr[c] = '\0';
  9323. listVersionInt = atoi(sstr);
  9324. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9325. //updateType
  9326. loc = strstr(sstrtemp, updateTypesearch);
  9327. c = 0;
  9328. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9329. {
  9330. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9331. c++;
  9332. }
  9333. sstr[c] = '\0';
  9334. strcpy(updateTypestr, sstr);
  9335. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9336. //localAuthorizationList
  9337. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9338. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9339. if(loc != NULL) // localAuthorizationList is not NULL
  9340. {
  9341. //Check UpdateType
  9342. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9343. {
  9344. //Local list full update
  9345. printf("Local list full update.\n");
  9346. OCPP_getListVerion();
  9347. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9348. {
  9349. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9350. goto end;
  9351. }
  9352. OCPP_cleanLocalList();
  9353. }
  9354. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9355. {
  9356. //Local list different update
  9357. printf("Local list different update.\n");
  9358. OCPP_getListVerion();
  9359. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9360. {
  9361. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9362. goto end;
  9363. }
  9364. }
  9365. else
  9366. {
  9367. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9368. goto end;
  9369. }
  9370. c = 0;
  9371. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9372. {
  9373. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9374. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9375. c++;
  9376. }
  9377. sstr[c] = '\0';
  9378. //DEBUG_INFO("sstr=%s\n", sstr);
  9379. //parsing strings to words
  9380. i = 0;
  9381. pch = strtok(sstr,delim1);
  9382. while (pch != NULL)
  9383. {
  9384. strcpy(CardList[i], pch);
  9385. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9386. pch = strtok (NULL, delim1);
  9387. i = i + 1;
  9388. }
  9389. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9390. //local Authorizations List Numbers
  9391. //n_localAuthorizations = i;
  9392. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9393. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9394. c= 0;
  9395. while(c < i) // i is CardList Number
  9396. {
  9397. //Search "IdToken"
  9398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9399. loc = strstr(CardList[c], "idTag");
  9400. int j = 0;
  9401. while (loc[3+strlen("idTag")+j] != '\"')
  9402. {
  9403. sstr[j] = loc[3+strlen("idTag")+j];
  9404. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9405. j++;
  9406. }
  9407. sstr[j] = '\0';
  9408. strcpy(idTagstr, sstr);
  9409. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9410. //Search "expiryDate"
  9411. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9412. loc = strstr(CardList[c], "expiryDate");
  9413. j = 0;
  9414. if(loc != NULL)
  9415. {
  9416. while (loc[3+strlen("expiryDate")+j] != '\"')
  9417. {
  9418. sstr[j] = loc[3+strlen("expiryDate")+j];
  9419. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9420. j++;
  9421. }
  9422. sstr[j] = '\0';
  9423. strcpy(expiryDate, sstr);
  9424. }
  9425. else
  9426. {
  9427. strcpy(expiryDate, "");
  9428. }
  9429. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9430. //Search "parentIdTag"
  9431. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9432. loc = strstr(CardList[c], "parentIdTag");
  9433. j = 0;
  9434. if(loc != NULL)
  9435. {
  9436. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9437. {
  9438. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9439. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9440. j++;
  9441. }
  9442. sstr[j] = '\0';
  9443. strcpy(parentIdTag, sstr);
  9444. }
  9445. else
  9446. {
  9447. strcpy(parentIdTag, "");
  9448. }
  9449. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9450. //Search "status"
  9451. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9452. loc = strstr(CardList[c], "status");
  9453. j = 0;
  9454. while (loc[3+strlen("status")+j] != '\"')
  9455. {
  9456. sstr[j] = loc[3+strlen("status")+j];
  9457. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9458. j++;
  9459. }
  9460. sstr[j] = '\0';
  9461. strcpy(idTagstatus, sstr);
  9462. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9463. OCPP_getIdTagFromLocalList(idTagstr);
  9464. //OCPP_getIdTagFromLocalList("test"); For Test
  9465. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9466. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9467. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9468. {
  9469. //Local list full update
  9470. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9471. // update list
  9472. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9473. //DEBUG_INFO("Local list full update. 1\n");
  9474. //OCPP_get_TableAuthlocalAllData();
  9475. //DEBUG_INFO("Local list full update. 2\n");
  9476. }
  9477. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9478. {
  9479. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9480. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9481. }
  9482. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9483. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9484. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9485. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9486. c++;
  9487. }
  9488. }
  9489. else
  9490. {
  9491. //Check UpdateType
  9492. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9493. {
  9494. //Local list full update
  9495. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9496. OCPP_cleanLocalList();
  9497. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9498. goto end;
  9499. }
  9500. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9501. {
  9502. //Local list different update
  9503. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9504. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9505. goto end;
  9506. }
  9507. }
  9508. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9509. end:
  9510. sendSendLocalListConfirmation(uuid, comfirmstr);
  9511. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9512. return result;
  9513. }
  9514. #define MAX 200
  9515. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9516. {
  9517. mtrace();
  9518. int result = FAIL;
  9519. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9520. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9521. char chargingProfilePurposeStr[30]={0};
  9522. char chargingProfileKindStr[16]={0};
  9523. char recurrencyKindStr[10]={0};
  9524. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9525. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9526. int chargingSchedulePeriodCount = 0;
  9527. char comfirmstr[20]={0};
  9528. int meet= FALSE;
  9529. FILE *fptr1;
  9530. char filename[MAX]={0};
  9531. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9532. char rmFileCmd[50]={0};
  9533. char tempchargingProfilePurposeStr[30]={0};
  9534. char word[1600]={0};
  9535. int n_chargingProfile = 0;
  9536. json_object *SetChargingProfile;
  9537. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9538. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9539. SetChargingProfile = json_tokener_parse(payload);
  9540. if(!is_error(SetChargingProfile))
  9541. {
  9542. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9543. {
  9544. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9545. if(connectorIdInt == 0)
  9546. {
  9547. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9548. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9549. }
  9550. else
  9551. {
  9552. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9553. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9554. }
  9555. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9556. }
  9557. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9558. {
  9559. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9560. {
  9561. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9562. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9563. {
  9564. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9565. }
  9566. else
  9567. {
  9568. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9569. }
  9570. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9571. }
  9572. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9573. {
  9574. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9575. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9576. {
  9577. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9578. }
  9579. else
  9580. {
  9581. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9582. }
  9583. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9584. }
  9585. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9586. {
  9587. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9588. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9589. {
  9590. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9591. }
  9592. else
  9593. {
  9594. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9595. }
  9596. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9597. }
  9598. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9599. {
  9600. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9601. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9602. {
  9603. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9604. }
  9605. else
  9606. {
  9607. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9608. }
  9609. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9610. }
  9611. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9612. {
  9613. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9614. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9615. {
  9616. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9617. }
  9618. else
  9619. {
  9620. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9621. }
  9622. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9623. }
  9624. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9625. {
  9626. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9627. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9628. {
  9629. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9630. }
  9631. else
  9632. {
  9633. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9634. }
  9635. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9636. }
  9637. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9638. {
  9639. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9640. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9641. {
  9642. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9643. }
  9644. else
  9645. {
  9646. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9647. }
  9648. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9649. }
  9650. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9651. {
  9652. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9653. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9654. {
  9655. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9656. }
  9657. else
  9658. {
  9659. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9660. }
  9661. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9662. }
  9663. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9664. {
  9665. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9666. {
  9667. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9668. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9669. {
  9670. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9671. }
  9672. else
  9673. {
  9674. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9675. }
  9676. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9677. }
  9678. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9679. {
  9680. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9681. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9682. {
  9683. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9684. }
  9685. else
  9686. {
  9687. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9688. }
  9689. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9690. }
  9691. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9692. {
  9693. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9694. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9695. {
  9696. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9697. }
  9698. else
  9699. {
  9700. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9701. }
  9702. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9703. }
  9704. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9705. {
  9706. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9707. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9708. {
  9709. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9710. }
  9711. else
  9712. {
  9713. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9714. }
  9715. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9716. }
  9717. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9718. {
  9719. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9720. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9721. if(chargingSchedulePeriodCount <= 10)
  9722. {
  9723. 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++)
  9724. {
  9725. 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)
  9726. {
  9727. 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"));
  9728. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9729. {
  9730. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9731. }
  9732. else
  9733. {
  9734. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9735. }
  9736. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9737. }
  9738. 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)
  9739. {
  9740. 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"));
  9741. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9742. {
  9743. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9744. }
  9745. else
  9746. {
  9747. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9748. }
  9749. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[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), "numberPhases") != NULL)
  9752. {
  9753. 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"));
  9754. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9755. {
  9756. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9757. }
  9758. else
  9759. {
  9760. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9761. }
  9762. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9763. }
  9764. }
  9765. }
  9766. }
  9767. }
  9768. }
  9769. }
  9770. json_object_put(SetChargingProfile);
  9771. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9772. {
  9773. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9774. goto end;
  9775. }
  9776. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9777. {
  9778. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9779. if(connectorIdInt != 0)
  9780. {
  9781. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9782. goto end;
  9783. }
  9784. strcpy(filename, ChargePointMaxProfile_JSON );
  9785. fptr1 = fopen(filename, "r");
  9786. if (!fptr1)
  9787. {
  9788. //file not exist
  9789. DEBUG_INFO("Unable to open the input file!!\n");
  9790. fptr1 = fopen(filename, "w+");
  9791. }
  9792. else
  9793. {
  9794. //Check Charging Profile Count
  9795. while(fscanf(fptr1, "%s", word) != EOF)
  9796. {
  9797. //DEBUG_INFO("word=%s\n",word);
  9798. if(strstr(word, "chargingProfileId")!= NULL)
  9799. {
  9800. //DEBUG_INFO("test chargingProfileId \n");
  9801. n_chargingProfile = n_chargingProfile + 1;
  9802. //DEBUG_INFO("chargingProfileId Found\n");
  9803. }
  9804. }
  9805. }
  9806. fclose(fptr1);
  9807. }
  9808. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9809. {
  9810. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9811. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9812. {
  9813. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9814. goto end;
  9815. }
  9816. memset(filename, 0, ARRAY_SIZE(filename));
  9817. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9818. fptr1 = fopen(filename, "r");
  9819. if (!fptr1)
  9820. {
  9821. //file not exist
  9822. //DEBUG_INFO("Unable to open the input file!!\n");
  9823. fptr1 = fopen(filename, "w+");
  9824. }
  9825. else
  9826. {
  9827. //Check Charging Profile Count
  9828. while(fscanf(fptr1, "%s", word) != EOF)
  9829. {
  9830. //DEBUG_INFO("word=%s\n",word);
  9831. if(strstr(word, "chargingProfileId")!= NULL)
  9832. {
  9833. //DEBUG_INFO("test chargingProfileId \n");
  9834. n_chargingProfile = n_chargingProfile + 1;
  9835. //DEBUG_INFO("chargingProfileId Found\n");
  9836. }
  9837. }
  9838. }
  9839. fclose(fptr1);
  9840. }
  9841. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9842. {
  9843. //printf("set chargingProfile 1-4\n");
  9844. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9845. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9846. if(connectorIdInt == 0)
  9847. {
  9848. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9849. goto end;
  9850. }
  9851. int tempIndex = 0;
  9852. //check Transaction active
  9853. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9854. {
  9855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9856. {
  9857. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9858. }
  9859. else
  9860. {
  9861. tempIndex = connectorIdInt -1;
  9862. }
  9863. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9864. {
  9865. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9866. {
  9867. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9868. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9869. {
  9870. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9871. {
  9872. meet = TRUE;
  9873. break;
  9874. }
  9875. }
  9876. }
  9877. }
  9878. }
  9879. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  9890. {
  9891. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9892. {
  9893. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9894. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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_GBT)
  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 < GB_QUANTITY; index++)
  9916. {
  9917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9918. {
  9919. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9920. (ShmSysConfigAndInfo->SysInfo.GbChargingData[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_DO)
  9932. {
  9933. tempIndex = connectorIdInt -1;
  9934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9935. {
  9936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9937. {
  9938. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9939. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9940. {
  9941. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9942. {
  9943. meet = TRUE;
  9944. break;
  9945. }
  9946. }
  9947. }
  9948. }
  9949. }
  9950. else
  9951. {
  9952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9953. {
  9954. tempIndex = 2;
  9955. }
  9956. else
  9957. {
  9958. tempIndex = (connectorIdInt -1);
  9959. }
  9960. for (int index = 0; index < AC_QUANTITY; index++)
  9961. {
  9962. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9963. {
  9964. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9965. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].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. //check Transaction active
  9977. if(meet == FALSE)
  9978. {
  9979. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9980. goto end;
  9981. }
  9982. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9983. {
  9984. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9985. goto end;
  9986. }
  9987. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9988. fptr1 = fopen(filename, "r");
  9989. if (!fptr1)
  9990. {
  9991. //file not exist
  9992. DEBUG_INFO("Unable to open the input file!!\n");
  9993. fptr1 = fopen(filename, "w+");
  9994. }
  9995. else
  9996. {
  9997. //Check Charging Profile Count
  9998. while(fscanf(fptr1, "%s", word) != EOF)
  9999. {
  10000. //DEBUG_INFO("word=%s\n",word);
  10001. if(strstr(word, "chargingProfileId")!= NULL)
  10002. {
  10003. //DEBUG_INFO("test chargingProfileId \n");
  10004. n_chargingProfile = n_chargingProfile + 1;
  10005. //DEBUG_INFO("chargingProfileId Found\n");
  10006. }
  10007. }
  10008. }
  10009. fclose(fptr1);
  10010. }
  10011. // Check ChargeProfileMaxStackLevel
  10012. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10013. {
  10014. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10015. goto end;
  10016. }
  10017. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10018. {
  10019. int i = 0;
  10020. char fnametemp[200]={0};
  10021. n_chargingProfile = 0;
  10022. //Check ChargePointMaxProfile.json exit
  10023. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10024. {
  10025. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10026. //Check Charging Profile Count
  10027. while(fscanf(fptr1, "%s", word) != EOF)
  10028. {
  10029. //DEBUG_INFO("word=%s\n",word);
  10030. if(strstr(word, "chargingProfileId")!= NULL)
  10031. {
  10032. //DEBUG_INFO("test chargingProfileId \n");
  10033. n_chargingProfile = n_chargingProfile + 1;
  10034. i = i + 1;
  10035. //DEBUG_INFO("chargingProfileId Found\n");
  10036. }
  10037. memset(word, 0, ARRAY_SIZE(word));
  10038. }
  10039. fclose(fptr1);
  10040. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10041. }
  10042. //Check TxDefaultProfile_0.json exit
  10043. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10044. {
  10045. i = 0;
  10046. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10047. //Check Charging Profile Count
  10048. while(fscanf(fptr1, "%s", word) != EOF)
  10049. {
  10050. //DEBUG_INFO("word=%s\n",word);
  10051. if(strstr(word, "chargingProfileId")!= NULL)
  10052. {
  10053. //DEBUG_INFO("test chargingProfileId \n");
  10054. n_chargingProfile = n_chargingProfile + 1;
  10055. i = i + 1;
  10056. //DEBUG_INFO("chargingProfileId Found\n");
  10057. }
  10058. memset(word, 0, ARRAY_SIZE(word));
  10059. }
  10060. fclose(fptr1);
  10061. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10062. }
  10063. //Check TxDefaultProfile_%d.json
  10064. for(int j=1; j <= gunTotalNumber; j++)
  10065. {
  10066. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10067. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10068. if((access(fnametemp,F_OK))!=-1)
  10069. {
  10070. i = 0;
  10071. fptr1 = fopen(fnametemp, "r");
  10072. //Check Charging Profile Count
  10073. while(fscanf(fptr1, "%s", word) != EOF)
  10074. {
  10075. //DEBUG_INFO("word=%s\n",word);
  10076. if(strstr(word, "chargingProfileId")!= NULL)
  10077. {
  10078. //DEBUG_INFO("test chargingProfileId \n");
  10079. n_chargingProfile = n_chargingProfile + 1;
  10080. i = i + 1;
  10081. //DEBUG_INFO("chargingProfileId Found\n");
  10082. }
  10083. memset(word, 0, ARRAY_SIZE(word));
  10084. }
  10085. fclose(fptr1);
  10086. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10087. }
  10088. }
  10089. //Check TxProfile_%d.json
  10090. for(int j=1; j <= gunTotalNumber; j++)
  10091. {
  10092. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10093. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%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. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10116. {
  10117. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10118. goto end;
  10119. }
  10120. }
  10121. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10122. //**********************************Write to File********************************************************/
  10123. FILE *infile;
  10124. FILE *outfile;
  10125. infile = fopen (filename, "r");
  10126. outfile = fopen (tempfile, "w");
  10127. int d =0;
  10128. d = fgetc(infile);
  10129. rewind(infile);
  10130. if(d == EOF)
  10131. {
  10132. // Profile is empty
  10133. fprintf(outfile,"%s\n",payload);
  10134. fclose(infile);
  10135. fclose(outfile);
  10136. sprintf(rmFileCmd,"rm -f %s",filename);
  10137. system(rmFileCmd);
  10138. rename(tempfile, filename);
  10139. }
  10140. else
  10141. {
  10142. // Profile is not empty
  10143. char buf[2048]={0};
  10144. int ChargingProfileAdded = FALSE;
  10145. while (fgets(buf, sizeof(buf), infile) != NULL)
  10146. {
  10147. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10148. json_object *tmpChargingProfile;
  10149. tmpChargingProfile = json_tokener_parse(buf);
  10150. if(!is_error(SetChargingProfile))
  10151. {
  10152. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10153. {
  10154. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10155. }
  10156. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10157. {
  10158. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10159. {
  10160. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10161. }
  10162. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10163. {
  10164. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10165. }
  10166. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10167. {
  10168. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10169. }
  10170. }
  10171. }
  10172. json_object_put(tmpChargingProfile);
  10173. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10174. {
  10175. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10176. {
  10177. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10178. if(ChargingProfileAdded == FALSE)
  10179. {
  10180. fprintf(outfile,"%s\n",payload);
  10181. ChargingProfileAdded = TRUE;
  10182. }
  10183. }
  10184. else
  10185. {
  10186. if(tempstackLevelInt < stackLevelInt)
  10187. {
  10188. if(ChargingProfileAdded == FALSE)
  10189. {
  10190. fprintf(outfile,"%s\n",buf);
  10191. fprintf(outfile,"%s\n",payload);
  10192. ChargingProfileAdded = TRUE;
  10193. }
  10194. else
  10195. {
  10196. fprintf(outfile,"%s\n",buf);
  10197. }
  10198. }
  10199. else
  10200. {
  10201. if(ChargingProfileAdded == FALSE)
  10202. {
  10203. fprintf(outfile,"%s\n",buf);
  10204. fprintf(outfile,"%s\n",payload);
  10205. ChargingProfileAdded = TRUE;
  10206. }
  10207. else
  10208. {
  10209. fprintf(outfile,"%s\n",buf);
  10210. }
  10211. }
  10212. }
  10213. }
  10214. else
  10215. {
  10216. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10217. {
  10218. if(ChargingProfileAdded == FALSE)
  10219. {
  10220. fprintf(outfile,"%s\n",buf);
  10221. fprintf(outfile,"%s\n",payload);
  10222. ChargingProfileAdded = TRUE;
  10223. }
  10224. else
  10225. {
  10226. fprintf(outfile,"%s\n",buf);
  10227. }
  10228. }
  10229. else if(tempstackLevelInt < stackLevelInt)
  10230. {
  10231. if(ChargingProfileAdded == FALSE)
  10232. {
  10233. fprintf(outfile,"%s\n",buf);
  10234. fprintf(outfile,"%s\n",payload);
  10235. ChargingProfileAdded = TRUE;
  10236. }
  10237. else
  10238. {
  10239. fprintf(outfile,"%s\n",buf);
  10240. }
  10241. }
  10242. else
  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. }
  10256. } // end of while loop
  10257. fclose(infile);
  10258. fclose(outfile);
  10259. sprintf(rmFileCmd,"rm -f %s",filename);
  10260. system(rmFileCmd);
  10261. rename(tempfile, filename);
  10262. }
  10263. sleep(1);
  10264. result = TRUE;
  10265. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10266. end:
  10267. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10268. {
  10269. if(connectorIdInt == 0)
  10270. {
  10271. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10272. {
  10273. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10274. }
  10275. }
  10276. else
  10277. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10278. }
  10279. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10280. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10281. return result;
  10282. }
  10283. int handleTriggerMessageRequest(char *uuid, char *payload)
  10284. {
  10285. mtrace();
  10286. int result = FAIL;
  10287. int connectorIdIsNULL = FALSE;
  10288. int connectorIdInt =0;
  10289. char sstr[40]={0},sstrtemp[100]={ 0 };
  10290. char requestedMessagestr[40]={0};
  10291. char comfirmstr[20]={0};
  10292. int c = 0;
  10293. char *loc;
  10294. DEBUG_INFO("handleTriggerMessageRequest\n");
  10295. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10296. strcpy(sstrtemp, stringtrimspace(payload));
  10297. c = 0;
  10298. loc = strstr(sstrtemp, "requestedMessage");
  10299. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10300. {
  10301. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10302. c++;
  10303. }
  10304. sstr[c] = '\0';
  10305. strcpy(requestedMessagestr, sstr);
  10306. c = 0;
  10307. loc = strstr(sstrtemp, "connectorId");
  10308. if(loc == NULL)
  10309. {
  10310. connectorIdIsNULL = TRUE;
  10311. }
  10312. else
  10313. {
  10314. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10315. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10316. {
  10317. sstr[c] = loc[strlen("connectorId")+2+c];
  10318. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10319. c++;
  10320. }
  10321. sstr[c] = '\0';
  10322. connectorIdInt = atoi(sstr);
  10323. }
  10324. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10325. {
  10326. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10327. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10328. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10329. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10330. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10331. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10332. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10333. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10334. {
  10335. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10336. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10337. return TRUE;
  10338. }
  10339. else
  10340. {
  10341. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10342. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10343. }
  10344. }
  10345. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10346. {
  10347. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10348. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10349. return TRUE;
  10350. }
  10351. //==========================
  10352. // Trigger message
  10353. //==========================
  10354. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10355. {
  10356. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10357. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10358. {
  10359. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10360. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10361. }
  10362. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10363. }
  10364. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10365. {
  10366. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10367. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10368. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10369. }
  10370. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10371. {
  10372. //sendBootNotificationRequest();
  10373. server_sign = FALSE;
  10374. }
  10375. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10376. {
  10377. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10378. }
  10379. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10380. {
  10381. if(connectorIdIsNULL == FALSE)
  10382. {
  10383. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10384. {
  10385. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10386. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10387. }
  10388. }
  10389. else
  10390. {
  10391. for(int idx=0;idx< gunTotalNumber;idx++)
  10392. {
  10393. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10394. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10395. }
  10396. }
  10397. }
  10398. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10399. {
  10400. if(connectorIdIsNULL == FALSE)
  10401. {
  10402. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  10403. {
  10404. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10405. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  10406. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10407. }
  10408. }
  10409. else
  10410. {
  10411. for(int idx=0;idx< gunTotalNumber;idx++)
  10412. {
  10413. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10414. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10415. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10416. }
  10417. }
  10418. }
  10419. return result;
  10420. }
  10421. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10422. {
  10423. mtrace();
  10424. int result = FAIL;
  10425. int connectorIdInt =0;
  10426. char comfirmstr[20]={0};
  10427. int tempIndex = 0;
  10428. json_object *UnlockConnector;
  10429. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10430. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10431. UnlockConnector = json_tokener_parse(payload);
  10432. if(!is_error(UnlockConnector))
  10433. {
  10434. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10435. {
  10436. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10437. }
  10438. }
  10439. json_object_put(UnlockConnector);
  10440. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10441. if(gunTotalNumber == 0)
  10442. {
  10443. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10444. goto end;
  10445. }
  10446. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10447. {
  10448. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10449. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10450. goto end;
  10451. }
  10452. else
  10453. {
  10454. //check Transaction active
  10455. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10456. {
  10457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10458. {
  10459. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10460. }
  10461. else
  10462. {
  10463. tempIndex = connectorIdInt -1;
  10464. }
  10465. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10466. {
  10467. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10468. {
  10469. //stop Transaction
  10470. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10471. }
  10472. }
  10473. }
  10474. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10475. {
  10476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10477. {
  10478. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10479. }
  10480. else
  10481. {
  10482. tempIndex = connectorIdInt -1;
  10483. }
  10484. for (int index = 0; index < CCS_QUANTITY; index++)
  10485. {
  10486. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10487. {
  10488. //stop Transaction
  10489. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10490. }
  10491. }
  10492. }
  10493. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10494. {
  10495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10496. {
  10497. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10498. }
  10499. else
  10500. {
  10501. tempIndex = connectorIdInt -1;
  10502. }
  10503. for (int index = 0; index < GB_QUANTITY; index++)
  10504. {
  10505. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10506. {
  10507. //stop Transaction
  10508. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10509. }
  10510. }
  10511. }
  10512. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10513. {
  10514. tempIndex = connectorIdInt -1;
  10515. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10516. {
  10517. 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)))
  10518. {
  10519. //stop Transaction
  10520. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10521. }
  10522. }
  10523. }
  10524. else
  10525. {
  10526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10527. {
  10528. tempIndex = 2;
  10529. }
  10530. else
  10531. {
  10532. tempIndex = connectorIdInt-1;
  10533. }
  10534. for (int index = 0; index < AC_QUANTITY; index++)
  10535. {
  10536. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10537. {
  10538. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10539. }
  10540. }
  10541. }
  10542. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10543. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10544. result = TRUE;
  10545. return result;
  10546. }
  10547. end:
  10548. //json_object_put(obj); --- remove temporally
  10549. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10550. return result;
  10551. }
  10552. static char UpdateFirmwarepayloadData[300]={0};
  10553. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10554. {
  10555. mtrace();
  10556. int result = FAIL;
  10557. pthread_t t;
  10558. sendUpdateFirmwareConfirmation(uuid);
  10559. memset(UpdateFirmwarepayloadData, 0, 300);
  10560. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10561. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10562. ////pthread_join(t, NULL); //
  10563. //pthread_detach(t);
  10564. //sendUpdateFirmwareConfirmation(uuid);
  10565. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10566. return result;
  10567. }
  10568. void *UpdateFirmwareProcess(void *data)
  10569. {
  10570. pthread_detach(pthread_self());
  10571. mtrace();
  10572. int retriesInt =0, retryIntervalInt=0;
  10573. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10574. int port=0;
  10575. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10576. int isSuccess = 0;
  10577. char ftpbuf[1024];
  10578. char temp[1024];
  10579. char * pch;
  10580. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10581. json_object *UpdateFirmware;
  10582. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10583. if(!is_error(UpdateFirmware))
  10584. {
  10585. // Required data
  10586. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10587. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10588. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10589. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10590. // Optional data
  10591. if(json_object_object_get(UpdateFirmware, "retries"))
  10592. {
  10593. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10594. }
  10595. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10596. {
  10597. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10598. }
  10599. }
  10600. json_object_put(UpdateFirmware);
  10601. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10602. memset(path, 0, ARRAY_SIZE(path));
  10603. // Wait retrieveData
  10604. if(strlen(retrieveDatestr) > 10)
  10605. {
  10606. do
  10607. {
  10608. sleep(1);
  10609. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10610. }
  10611. // Ready to download
  10612. system("rm -f /mnt/*");
  10613. if(strncmp(locationstr,"http", 4) == 0)
  10614. {
  10615. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10616. sprintf(ftppath,"/%s", path);
  10617. DEBUG_INFO("locationstr: %s\n", locationstr);
  10618. DEBUG_INFO("protocol: %s\n",protocol);
  10619. DEBUG_INFO("host: %s\n",host);
  10620. DEBUG_INFO("path: %s\n",path);
  10621. DEBUG_INFO("ftppath: %s\n",ftppath);
  10622. int ftppathlen=strlen(ftppath);
  10623. int i=1;
  10624. char filenametemp[50];
  10625. while(i < ftppathlen)
  10626. {
  10627. int len=ftppathlen-i;
  10628. if(ftppath[len]== 47) // '/' ascll code: 47
  10629. {
  10630. DEBUG_INFO("compare '/' all right\n");
  10631. break;
  10632. }
  10633. i=i+1;
  10634. }
  10635. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10636. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10637. filenametemp[i+1] = 0;
  10638. do
  10639. {
  10640. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10641. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10642. sleep(1);
  10643. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10644. if(!isSuccess)
  10645. {
  10646. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10647. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10648. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10649. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10650. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10651. }
  10652. else
  10653. {
  10654. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10655. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10656. }
  10657. retriesInt--;
  10658. }while((isSuccess == 0)&&(retriesInt >= 0));
  10659. }
  10660. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10661. {
  10662. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10663. memset(temp, 0, ARRAY_SIZE(temp));
  10664. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10665. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10666. int ftppathlen=strlen(ftpbuf);
  10667. int i=1;
  10668. char filenametemp[50];
  10669. while(i < ftppathlen)
  10670. {
  10671. int len=ftppathlen-i;
  10672. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10673. {
  10674. DEBUG_INFO(" compare '/' all right\n");
  10675. break;
  10676. }
  10677. i=i+1;
  10678. }
  10679. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10680. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10681. filenametemp[i+1] = 0;
  10682. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10683. pch=strchr(temp,'@');
  10684. if(pch==NULL)
  10685. {
  10686. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10687. protocol, host, &port, path);
  10688. strcpy(user,"anonymous");
  10689. strcpy(password,"");
  10690. }
  10691. else
  10692. {
  10693. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10694. protocol, user, password, host, &port, path);
  10695. }
  10696. sscanf(host,"%[^/]%s",host1, path1);
  10697. sprintf(ftppath,"%s", path1);
  10698. //DEBUG_INFO("protocol =%s\n",protocol);
  10699. //DEBUG_INFO("user =%s\n",user);
  10700. //DEBUG_INFO("password =%s\n",password);
  10701. //DEBUG_INFO("host1 =%s\n",host1);
  10702. //DEBUG_INFO("port =%d\n",port);
  10703. //DEBUG_INFO("path1 =%s\n",path1);
  10704. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10705. //ftpFile(host, user, password, port, ftppath, fname);
  10706. //download firmware pthred
  10707. if(port == 0)
  10708. {
  10709. port = 21;
  10710. }
  10711. do
  10712. {
  10713. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10714. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10715. sleep(1);
  10716. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10717. if(!isSuccess)
  10718. {
  10719. //BulldogUtil.sleepMs(interval*1000);
  10720. DEBUG_INFO("Update firmware request and download file fail.\n");
  10721. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10722. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10723. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10724. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10725. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10726. }
  10727. else
  10728. {
  10729. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10730. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10731. }
  10732. retriesInt--;
  10733. }while((!isSuccess)&&(retriesInt >= 0));
  10734. }
  10735. else
  10736. {
  10737. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10738. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10739. sleep(1);
  10740. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10741. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10742. }
  10743. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10744. pthread_exit(NULL);
  10745. }
  10746. int handleCertificateSignedRequest(char *uuid, char *payload)
  10747. {
  10748. mtrace();
  10749. int result = PASS;
  10750. json_object *CertificateSigned;
  10751. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10752. CertificateSigned = json_tokener_parse(payload);
  10753. if(!is_error(CertificateSigned))
  10754. {
  10755. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10756. }
  10757. json_object_put(CertificateSigned);
  10758. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10759. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10760. fclose(fp);
  10761. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10762. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10763. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10764. sendCertificateSignedConfirmation(uuid);
  10765. return result;
  10766. }
  10767. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10768. {
  10769. mtrace();
  10770. int result = PASS;
  10771. json_object *DeleteCertificate;
  10772. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10773. DeleteCertificate = json_tokener_parse(payload);
  10774. if(!is_error(DeleteCertificate))
  10775. {
  10776. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10777. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10778. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10779. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10780. }
  10781. json_object_put(DeleteCertificate);
  10782. /*
  10783. * TODO: Delete certificateSigned process
  10784. */
  10785. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10786. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10787. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10788. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10789. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10790. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10791. sendDeleteCertificateConfirmation(uuid);
  10792. return result;
  10793. }
  10794. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10795. {
  10796. mtrace();
  10797. int result = PASS;
  10798. json_object *ExtendedTriggerMessage;
  10799. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10800. ExtendedTriggerMessage = json_tokener_parse(payload);
  10801. if(!is_error(ExtendedTriggerMessage))
  10802. {
  10803. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10804. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10805. {
  10806. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10807. }
  10808. else
  10809. {
  10810. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10811. }
  10812. }
  10813. json_object_put(ExtendedTriggerMessage);
  10814. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10815. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10816. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10817. {
  10818. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10819. }
  10820. else
  10821. {
  10822. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10823. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10824. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10825. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10826. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10827. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10828. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10829. {
  10830. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10831. }
  10832. else
  10833. {
  10834. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10835. }
  10836. }
  10837. sendExtendedTriggerMessageConfirmation(uuid);
  10838. //==========================
  10839. // Trigger message
  10840. //==========================
  10841. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10842. {
  10843. //sendBootNotificationRequest();
  10844. server_sign = FALSE;
  10845. }
  10846. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10847. {
  10848. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10849. }
  10850. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10851. {
  10852. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10853. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10854. {
  10855. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10856. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10857. }
  10858. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10859. }
  10860. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10861. {
  10862. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10863. }
  10864. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10865. {
  10866. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10867. {
  10868. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10869. }
  10870. else
  10871. {
  10872. for(int idx=0;idx< gunTotalNumber;idx++)
  10873. {
  10874. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10875. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10876. }
  10877. }
  10878. }
  10879. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10880. {
  10881. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10882. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10883. {
  10884. 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\" &");
  10885. }
  10886. }
  10887. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10888. {
  10889. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10890. {
  10891. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10892. }
  10893. else
  10894. {
  10895. for(int idx=0;idx< gunTotalNumber;idx++)
  10896. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10897. }
  10898. }
  10899. return result;
  10900. }
  10901. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10902. {
  10903. mtrace();
  10904. int result = PASS;
  10905. json_object *GetInstalledCertificateIds;
  10906. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10907. GetInstalledCertificateIds = json_tokener_parse(payload);
  10908. if(!is_error(GetInstalledCertificateIds))
  10909. {
  10910. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10911. }
  10912. json_object_put(GetInstalledCertificateIds);
  10913. /*
  10914. * TODO: Return installed certificate process
  10915. */
  10916. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10917. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10918. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10919. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10920. sendGetInstalledCertificateIdsConfirmation(uuid);
  10921. return result;
  10922. }
  10923. int handleGetLogRequest(char *uuid, char *payload)
  10924. {
  10925. mtrace();
  10926. int result = PASS;
  10927. json_object *GetLog;
  10928. DEBUG_INFO("handleGetLogRequest...\n");
  10929. GetLog = json_tokener_parse(payload);
  10930. if(!is_error(GetLog))
  10931. {
  10932. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10933. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10934. if(json_object_object_get(GetLog, "retries") != NULL)
  10935. {
  10936. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10937. }
  10938. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10939. {
  10940. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10941. }
  10942. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10943. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10944. {
  10945. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10946. }
  10947. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10948. {
  10949. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10950. }
  10951. }
  10952. json_object_put(GetLog);
  10953. /*
  10954. * TODO: Upload log process
  10955. */
  10956. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10957. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10958. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10959. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10960. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10961. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10962. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10963. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10964. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10965. sendGetLogConfirmation(uuid);
  10966. return result;
  10967. }
  10968. int handleInstallCertificateRequest(char *uuid, char *payload)
  10969. {
  10970. mtrace();
  10971. int result = PASS;
  10972. json_object *InstallCertificate;
  10973. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10974. InstallCertificate = json_tokener_parse(payload);
  10975. if(!is_error(InstallCertificate))
  10976. {
  10977. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10978. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10979. /*
  10980. * TODO: Install certificate process
  10981. */
  10982. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10983. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10984. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10985. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10986. sendInstallCertificateConfirmation(uuid);
  10987. }
  10988. json_object_put(InstallCertificate);
  10989. return result;
  10990. }
  10991. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10992. {
  10993. mtrace();
  10994. int result = PASS;
  10995. json_object *SignedUpdateFirmware;
  10996. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10997. SignedUpdateFirmware = json_tokener_parse(payload);
  10998. if(!is_error(SignedUpdateFirmware))
  10999. {
  11000. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11001. {
  11002. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11003. }
  11004. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11005. {
  11006. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11007. }
  11008. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11009. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11010. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11011. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11012. {
  11013. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11014. }
  11015. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11016. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11017. }
  11018. json_object_put(SignedUpdateFirmware);
  11019. /*
  11020. * TODO: Upgrade firmware process
  11021. */
  11022. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11023. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11024. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11025. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11026. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11027. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11028. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11029. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11030. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11031. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11032. sendInstallCertificateConfirmation(uuid);
  11033. return result;
  11034. }
  11035. int handleUnknownRequest(char *uuid, char *payload)
  11036. {
  11037. mtrace();
  11038. int result = PASS;
  11039. DEBUG_INFO("handleUnknownRequest...\n");
  11040. sendUnknownConfirmation(uuid);
  11041. result = PASS;
  11042. return result;
  11043. }
  11044. //==========================================
  11045. // Handle server response routine
  11046. //==========================================
  11047. void handleAuthorizeResponse(char *payload, int gun_index)
  11048. {
  11049. mtrace();
  11050. char expiryDatestr[30]={0};
  11051. char parentIdTagstr[20]={0};
  11052. char statusstr[20]={0};
  11053. int expiryDateISNULL=FALSE;
  11054. int parentIdTagISNULL=FALSE;
  11055. DEBUG_INFO("handleAuthorizeResponse...\n");
  11056. json_object *Authorize;
  11057. Authorize = json_tokener_parse(payload);
  11058. if(!is_error(Authorize))
  11059. {
  11060. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11061. {
  11062. // Required data
  11063. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11064. // Optional data
  11065. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11066. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11067. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11068. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11069. }
  11070. }
  11071. json_object_put(Authorize);
  11072. if(expiryDateISNULL == FALSE)
  11073. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11074. if(parentIdTagISNULL == FALSE)
  11075. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11076. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11077. //Update idTag information to authorization cache if supproted
  11078. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11079. {
  11080. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11081. }
  11082. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11083. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11084. authorizeRetryTimes = 0;
  11085. }
  11086. void handleBootNotificationResponse(char *payload, int gun_index)
  11087. {
  11088. mtrace();
  11089. char statusStr[12]={0};
  11090. char currentTimeStr[30]={0};
  11091. int intervalInt = 0;
  11092. DEBUG_INFO("handleBootNotificationResponse...\n");
  11093. json_object *BootNotification;
  11094. BootNotification = json_tokener_parse(payload);
  11095. if(!is_error(BootNotification))
  11096. {
  11097. // Required data
  11098. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11099. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11100. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11101. }
  11102. json_object_put(BootNotification);
  11103. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11104. BootNotificationInterval = intervalInt;
  11105. HeartBeatWaitTime = intervalInt;
  11106. //write back to ShmOCPP16Data->BootNotification
  11107. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11108. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11109. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11110. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11111. {
  11112. server_sign = TRUE;
  11113. server_pending =FALSE;
  11114. }
  11115. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11116. {
  11117. server_pending = TRUE;
  11118. }
  11119. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11120. srand(time(NULL));
  11121. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11122. SetOcppConnStatus(TRUE);
  11123. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11124. }
  11125. void handleDataTransferResponse(char *payload, int gun_index)
  11126. {
  11127. char sstr[160]={0};//sstr[200]={ 0 };
  11128. int c = 0;
  11129. char *loc;
  11130. DEBUG_INFO("handleDataTransferResponse ...\n");
  11131. loc = strstr(payload, "status");
  11132. printf("loc=%s\n",loc);
  11133. c = 0;
  11134. while (loc[3+strlen("status")+c] != '\"')
  11135. {
  11136. sstr[c] = loc[3+strlen("status")+c];
  11137. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11138. c++;
  11139. }
  11140. sstr[c] = '\0';
  11141. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11142. }
  11143. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11144. {
  11145. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11146. //struct json_object *obj;
  11147. // obj = json_tokener_parse(payload);
  11148. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11149. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11150. //No fields are defined.
  11151. }
  11152. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11153. {
  11154. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11155. //struct json_object *obj;
  11156. // obj = json_tokener_parse(payload);
  11157. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11158. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11159. //No fields are defined.
  11160. }
  11161. void handleHeartbeatResponse(char *payload, int gun_index)
  11162. {
  11163. mtrace();
  11164. DEBUG_INFO("handleHeartbeatResponse...\n");
  11165. json_object *Heartbeat;
  11166. Heartbeat = json_tokener_parse(payload);
  11167. if(!is_error(Heartbeat))
  11168. {
  11169. // Required data
  11170. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11171. }
  11172. json_object_put(Heartbeat);
  11173. if(FirstHeartBeat == 0)
  11174. {
  11175. FirstHeartBeat = 1;
  11176. DEBUG_INFO("FirstHeartBeat \n");
  11177. }
  11178. HeartBeatWithNOResponse = 0;
  11179. clientTime.Heartbeat=time((time_t*)NULL);
  11180. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11181. }
  11182. void handleMeterValuesResponse(char *payload, int gun_index)
  11183. {
  11184. mtrace();
  11185. DEBUG_INFO("handleMeterValuesResponse...\n");
  11186. }
  11187. void handleStartTransactionResponse(char *payload, int gun_index)
  11188. {
  11189. mtrace();
  11190. //int transactionIdInt = 0;
  11191. FILE *outfile;
  11192. char data[100]={0};
  11193. DEBUG_INFO("handleStartTransactionResponse...\n");
  11194. json_object *StartTransaction;
  11195. StartTransaction = json_tokener_parse(payload);
  11196. if(!is_error(StartTransaction))
  11197. {
  11198. // Required data
  11199. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11200. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11201. // Optional data
  11202. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11203. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11204. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11205. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11206. }
  11207. json_object_put(StartTransaction);
  11208. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11209. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11210. //-----------Start : write to the Queue TransactionId file -----------------//
  11211. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11212. {}
  11213. else
  11214. {
  11215. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11216. if(log == NULL)
  11217. {
  11218. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11219. return ;
  11220. }
  11221. else
  11222. {
  11223. fclose(log);
  11224. }
  11225. }
  11226. // open file for writing
  11227. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11228. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11229. {
  11230. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11231. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11232. fputs(data, outfile);
  11233. fclose (outfile);
  11234. }
  11235. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11236. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11237. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11238. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11239. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11240. }
  11241. void handleStatusNotificationResponse(char *payload, int gun_index)
  11242. {
  11243. mtrace();
  11244. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11245. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11246. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11247. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11248. }
  11249. void handleStopTransactionnResponse(char *payload, int gun_index)
  11250. {
  11251. mtrace();
  11252. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11253. json_object *StopTransaction;
  11254. StopTransaction = json_tokener_parse(payload);
  11255. if(!is_error(StopTransaction))
  11256. {
  11257. // Optional data
  11258. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11259. {
  11260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11261. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11263. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11264. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11265. }
  11266. }
  11267. json_object_put(StopTransaction);
  11268. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11269. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11270. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11271. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11272. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11273. }
  11274. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11275. {
  11276. mtrace();
  11277. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11278. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11279. }
  11280. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11281. {
  11282. mtrace();
  11283. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11284. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11285. }
  11286. void handleSignCertificateResponse(char *payload, int gun_index)
  11287. {
  11288. mtrace();
  11289. DEBUG_INFO("handleSignCertificateResponse...\n");
  11290. json_object *SignCertificate;
  11291. SignCertificate = json_tokener_parse(payload);
  11292. if(!is_error(SignCertificate))
  11293. {
  11294. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11295. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11296. }
  11297. json_object_put(SignCertificate);
  11298. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11299. }
  11300. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11301. {
  11302. mtrace();
  11303. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11304. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11305. }
  11306. //==========================================
  11307. // Handle Error routine
  11308. //==========================================
  11309. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11310. {
  11311. mtrace();
  11312. #ifdef SystemLogMessage
  11313. DEBUG_INFO("errorCode: %s\n", errorCode);
  11314. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11315. DEBUG_INFO("errorDetails: %s\n", payload);
  11316. #endif
  11317. }
  11318. //===============================================
  11319. // Common routine
  11320. //===============================================
  11321. int initialConfigurationTable(void)
  11322. {
  11323. //clock_t start_t, end_t, total_t;
  11324. FILE *fp;
  11325. FILE *outfile;
  11326. char str[512]={0};
  11327. char sstr[256]={0};
  11328. int c = 0;
  11329. char *loc;
  11330. int confVersion = 3;
  11331. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11332. //start_t = clock();
  11333. //printf("Starting of the program, start_t = %ld\n", start_t);
  11334. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11335. // Check configuration file size is correct
  11336. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11337. {
  11338. struct stat st;
  11339. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11340. if(st.st_size < 3100)
  11341. {
  11342. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11343. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11344. }
  11345. }
  11346. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11347. {
  11348. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11349. if(outfile == NULL)
  11350. {
  11351. DEBUG_INFO("Error opening file\n");
  11352. return FALSE;
  11353. }
  11354. /*Core Profile*/
  11355. //AllowOfflineTxForUnknownId
  11356. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11360. //AuthorizationCacheEnabled
  11361. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11365. //AuthorizeRemoteTxRequests
  11366. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11370. //BlinkRepeat
  11371. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11375. //ClockAlignedDataInterval
  11376. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11380. //ConnectionTimeOut
  11381. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11385. //GetConfigurationMaxKeys
  11386. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11390. // HeartbeatInterval
  11391. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11395. // LightIntensity
  11396. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11400. // LocalAuthorizeOffline
  11401. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11405. // LocalPreAuthorize
  11406. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11410. // MaxEnergyOnInvalidId
  11411. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11415. // MeterValuesAlignedData
  11416. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11420. else
  11421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11423. // MeterValuesAlignedDataMaxLength
  11424. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11428. else
  11429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11431. // MeterValuesSampledData
  11432. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11436. else
  11437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11439. // MeterValuesSampledDataMaxLength
  11440. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11444. else
  11445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11447. // MeterValueSampleInterval
  11448. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11452. // MinimumStatusDuration
  11453. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11456. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11458. // NumberOfConnectors
  11459. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11462. {
  11463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11464. }
  11465. else
  11466. {
  11467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11468. }
  11469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11470. // ResetRetries
  11471. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11475. // ConnectorPhaseRotation
  11476. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11480. // ConnectorPhaseRotationMaxLength
  11481. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11485. // StopTransactionOnEVSideDisconnect
  11486. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11490. // StopTransactionOnInvalidId
  11491. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11495. // StopTxnAlignedData
  11496. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11500. // StopTxnAlignedDataMaxLength
  11501. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11505. // StopTxnSampledData
  11506. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11510. else
  11511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11513. // StopTxnSampledDataMaxLength
  11514. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11517. {
  11518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11519. }
  11520. else
  11521. {
  11522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11523. }
  11524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11525. // SupportedFeatureProfiles
  11526. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11530. // SupportedFeatureProfilesMaxLength
  11531. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11535. // TransactionMessageAttempts
  11536. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11539. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11541. // TransactionMessageRetryInterval
  11542. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11545. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11547. // UnlockConnectorOnEVSideDisconnect
  11548. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11552. // WebSocketPingInterval
  11553. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11557. // QueueOffLineStartTransactionMessage
  11558. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11562. // AuthorizationKey
  11563. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11567. // SecurityProfile
  11568. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11572. // DefaultPrice
  11573. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11577. // CustomDisplayCostAndPrice
  11578. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11582. // CustomIdleFeeAfterStop
  11583. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11587. // Configuration Version
  11588. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11592. //* Local Auth List Management Profile*/
  11593. #if 0
  11594. //For OCTT Test Case
  11595. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11598. #endif
  11599. #if 1
  11600. //LocalAuthListEnabled
  11601. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11605. #endif
  11606. //LocalAuthListMaxLength
  11607. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11611. //SendLocalListMaxLength
  11612. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11616. //ReserveConnectorZeroSupported
  11617. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11621. //* Smart Charging Profile */
  11622. //ChargeProfileMaxStackLevel
  11623. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11627. // ChargingScheduleAllowedChargingRateUnit
  11628. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11632. // ChargingScheduleMaxPeriods
  11633. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11637. // ConnectorSwitch3to1PhaseSupported
  11638. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11642. // MaxChargingProfilesInstalled
  11643. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11647. fclose(outfile);
  11648. }
  11649. else
  11650. {
  11651. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11652. char keystr[60]={0};
  11653. char readonlystr[10]={0};
  11654. char valuestr[256]={0};
  11655. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11656. if(fp == NULL) {
  11657. DEBUG_INFO("Error opening file");
  11658. return FALSE;
  11659. }
  11660. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11661. {
  11662. //DEBUG_INFO("Get Configuration \n");
  11663. if(strlen(str) > 0)
  11664. {
  11665. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11666. //*************************key*********************************/
  11667. if(strstr(str, "key") != NULL)
  11668. {
  11669. loc = strstr(str, "key");
  11670. c = 0;
  11671. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11672. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11673. {
  11674. sstr[c] = loc[strlen("key")+3+c];
  11675. c++;
  11676. }
  11677. sstr[c] = '\0';
  11678. strcpy(keystr,sstr);
  11679. }
  11680. //*************************readonly*********************************/
  11681. if(strstr(str, "readonly") != NULL)
  11682. {
  11683. loc = strstr(str, "readonly");
  11684. c = 0;
  11685. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11686. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11687. {
  11688. sstr[c] = loc[strlen("readonly")+2+c];
  11689. c++;
  11690. }
  11691. sstr[c] = '\0';
  11692. strcpy(readonlystr,sstr);
  11693. }
  11694. //*************************value*********************************/
  11695. if(strstr(str, "value") != NULL)
  11696. {
  11697. loc = strstr(str, "value");
  11698. c = 0;
  11699. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11700. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11701. {
  11702. sstr[c] = loc[strlen("value")+3+c];
  11703. c++;
  11704. }
  11705. sstr[c] = '\0';
  11706. strcpy(valuestr,sstr);
  11707. }
  11708. // DEBUG_INFO("keystr=%s\n",keystr);
  11709. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11710. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11711. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11712. {
  11713. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11714. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11716. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11717. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11718. }
  11719. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11720. {
  11721. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11722. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11724. }
  11725. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11726. {
  11727. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11729. }
  11730. if(strcmp(keystr, "BlinkRepeat") == 0)
  11731. {
  11732. //Charger.BlinkRepeat = Integer.parseInt(value);
  11733. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11735. }
  11736. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11737. {
  11738. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11740. }
  11741. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11742. {
  11743. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11745. }
  11746. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11747. {
  11748. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11750. }
  11751. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11752. {
  11753. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11755. HeartBeatWaitTime = atoi(valuestr);
  11756. }
  11757. if(strcmp(keystr, "LightIntensity") == 0)
  11758. {
  11759. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11761. }
  11762. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11763. {
  11764. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11766. }
  11767. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11768. {
  11769. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11771. }
  11772. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11773. {
  11774. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11776. }
  11777. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11778. {
  11779. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11781. }
  11782. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11783. {
  11784. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11786. }
  11787. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11788. {
  11789. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11791. }
  11792. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11793. {
  11794. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11796. }
  11797. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11798. {
  11799. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11801. }
  11802. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11803. {
  11804. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11806. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11807. }
  11808. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11809. {
  11810. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11812. }
  11813. if(strcmp(keystr, "ResetRetries") == 0)
  11814. {
  11815. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11817. }
  11818. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11819. {
  11820. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11822. }
  11823. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11824. {
  11825. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11827. }
  11828. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11829. {
  11830. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11832. }
  11833. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11834. {
  11835. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11837. }
  11838. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11839. {
  11840. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11842. }
  11843. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11844. {
  11845. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11847. }
  11848. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11849. {
  11850. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11852. }
  11853. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11854. {
  11855. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11857. }
  11858. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11859. {
  11860. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11862. }
  11863. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11864. {
  11865. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11867. }
  11868. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11869. {
  11870. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11872. TransactionMessageAttemptsValue = atoi(valuestr);
  11873. }
  11874. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11875. {
  11876. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11878. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11879. }
  11880. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11881. {
  11882. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11884. }
  11885. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11886. {
  11887. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11889. }
  11890. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11891. {
  11892. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11894. }
  11895. if(strcmp(keystr, "AuthorizationKey") == 0)
  11896. {
  11897. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11898. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11900. }
  11901. if(strcmp(keystr, "SecurityProfile") == 0)
  11902. {
  11903. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11905. }
  11906. if(strcmp(keystr, "DefaultPrice") == 0)
  11907. {
  11908. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11910. }
  11911. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11912. {
  11913. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11915. }
  11916. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11917. {
  11918. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11920. }
  11921. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11922. {
  11923. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11925. }
  11926. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11927. {
  11928. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11930. }
  11931. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11932. {
  11933. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11935. }
  11936. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11937. {
  11938. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11940. }
  11941. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11942. {
  11943. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11945. }
  11946. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11947. {
  11948. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11950. }
  11951. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11952. {
  11953. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11955. }
  11956. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11957. {
  11958. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11960. }
  11961. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11962. {
  11963. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11965. }
  11966. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11967. {
  11968. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11970. }
  11971. }
  11972. }
  11973. fclose(fp);
  11974. }
  11975. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11976. {
  11977. return PASS;
  11978. }
  11979. else
  11980. {
  11981. return FAIL;
  11982. }
  11983. }
  11984. void StoreConfigurationTable(void)
  11985. {
  11986. FILE *outfile;
  11987. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11988. if(outfile == NULL)
  11989. {
  11990. DEBUG_INFO("Error opening file");
  11991. return ;
  11992. }
  11993. /*Core Profile*/
  11994. //AllowOfflineTxForUnknownId
  11995. /*
  11996. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11997. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12000. */
  12001. //DEBUG_INFO("data=%s\n",data);
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12003. //AuthorizationCacheEnabled
  12004. /*
  12005. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12008. */
  12009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12010. //AuthorizeRemoteTxRequests
  12011. /*
  12012. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12015. */
  12016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12017. //BlinkRepeat
  12018. /*
  12019. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12022. */
  12023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12024. //ClockAlignedDataInterval
  12025. /*
  12026. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12029. */
  12030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12031. //ConnectionTimeOut
  12032. /*
  12033. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12036. */
  12037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12038. //GetConfigurationMaxKeys
  12039. /*
  12040. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12043. */
  12044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12045. // HeartbeatInterval
  12046. /*
  12047. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12050. */
  12051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12052. // LightIntensity
  12053. /*
  12054. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12057. */
  12058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12059. // LocalAuthorizeOffline
  12060. /*
  12061. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12064. */
  12065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12066. // LocalPreAuthorize
  12067. /*
  12068. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12071. */
  12072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12073. // MaxEnergyOnInvalidId
  12074. /*
  12075. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12078. */
  12079. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12081. // MeterValuesAlignedData
  12082. /*
  12083. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12086. */
  12087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12088. // MeterValuesAlignedDataMaxLength
  12089. /*
  12090. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12093. */
  12094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12095. // MeterValuesSampledData
  12096. /*
  12097. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12100. */
  12101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12102. // MeterValuesSampledDataMaxLength
  12103. /*
  12104. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12107. */
  12108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12109. // MeterValueSampleInterval
  12110. /*
  12111. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12114. */
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12116. // MinimumStatusDuration
  12117. /*
  12118. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12121. */
  12122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12123. // NumberOfConnectors
  12124. /*
  12125. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12128. {
  12129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12130. }
  12131. else
  12132. {
  12133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12134. }
  12135. */
  12136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12137. // ResetRetries
  12138. /*
  12139. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12142. */
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12144. // ConnectorPhaseRotation
  12145. /*
  12146. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12149. */
  12150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12151. // ConnectorPhaseRotationMaxLength
  12152. /*
  12153. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12156. */
  12157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12158. // StopTransactionOnEVSideDisconnect
  12159. /*
  12160. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12163. */
  12164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12165. // StopTransactionOnInvalidId
  12166. /*
  12167. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12170. */
  12171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12172. // StopTxnAlignedData
  12173. /*
  12174. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12177. */
  12178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12179. // StopTxnAlignedDataMaxLength
  12180. /*
  12181. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12184. */
  12185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12186. // StopTxnSampledData
  12187. /*
  12188. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12191. */
  12192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12193. // StopTxnSampledDataMaxLength
  12194. /*
  12195. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12198. */
  12199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12200. // SupportedFeatureProfiles
  12201. /*
  12202. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12205. */
  12206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12207. // SupportedFeatureProfilesMaxLength
  12208. /*
  12209. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12212. */
  12213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12214. // TransactionMessageAttempts
  12215. /*
  12216. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12219. */
  12220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12221. // TransactionMessageRetryInterval
  12222. /*
  12223. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12226. */
  12227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12228. // UnlockConnectorOnEVSideDisconnect
  12229. /*
  12230. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12233. */
  12234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12235. // WebSocketPingInterval
  12236. /*
  12237. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12240. */
  12241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12242. // QueueOffLineStartTransactionMessage
  12243. /*
  12244. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12247. */
  12248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12249. // AuthorizationKey
  12250. /*
  12251. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12254. */
  12255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12256. // SecurityProfile
  12257. /*
  12258. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12261. */
  12262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12263. // DefaultPrice
  12264. /*
  12265. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12268. */
  12269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12270. // CustomDisplayCostAndPrice
  12271. /*
  12272. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12275. */
  12276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12277. // CustomIdleFeeAfterStop
  12278. /*
  12279. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12282. */
  12283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12284. // ConfigurationVersion
  12285. /*
  12286. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12289. */
  12290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12291. //* Local Auth List Management Profile*/
  12292. //LocalAuthListEnabled
  12293. /*
  12294. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12297. */
  12298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12299. //LocalAuthListMaxLength
  12300. /*
  12301. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12304. */
  12305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12306. //SendLocalListMaxLength
  12307. /*
  12308. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12311. */
  12312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12313. //ReserveConnectorZeroSupported
  12314. /*
  12315. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12318. */
  12319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12320. //* Smart Charging Profile */
  12321. //ChargeProfileMaxStackLevel
  12322. /*
  12323. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12326. */
  12327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12328. // ChargingScheduleAllowedChargingRateUnit
  12329. /*
  12330. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12333. */
  12334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12335. // ChargingScheduleMaxPeriods
  12336. /*
  12337. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12340. */
  12341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12342. // ConnectorSwitch3to1PhaseSupported
  12343. /*
  12344. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12347. */
  12348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12349. // MaxChargingProfilesInstalled
  12350. /*
  12351. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12354. */
  12355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12356. fclose(outfile);
  12357. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12358. }
  12359. void getKeyValue(char *keyReq)
  12360. {
  12361. int isEmpty = FALSE;
  12362. int isKnowKey = FALSE;
  12363. DEBUG_INFO("keyReq = %s\n", keyReq);
  12364. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12365. isEmpty = TRUE;
  12366. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12367. {
  12368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12371. {
  12372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12373. }
  12374. else
  12375. {
  12376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12377. }
  12378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12379. isKnowKey = TRUE;
  12380. }
  12381. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12382. {
  12383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12386. {
  12387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12388. }
  12389. else
  12390. {
  12391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12392. }
  12393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12394. isKnowKey = TRUE;
  12395. }
  12396. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12397. {
  12398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12401. {
  12402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12403. }
  12404. else
  12405. {
  12406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12407. }
  12408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12409. isKnowKey = TRUE;
  12410. }
  12411. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12412. {
  12413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12416. {
  12417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12418. }
  12419. else
  12420. {
  12421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12422. }
  12423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12424. isKnowKey = TRUE;
  12425. }
  12426. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12427. {
  12428. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12431. {
  12432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12433. }
  12434. else
  12435. {
  12436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12437. }
  12438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12439. isKnowKey = TRUE;
  12440. }
  12441. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12442. {
  12443. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12446. {
  12447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12448. }
  12449. else
  12450. {
  12451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12452. }
  12453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12454. isKnowKey = TRUE;
  12455. }
  12456. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12457. {
  12458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12461. {
  12462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12463. }
  12464. else
  12465. {
  12466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12467. }
  12468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12469. isKnowKey = TRUE;
  12470. }
  12471. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12472. {
  12473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12476. {
  12477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12478. }
  12479. else
  12480. {
  12481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12482. }
  12483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12484. isKnowKey = TRUE;
  12485. }
  12486. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12487. {
  12488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12491. {
  12492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12493. }
  12494. else
  12495. {
  12496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12497. }
  12498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12499. isKnowKey = TRUE;
  12500. }
  12501. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12502. {
  12503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12506. {
  12507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12508. }
  12509. else
  12510. {
  12511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12512. }
  12513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12514. isKnowKey = TRUE;
  12515. }
  12516. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12517. {
  12518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12521. {
  12522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12523. }
  12524. else
  12525. {
  12526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12527. }
  12528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12529. isKnowKey = TRUE;
  12530. }
  12531. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12532. {
  12533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12536. {
  12537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12538. }
  12539. else
  12540. {
  12541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12542. }
  12543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12544. isKnowKey = TRUE;
  12545. }
  12546. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12547. {
  12548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12551. {
  12552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12553. }
  12554. else
  12555. {
  12556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12557. }
  12558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12559. isKnowKey = TRUE;
  12560. }
  12561. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12562. {
  12563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12566. {
  12567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12568. }
  12569. else
  12570. {
  12571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12572. }
  12573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12574. isKnowKey = TRUE;
  12575. }
  12576. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12577. {
  12578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12581. {
  12582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12583. }
  12584. else
  12585. {
  12586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12587. }
  12588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12589. isKnowKey = TRUE;
  12590. }
  12591. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12592. {
  12593. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12596. {
  12597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12598. }
  12599. else
  12600. {
  12601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12602. }
  12603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12604. isKnowKey = TRUE;
  12605. }
  12606. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12607. {
  12608. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12611. {
  12612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12613. }
  12614. else
  12615. {
  12616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12617. }
  12618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12619. isKnowKey = TRUE;
  12620. }
  12621. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12622. {
  12623. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12626. {
  12627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12628. }
  12629. else
  12630. {
  12631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12632. }
  12633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12634. isKnowKey = TRUE;
  12635. }
  12636. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12637. {
  12638. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12641. {
  12642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12643. }
  12644. else
  12645. {
  12646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12647. }
  12648. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12650. isKnowKey = TRUE;
  12651. }
  12652. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12653. {
  12654. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12657. {
  12658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12659. }
  12660. else
  12661. {
  12662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12663. }
  12664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12665. isKnowKey = TRUE;
  12666. }
  12667. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12668. {
  12669. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12672. {
  12673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12674. }
  12675. else
  12676. {
  12677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12678. }
  12679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12680. isKnowKey = TRUE;
  12681. }
  12682. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12683. {
  12684. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12687. {
  12688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12689. }
  12690. else
  12691. {
  12692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12693. }
  12694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12695. isKnowKey = TRUE;
  12696. }
  12697. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12698. {
  12699. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12702. {
  12703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12704. }
  12705. else
  12706. {
  12707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12708. }
  12709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12710. isKnowKey = TRUE;
  12711. }
  12712. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12713. {
  12714. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12716. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12717. {
  12718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12719. }
  12720. else
  12721. {
  12722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12723. }
  12724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12725. isKnowKey = TRUE;
  12726. }
  12727. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12728. {
  12729. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12732. {
  12733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12734. }
  12735. else
  12736. {
  12737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12738. }
  12739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12740. isKnowKey = TRUE;
  12741. }
  12742. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12743. {
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12747. {
  12748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12749. }
  12750. else
  12751. {
  12752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12753. }
  12754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12755. isKnowKey = TRUE;
  12756. }
  12757. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12758. {
  12759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12762. {
  12763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12764. }
  12765. else
  12766. {
  12767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12768. }
  12769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12770. isKnowKey = TRUE;
  12771. }
  12772. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12773. {
  12774. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12777. {
  12778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12779. }
  12780. else
  12781. {
  12782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12783. }
  12784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12785. isKnowKey = TRUE;
  12786. }
  12787. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12788. {
  12789. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12792. {
  12793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12794. }
  12795. else
  12796. {
  12797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12798. }
  12799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12800. isKnowKey = TRUE;
  12801. }
  12802. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12803. {
  12804. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12807. {
  12808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12809. }
  12810. else
  12811. {
  12812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12813. }
  12814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12815. isKnowKey = TRUE;
  12816. }
  12817. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12818. {
  12819. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12822. {
  12823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12824. }
  12825. else
  12826. {
  12827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12828. }
  12829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12830. isKnowKey = TRUE;
  12831. }
  12832. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12833. {
  12834. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12837. {
  12838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12839. }
  12840. else
  12841. {
  12842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12843. }
  12844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12845. isKnowKey = TRUE;
  12846. }
  12847. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12848. {
  12849. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12852. {
  12853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12854. }
  12855. else
  12856. {
  12857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12858. }
  12859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12860. isKnowKey = TRUE;
  12861. }
  12862. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12863. {
  12864. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12867. {
  12868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12869. }
  12870. else
  12871. {
  12872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12873. }
  12874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12875. isKnowKey = TRUE;
  12876. }
  12877. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12878. {
  12879. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12882. {
  12883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12884. }
  12885. else
  12886. {
  12887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12888. }
  12889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12890. isKnowKey = TRUE;
  12891. }
  12892. /*
  12893. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12894. {
  12895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12898. {
  12899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12900. }
  12901. else
  12902. {
  12903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12904. }
  12905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12906. isKnowKey = TRUE;
  12907. }*/
  12908. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12909. {
  12910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12913. {
  12914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12915. }
  12916. else
  12917. {
  12918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12919. }
  12920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12921. isKnowKey = TRUE;
  12922. }
  12923. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12924. {
  12925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12928. {
  12929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12930. }
  12931. else
  12932. {
  12933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12934. }
  12935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12936. isKnowKey = TRUE;
  12937. }
  12938. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12939. {
  12940. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12942. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12943. {
  12944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12945. }
  12946. else
  12947. {
  12948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12949. }
  12950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12951. isKnowKey = TRUE;
  12952. }
  12953. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12954. {
  12955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12958. {
  12959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12960. }
  12961. else
  12962. {
  12963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12964. }
  12965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12966. isKnowKey = TRUE;
  12967. }
  12968. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12969. {
  12970. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12973. {
  12974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12975. }
  12976. else
  12977. {
  12978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12979. }
  12980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12981. isKnowKey = TRUE;
  12982. }
  12983. #if 1
  12984. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12985. {
  12986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12988. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12989. {
  12990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12991. }
  12992. else
  12993. {
  12994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12995. }
  12996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12997. isKnowKey = TRUE;
  12998. }
  12999. #endif
  13000. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13001. {
  13002. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13004. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13005. {
  13006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13007. }
  13008. else
  13009. {
  13010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13011. }
  13012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13013. isKnowKey = TRUE;
  13014. }
  13015. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13016. {
  13017. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13019. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13020. {
  13021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13022. }
  13023. else
  13024. {
  13025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13026. }
  13027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13028. isKnowKey = TRUE;
  13029. }
  13030. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13031. {
  13032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13034. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13035. {
  13036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13037. }
  13038. else
  13039. {
  13040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13041. }
  13042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13043. isKnowKey = TRUE;
  13044. }
  13045. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13046. {
  13047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13049. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13050. {
  13051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13052. }
  13053. else
  13054. {
  13055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13056. }
  13057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13058. isKnowKey = TRUE;
  13059. }
  13060. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13061. {
  13062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13064. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13065. {
  13066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13067. }
  13068. else
  13069. {
  13070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13071. }
  13072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13073. isKnowKey = TRUE;
  13074. }
  13075. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13076. {
  13077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13079. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13080. {
  13081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13082. }
  13083. else
  13084. {
  13085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13086. }
  13087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13088. isKnowKey = TRUE;
  13089. }
  13090. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13091. {
  13092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13094. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13095. {
  13096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13097. }
  13098. else
  13099. {
  13100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13101. }
  13102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13103. isKnowKey = TRUE;
  13104. }
  13105. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13106. {
  13107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13109. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13110. {
  13111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13112. }
  13113. else
  13114. {
  13115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13116. }
  13117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13118. isKnowKey = TRUE;
  13119. }
  13120. //=========================================================
  13121. if(!isEmpty && !isKnowKey)
  13122. {
  13123. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13124. strcpy(unknownkey[UnknownKeynum], keyReq);
  13125. UnknownKeynum = UnknownKeynum + 1;
  13126. }
  13127. }
  13128. void processUnkownKey(void)
  13129. {
  13130. DEBUG_INFO("processUnkownKey...\n");
  13131. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13132. for(int index=0; index < UnknownKeynum; index++)
  13133. {
  13134. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13135. {
  13136. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13137. }
  13138. }
  13139. }
  13140. int setKeyValue(char *key, char *value)
  13141. {
  13142. int isSuccess = NotSupported;
  13143. int check_ascii=0;
  13144. char str[256]={0};
  13145. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13146. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13147. {
  13148. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13150. {
  13151. strcpy(str, (const char*)value);
  13152. for(int i = 0; str[i]; i++){
  13153. str[i] = tolower(str[i]);
  13154. }
  13155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13156. isSuccess = ConfigurationStatus_Accepted;
  13157. }
  13158. else
  13159. {
  13160. isSuccess = ConfigurationStatus_Rejected;
  13161. }
  13162. }
  13163. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13164. {
  13165. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13167. {
  13168. strcpy(str, (const char*)value);
  13169. for(int i = 0; str[i]; i++){
  13170. str[i] = tolower(str[i]);
  13171. }
  13172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13173. isSuccess = ConfigurationStatus_Accepted;
  13174. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13175. }
  13176. else
  13177. {
  13178. isSuccess = ConfigurationStatus_Rejected;
  13179. }
  13180. }
  13181. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13182. {
  13183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13184. {
  13185. strcpy(str, (const char*)value);
  13186. for(int i = 0; str[i]; i++)
  13187. {
  13188. str[i] = tolower(str[i]);
  13189. }
  13190. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13192. isSuccess = ConfigurationStatus_Accepted;
  13193. }
  13194. else
  13195. {
  13196. isSuccess = ConfigurationStatus_Rejected;
  13197. }
  13198. }
  13199. if(strcmp(key, "BlinkRepeat") == 0)
  13200. {
  13201. //Charger.BlinkRepeat = Integer.parseInt(value);
  13202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13203. {
  13204. check_ascii = value[0];
  13205. if( (check_ascii < 48) || (check_ascii > 57) )
  13206. {
  13207. isSuccess = ConfigurationStatus_Rejected;
  13208. }
  13209. else
  13210. {
  13211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13212. isSuccess = ConfigurationStatus_Accepted;
  13213. }
  13214. }
  13215. else
  13216. {
  13217. isSuccess = ConfigurationStatus_Rejected;
  13218. }
  13219. }
  13220. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13221. {
  13222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13223. {
  13224. check_ascii = value[0];
  13225. if( (check_ascii < 48) || (check_ascii > 57) )
  13226. {
  13227. isSuccess = ConfigurationStatus_Rejected;
  13228. }
  13229. else
  13230. {
  13231. if((atoi(value) == 0) || (atoi(value) >= 10))
  13232. {
  13233. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13235. isSuccess = ConfigurationStatus_Accepted;
  13236. }
  13237. else
  13238. isSuccess = ConfigurationStatus_Rejected;
  13239. }
  13240. }
  13241. else
  13242. {
  13243. isSuccess = ConfigurationStatus_Rejected;
  13244. }
  13245. }
  13246. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13247. {
  13248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13249. {
  13250. check_ascii = value[0];
  13251. if( (check_ascii < 48) || (check_ascii > 57) )
  13252. {
  13253. isSuccess = ConfigurationStatus_Rejected;
  13254. }
  13255. else
  13256. {
  13257. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13259. isSuccess = ConfigurationStatus_Accepted;
  13260. }
  13261. }
  13262. else
  13263. {
  13264. isSuccess = ConfigurationStatus_Rejected;
  13265. }
  13266. }
  13267. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13268. {
  13269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13270. {
  13271. check_ascii = value[0];
  13272. if( (check_ascii < 48) || (check_ascii > 57) )
  13273. {
  13274. isSuccess = ConfigurationStatus_Rejected;
  13275. }
  13276. else
  13277. {
  13278. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13280. isSuccess = ConfigurationStatus_Accepted;
  13281. }
  13282. }
  13283. else
  13284. {
  13285. isSuccess = ConfigurationStatus_Rejected;
  13286. }
  13287. }
  13288. if(strcmp(key, "HeartbeatInterval") == 0)
  13289. {
  13290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13291. {
  13292. check_ascii = value[0];
  13293. if( (check_ascii < 48) || (check_ascii > 57) )
  13294. {
  13295. isSuccess = ConfigurationStatus_Rejected;
  13296. }
  13297. else
  13298. {
  13299. if((atoi(value) == 0) || (atoi(value) >= 10))
  13300. {
  13301. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13303. HeartBeatWaitTime = atoi(value);
  13304. isSuccess = ConfigurationStatus_Accepted;
  13305. }
  13306. else
  13307. {
  13308. isSuccess = ConfigurationStatus_Rejected;
  13309. }
  13310. }
  13311. }
  13312. else
  13313. {
  13314. isSuccess = ConfigurationStatus_Rejected;
  13315. }
  13316. }
  13317. if(strcmp(key, "LightIntensity") == 0)
  13318. {
  13319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13320. {
  13321. check_ascii = value[0];
  13322. if( (check_ascii < 48) || (check_ascii > 57) )
  13323. {
  13324. isSuccess = ConfigurationStatus_Rejected;
  13325. }
  13326. else
  13327. {
  13328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13329. isSuccess = ConfigurationStatus_Accepted;
  13330. }
  13331. }
  13332. else
  13333. {
  13334. isSuccess = ConfigurationStatus_Rejected;
  13335. }
  13336. }
  13337. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13338. {
  13339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13340. {
  13341. strcpy(str, (const char*)value);
  13342. for(int i = 0; str[i]; i++)
  13343. {
  13344. str[i] = tolower(str[i]);
  13345. }
  13346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13347. isSuccess = ConfigurationStatus_Accepted;
  13348. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13349. }
  13350. else
  13351. {
  13352. isSuccess = ConfigurationStatus_Rejected;
  13353. }
  13354. }
  13355. if(strcmp(key, "LocalPreAuthorize") == 0)
  13356. {
  13357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13358. {
  13359. strcpy(str, (const char*)value);
  13360. for(int i = 0; str[i]; i++)
  13361. {
  13362. str[i] = tolower(str[i]);
  13363. }
  13364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13365. isSuccess = ConfigurationStatus_Accepted;
  13366. }
  13367. else
  13368. {
  13369. isSuccess = ConfigurationStatus_Rejected;
  13370. }
  13371. }
  13372. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13373. {
  13374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13375. {
  13376. check_ascii = value[0];
  13377. if( (check_ascii < 48) || (check_ascii > 57) )
  13378. {
  13379. isSuccess = ConfigurationStatus_Rejected;
  13380. }
  13381. else
  13382. {
  13383. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13384. isSuccess = ConfigurationStatus_Accepted;
  13385. }
  13386. }
  13387. else
  13388. {
  13389. isSuccess = ConfigurationStatus_Rejected;
  13390. }
  13391. }
  13392. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13393. {
  13394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13395. {
  13396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13397. isSuccess = ConfigurationStatus_Accepted;
  13398. }
  13399. else
  13400. {
  13401. isSuccess = ConfigurationStatus_Rejected;
  13402. }
  13403. }
  13404. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13405. {
  13406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13407. {
  13408. check_ascii = value[0];
  13409. if( (check_ascii < 48) || (check_ascii > 57) )
  13410. {
  13411. isSuccess = ConfigurationStatus_Rejected;
  13412. }
  13413. else
  13414. {
  13415. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13417. isSuccess = ConfigurationStatus_Accepted;
  13418. }
  13419. }
  13420. else
  13421. {
  13422. isSuccess = ConfigurationStatus_Rejected;
  13423. }
  13424. }
  13425. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13426. {
  13427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13428. {
  13429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13430. isSuccess = ConfigurationStatus_Accepted;
  13431. }
  13432. else
  13433. {
  13434. isSuccess = ConfigurationStatus_Rejected;
  13435. }
  13436. }
  13437. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13438. {
  13439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].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. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13450. isSuccess = ConfigurationStatus_Accepted;
  13451. }
  13452. }
  13453. else
  13454. {
  13455. isSuccess = ConfigurationStatus_Rejected;
  13456. }
  13457. }
  13458. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13459. {
  13460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13461. {
  13462. check_ascii = value[0];
  13463. if( (check_ascii < 48) || (check_ascii > 57) )
  13464. {
  13465. isSuccess = ConfigurationStatus_Rejected;
  13466. }
  13467. else
  13468. {
  13469. if((atoi(value) == 0) || (atoi(value) >= 10))
  13470. {
  13471. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13473. isSuccess = ConfigurationStatus_Accepted;
  13474. }
  13475. else
  13476. {
  13477. isSuccess = ConfigurationStatus_Rejected;
  13478. }
  13479. }
  13480. }
  13481. else
  13482. {
  13483. isSuccess = ConfigurationStatus_Rejected;
  13484. }
  13485. }
  13486. if(strcmp(key, "MinimumStatusDuration") == 0)
  13487. {
  13488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13489. {
  13490. check_ascii = value[0];
  13491. if( (check_ascii < 48) || (check_ascii > 57) )
  13492. {
  13493. isSuccess = ConfigurationStatus_Rejected;
  13494. }
  13495. else
  13496. {
  13497. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13498. {
  13499. isSuccess = ConfigurationStatus_Rejected;
  13500. }
  13501. else
  13502. {
  13503. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13505. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13506. isSuccess = ConfigurationStatus_Accepted;
  13507. }
  13508. }
  13509. }
  13510. else
  13511. {
  13512. isSuccess = ConfigurationStatus_Rejected;
  13513. }
  13514. }
  13515. if(strcmp(key, "NumberOfConnectors") == 0)
  13516. {
  13517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13518. {
  13519. check_ascii = value[0];
  13520. if( (check_ascii < 48) || (check_ascii > 57) )
  13521. {
  13522. isSuccess = ConfigurationStatus_Rejected;
  13523. }
  13524. else
  13525. {
  13526. //Charger.ResetRetries = Integer.parseInt(value);
  13527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13528. isSuccess = ConfigurationStatus_Accepted;
  13529. }
  13530. }
  13531. else
  13532. {
  13533. isSuccess = ConfigurationStatus_Rejected;
  13534. }
  13535. }
  13536. if(strcmp(key, "ResetRetries") == 0)
  13537. {
  13538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13539. {
  13540. check_ascii = value[0];
  13541. if( (check_ascii < 48) || (check_ascii > 57) )
  13542. {
  13543. isSuccess = ConfigurationStatus_Rejected;
  13544. }
  13545. else
  13546. {
  13547. //Charger.ResetRetries = Integer.parseInt(value);
  13548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13549. isSuccess = ConfigurationStatus_Accepted;
  13550. }
  13551. }
  13552. else
  13553. {
  13554. isSuccess = ConfigurationStatus_Rejected;
  13555. }
  13556. }
  13557. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13558. {
  13559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13560. {
  13561. strcpy(str, (const char*)value);
  13562. for(int i = 0; str[i]; i++)
  13563. {
  13564. str[i] = tolower(str[i]);
  13565. }
  13566. if(strcmp(str, "notapplicable")== 0)
  13567. {
  13568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13569. isSuccess = ConfigurationStatus_Accepted;
  13570. }
  13571. else if(strcmp(str, "unknown")== 0)
  13572. {
  13573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13574. isSuccess = ConfigurationStatus_Accepted;
  13575. }
  13576. else if(strcmp(str, "rst")== 0)
  13577. {
  13578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13579. isSuccess = ConfigurationStatus_Accepted;
  13580. }
  13581. else if(strcmp(str, "rts")== 0)
  13582. {
  13583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13584. isSuccess = ConfigurationStatus_Accepted;
  13585. }
  13586. else if(strcmp(str, "srt")== 0)
  13587. {
  13588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13589. isSuccess = ConfigurationStatus_Accepted;
  13590. }
  13591. else if(strcmp(str, "str")== 0)
  13592. {
  13593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13594. isSuccess = ConfigurationStatus_Accepted;
  13595. }
  13596. else if(strcmp(str, "trs")== 0)
  13597. {
  13598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13599. isSuccess = ConfigurationStatus_Accepted;
  13600. }
  13601. else if(strcmp(str, "tsr")== 0)
  13602. {
  13603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13604. isSuccess = ConfigurationStatus_Accepted;
  13605. }
  13606. else
  13607. {
  13608. isSuccess = ConfigurationStatus_Rejected;
  13609. }
  13610. }
  13611. else
  13612. {
  13613. isSuccess = ConfigurationStatus_Rejected;
  13614. }
  13615. }
  13616. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13617. {
  13618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13619. {
  13620. check_ascii = value[0];
  13621. if( (check_ascii < 48) || (check_ascii > 57) )
  13622. {
  13623. isSuccess = ConfigurationStatus_Rejected;
  13624. }
  13625. else
  13626. {
  13627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13628. isSuccess = ConfigurationStatus_Accepted;
  13629. }
  13630. }
  13631. else
  13632. {
  13633. isSuccess = ConfigurationStatus_Rejected;
  13634. }
  13635. }
  13636. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13637. {
  13638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13639. {
  13640. strcpy(str, (const char*)value);
  13641. for(int i = 0; str[i]; i++)
  13642. {
  13643. str[i] = tolower(str[i]);
  13644. }
  13645. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13647. isSuccess = ConfigurationStatus_Accepted;
  13648. }
  13649. else
  13650. {
  13651. isSuccess = ConfigurationStatus_Rejected;
  13652. }
  13653. }
  13654. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13655. {
  13656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13657. {
  13658. strcpy(str, (const char*)value);
  13659. for(int i = 0; str[i]; i++)
  13660. {
  13661. str[i] = tolower(str[i]);
  13662. }
  13663. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13665. isSuccess = ConfigurationStatus_Accepted;
  13666. }
  13667. else
  13668. {
  13669. isSuccess = ConfigurationStatus_Rejected;
  13670. }
  13671. }
  13672. if(strcmp(key, "StopTxnAlignedData") == 0)
  13673. {
  13674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13675. {
  13676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13677. isSuccess = ConfigurationStatus_Accepted;
  13678. }
  13679. else
  13680. {
  13681. isSuccess = ConfigurationStatus_Rejected;
  13682. }
  13683. }
  13684. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13685. {
  13686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13687. {
  13688. check_ascii = value[0];
  13689. if( (check_ascii < 48) || (check_ascii > 57) )
  13690. {
  13691. isSuccess = ConfigurationStatus_Rejected;
  13692. }
  13693. else
  13694. {
  13695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13696. isSuccess = ConfigurationStatus_Accepted;
  13697. }
  13698. }
  13699. else
  13700. {
  13701. isSuccess = ConfigurationStatus_Rejected;
  13702. }
  13703. }
  13704. if(strcmp(key, "StopTxnSampledData") == 0)
  13705. {
  13706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13707. {
  13708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13709. isSuccess = ConfigurationStatus_Accepted;
  13710. }
  13711. else
  13712. {
  13713. isSuccess = ConfigurationStatus_Rejected;
  13714. }
  13715. }
  13716. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13717. {
  13718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13719. {
  13720. check_ascii = value[0];
  13721. if( (check_ascii < 48) || (check_ascii > 57) )
  13722. {
  13723. isSuccess = ConfigurationStatus_Rejected;
  13724. }
  13725. else
  13726. {
  13727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13728. isSuccess = ConfigurationStatus_Accepted;
  13729. }
  13730. }
  13731. else
  13732. {
  13733. isSuccess = ConfigurationStatus_Rejected;
  13734. }
  13735. }
  13736. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13737. {
  13738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13739. {
  13740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13741. isSuccess = ConfigurationStatus_Accepted;
  13742. }
  13743. else
  13744. {
  13745. isSuccess = ConfigurationStatus_Rejected;
  13746. }
  13747. }
  13748. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13749. {
  13750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13751. {
  13752. check_ascii = value[0];
  13753. if( (check_ascii < 48) || (check_ascii > 57) )
  13754. {
  13755. isSuccess = ConfigurationStatus_Rejected;
  13756. }
  13757. else
  13758. {
  13759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13760. isSuccess = ConfigurationStatus_Accepted;
  13761. }
  13762. }
  13763. else
  13764. {
  13765. isSuccess = ConfigurationStatus_Rejected;
  13766. }
  13767. }
  13768. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13769. {
  13770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13771. {
  13772. check_ascii = value[0];
  13773. if( (check_ascii < 48) || (check_ascii > 57) )
  13774. {
  13775. isSuccess = ConfigurationStatus_Rejected;
  13776. }
  13777. else
  13778. {
  13779. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13781. TransactionMessageAttemptsValue = atoi(value);
  13782. isSuccess = ConfigurationStatus_Accepted;
  13783. }
  13784. }
  13785. else
  13786. {
  13787. isSuccess = ConfigurationStatus_Rejected;
  13788. }
  13789. }
  13790. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13791. {
  13792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13793. {
  13794. check_ascii = value[0];
  13795. if( (check_ascii < 48) || (check_ascii > 57) )
  13796. {
  13797. isSuccess = ConfigurationStatus_Rejected;
  13798. }
  13799. else
  13800. {
  13801. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13803. TransactionMessageRetryIntervalValue = atoi(value);
  13804. isSuccess = ConfigurationStatus_Accepted;
  13805. }
  13806. }
  13807. else
  13808. {
  13809. isSuccess = ConfigurationStatus_Rejected;
  13810. }
  13811. }
  13812. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13813. {
  13814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13815. {
  13816. strcpy(str, (const char*)value);
  13817. for(int i = 0; str[i]; i++)
  13818. {
  13819. str[i] = tolower(str[i]);
  13820. }
  13821. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13823. isSuccess = ConfigurationStatus_Accepted;
  13824. }
  13825. else
  13826. {
  13827. isSuccess = ConfigurationStatus_Rejected;
  13828. }
  13829. }
  13830. if(strcmp(key, "WebSocketPingInterval") == 0)
  13831. {
  13832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13833. {
  13834. check_ascii = value[0];
  13835. if( (check_ascii < 48) || (check_ascii > 57) )
  13836. {
  13837. isSuccess = ConfigurationStatus_Rejected;
  13838. }
  13839. else
  13840. {
  13841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13842. isSuccess = ConfigurationStatus_Accepted;
  13843. }
  13844. }
  13845. else
  13846. {
  13847. isSuccess = ConfigurationStatus_Rejected;
  13848. }
  13849. }
  13850. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13851. {
  13852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13853. {
  13854. strcpy(str, (const char*)value);
  13855. for(int i = 0; str[i]; i++)
  13856. {
  13857. str[i] = tolower(str[i]);
  13858. }
  13859. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13861. isSuccess = ConfigurationStatus_Accepted;
  13862. }
  13863. else
  13864. {
  13865. isSuccess = ConfigurationStatus_Rejected;
  13866. }
  13867. }
  13868. if(strcmp(key, "AuthorizationKey") == 0)
  13869. {
  13870. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13871. {
  13872. strcpy(str, (const char*)value);
  13873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13874. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13875. isSuccess = ConfigurationStatus_Accepted;
  13876. }
  13877. else
  13878. {
  13879. isSuccess = ConfigurationStatus_Rejected;
  13880. }
  13881. }
  13882. if(strcmp(key, "SecurityProfile") == 0)
  13883. {
  13884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13885. {
  13886. check_ascii = value[0];
  13887. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13888. {
  13889. isSuccess = ConfigurationStatus_Rejected;
  13890. }
  13891. else if(check_ascii == 0x33)
  13892. {
  13893. isSuccess = NotSupported;
  13894. }
  13895. else
  13896. {
  13897. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13898. {
  13899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13900. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13901. isSuccess = ConfigurationStatus_Accepted;
  13902. }
  13903. else
  13904. isSuccess = ConfigurationStatus_Rejected;
  13905. }
  13906. }
  13907. else
  13908. {
  13909. isSuccess = ConfigurationStatus_Rejected;
  13910. }
  13911. }
  13912. if(strcmp(key, "DefaultPrice") == 0)
  13913. {
  13914. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13915. {
  13916. strcpy(str, (const char*)value);
  13917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13918. isSuccess = ConfigurationStatus_Accepted;
  13919. }
  13920. else
  13921. {
  13922. isSuccess = ConfigurationStatus_Rejected;
  13923. }
  13924. }
  13925. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13926. {
  13927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13928. {
  13929. strcpy(str, (const char*)value);
  13930. for(int i = 0; str[i]; i++)
  13931. {
  13932. str[i] = tolower(str[i]);
  13933. }
  13934. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13936. isSuccess = ConfigurationStatus_Accepted;
  13937. }
  13938. else
  13939. {
  13940. isSuccess = ConfigurationStatus_Rejected;
  13941. }
  13942. }
  13943. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13944. {
  13945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13946. {
  13947. strcpy(str, (const char*)value);
  13948. for(int i = 0; str[i]; i++)
  13949. {
  13950. str[i] = tolower(str[i]);
  13951. }
  13952. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13954. isSuccess = ConfigurationStatus_Accepted;
  13955. }
  13956. else
  13957. {
  13958. isSuccess = ConfigurationStatus_Rejected;
  13959. }
  13960. }
  13961. #if 0
  13962. //For OCPP Test Case
  13963. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13964. {
  13965. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13966. {
  13967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13968. isSuccess = ConfigurationStatus_Accepted;
  13969. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13970. }
  13971. else
  13972. {
  13973. isSuccess = ConfigurationStatus_Rejected;
  13974. }
  13975. }
  13976. #endif
  13977. #if 1
  13978. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13979. {
  13980. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13981. {
  13982. strcpy(str, (const char*)value);
  13983. for(int i = 0; str[i]; i++)
  13984. {
  13985. str[i] = tolower(str[i]);
  13986. }
  13987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13988. isSuccess = ConfigurationStatus_Accepted;
  13989. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13990. }
  13991. else
  13992. {
  13993. isSuccess = ConfigurationStatus_Rejected;
  13994. }
  13995. }
  13996. #endif
  13997. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13998. {
  13999. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14000. {
  14001. check_ascii = value[0];
  14002. if( (check_ascii < 48) || (check_ascii > 57) )
  14003. {
  14004. isSuccess = ConfigurationStatus_Rejected;
  14005. }
  14006. else
  14007. {
  14008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14009. isSuccess = ConfigurationStatus_Accepted;
  14010. }
  14011. }
  14012. else
  14013. {
  14014. isSuccess = ConfigurationStatus_Rejected;
  14015. }
  14016. }
  14017. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14018. {
  14019. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14020. {
  14021. check_ascii = value[0];
  14022. if( (check_ascii < 48) || (check_ascii > 57) )
  14023. {
  14024. isSuccess = ConfigurationStatus_Rejected;
  14025. }
  14026. else
  14027. {
  14028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14029. isSuccess = ConfigurationStatus_Accepted;
  14030. }
  14031. }
  14032. else
  14033. {
  14034. isSuccess = ConfigurationStatus_Rejected;
  14035. }
  14036. }
  14037. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14038. {
  14039. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14040. {
  14041. strcpy(str, (const char*)value);
  14042. for(int i = 0; str[i]; i++)
  14043. {
  14044. str[i] = tolower(str[i]);
  14045. }
  14046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14047. isSuccess = ConfigurationStatus_Accepted;
  14048. }
  14049. else
  14050. {
  14051. isSuccess = ConfigurationStatus_Rejected;
  14052. }
  14053. }
  14054. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14055. {
  14056. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14057. {
  14058. check_ascii = value[0];
  14059. if( (check_ascii < 48) || (check_ascii > 57) )
  14060. {
  14061. isSuccess = ConfigurationStatus_Rejected;
  14062. }
  14063. else
  14064. {
  14065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14066. isSuccess = ConfigurationStatus_Accepted;
  14067. }
  14068. }
  14069. else
  14070. {
  14071. isSuccess = ConfigurationStatus_Rejected;
  14072. }
  14073. }
  14074. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14075. {
  14076. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14077. {
  14078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14079. isSuccess = ConfigurationStatus_Accepted;
  14080. }
  14081. else
  14082. {
  14083. isSuccess = ConfigurationStatus_Rejected;
  14084. }
  14085. }
  14086. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14087. {
  14088. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14089. {
  14090. check_ascii = value[0];
  14091. if( (check_ascii < 48) || (check_ascii > 57) )
  14092. {
  14093. isSuccess = ConfigurationStatus_Rejected;
  14094. }
  14095. else
  14096. {
  14097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14098. isSuccess = ConfigurationStatus_Accepted;
  14099. }
  14100. }
  14101. else
  14102. {
  14103. isSuccess = ConfigurationStatus_Rejected;
  14104. }
  14105. }
  14106. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14107. {
  14108. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14109. {
  14110. strcpy(str, (const char*)value);
  14111. for(int i = 0; str[i]; i++)
  14112. {
  14113. str[i] = tolower(str[i]);
  14114. }
  14115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14116. isSuccess = ConfigurationStatus_Accepted;
  14117. }
  14118. else
  14119. {
  14120. isSuccess = ConfigurationStatus_Rejected;
  14121. }
  14122. }
  14123. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14124. {
  14125. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14126. {
  14127. check_ascii = value[0];
  14128. if( (check_ascii < 48) || (check_ascii > 57) )
  14129. {
  14130. isSuccess = ConfigurationStatus_Rejected;
  14131. }
  14132. else
  14133. {
  14134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14135. isSuccess = ConfigurationStatus_Accepted;
  14136. }
  14137. }
  14138. else
  14139. {
  14140. isSuccess = ConfigurationStatus_Rejected;
  14141. }
  14142. }
  14143. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14144. return isSuccess;
  14145. }
  14146. int TransactionMessageAttemptsGet(void)
  14147. {
  14148. return TransactionMessageAttemptsValue;
  14149. }
  14150. int FirstHeartBeatResponse(void)
  14151. {
  14152. return FirstHeartBeat;
  14153. }
  14154. int TransactionMessageRetryIntervalGet(void)
  14155. {
  14156. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14157. }
  14158. int ReadHttpStatus(int sock)
  14159. {
  14160. //char c;
  14161. char buff[1024]="",*ptr=buff+1;
  14162. int bytes_received, status;
  14163. DEBUG_INFO("Begin Response ..\n");
  14164. while((bytes_received = recv(sock, ptr, 1, 0))){
  14165. if(bytes_received==-1){
  14166. perror("ReadHttpStatus");
  14167. exit(1);
  14168. }
  14169. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14170. ptr++;
  14171. }
  14172. *ptr=0;
  14173. ptr=buff+1;
  14174. sscanf(ptr,"%*s %d ", &status);
  14175. DEBUG_INFO("%s\n",ptr);
  14176. DEBUG_INFO("status=%d\n",status);
  14177. DEBUG_INFO("End Response ..\n");
  14178. return (bytes_received>0)?status:0;
  14179. }
  14180. //the only filed that it parsed is 'Content-Length'
  14181. int ParseHeader(int sock)
  14182. {
  14183. //char c;
  14184. char buff[1024]="",*ptr=buff+4;
  14185. int bytes_received;
  14186. DEBUG_INFO("Begin HEADER ..\n");
  14187. while((bytes_received = recv(sock, ptr, 1, 0))){
  14188. if(bytes_received==-1){
  14189. perror("Parse Header");
  14190. exit(1);
  14191. }
  14192. if(
  14193. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14194. (ptr[-1]=='\r') && (*ptr=='\n' )
  14195. ) break;
  14196. ptr++;
  14197. }
  14198. *ptr=0;
  14199. ptr=buff+4;
  14200. //printf("%s",ptr);
  14201. if(bytes_received){
  14202. ptr=strstr(ptr,"Content-Length:");
  14203. if(ptr){
  14204. sscanf(ptr,"%*s %d",&bytes_received);
  14205. }else
  14206. bytes_received=-1; //unknown size
  14207. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14208. }
  14209. DEBUG_INFO("End HEADER ..\n");
  14210. return bytes_received ;
  14211. }
  14212. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14213. {
  14214. int result = TRUE;
  14215. char rmFileCmd[100]={0};
  14216. char FilePath[100]={0};
  14217. char ftpbuf[200];
  14218. int systemresult;
  14219. //DEBUG_INFO("filename=%s\n",filename);
  14220. //DEBUG_INFO("url=%s\n",url);
  14221. sprintf(FilePath,"/mnt/%s",filename);
  14222. system("ping 8.8.8.8 &");
  14223. if((access(FilePath,F_OK))!=-1)
  14224. {
  14225. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14226. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14227. system(rmFileCmd);
  14228. }
  14229. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14230. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14231. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14232. systemresult = system(ftpbuf);
  14233. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14234. if(systemresult != 0)
  14235. {
  14236. DEBUG_INFO("http DownLoad error!\n");
  14237. result = FALSE;
  14238. }
  14239. system("pkill ping");
  14240. return result;
  14241. }
  14242. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14243. {
  14244. int result = TRUE;
  14245. char rmFileCmd[100]={0};
  14246. char FilePath[100]={0};
  14247. char ftpbuf[200];
  14248. int systemresult;
  14249. //char temp[100];
  14250. sprintf(FilePath,"/mnt/%s",filename);
  14251. system("ping 8.8.8.8 &");
  14252. if((access(FilePath,F_OK))!=-1)
  14253. {
  14254. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14255. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14256. system(rmFileCmd);
  14257. }
  14258. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14259. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14260. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14261. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14262. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14263. systemresult = system(ftpbuf);
  14264. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14265. if(systemresult != 0)
  14266. {
  14267. printf("wget error!\n");
  14268. result = FALSE;
  14269. }
  14270. system("pkill ping");
  14271. return result;
  14272. }
  14273. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14274. {
  14275. char rmFileCmd[100]={0};
  14276. char FilePath[100]={0};
  14277. char buf[512];
  14278. int systemresult = 0;
  14279. //DEBUG_INFO("filename=%s\n",filename);
  14280. //DEBUG_INFO("url=%s\n",url);
  14281. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14282. if((access(FilePath,F_OK))!=-1)
  14283. {
  14284. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14285. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14286. system(rmFileCmd);
  14287. }
  14288. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14289. if(fp == NULL)
  14290. {
  14291. DEBUG_INFO("log is NULL\n");
  14292. return FALSE;
  14293. }
  14294. else
  14295. {
  14296. fprintf(fp, "%s\n", url);
  14297. fprintf(fp, "%s\n", filename);
  14298. fclose(fp);
  14299. }
  14300. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14301. if(phpFP == NULL)
  14302. {
  14303. DEBUG_INFO("PHP upload fail.\n");
  14304. return FALSE;
  14305. }
  14306. else
  14307. {
  14308. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14309. {
  14310. if(strstr(buf, "result") != NULL)
  14311. {
  14312. sscanf(buf, "result: %d", &systemresult);
  14313. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14314. }
  14315. }
  14316. pclose(phpFP);
  14317. }
  14318. if(systemresult != 1)
  14319. {
  14320. DEBUG_INFO("HTTP upload error!\n");
  14321. return FALSE;
  14322. }
  14323. return TRUE;
  14324. }
  14325. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14326. {
  14327. struct hostent* server;
  14328. char *IPbuffer;
  14329. char ftpbuf[200];
  14330. int systemresult;
  14331. // To retrieve host information
  14332. server = gethostbyname(location);
  14333. // To convert an Internet network
  14334. // address into ASCII string
  14335. IPbuffer = inet_ntoa(*((struct in_addr*)
  14336. server->h_addr_list[0]));
  14337. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14338. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14339. /* format : ftpput -u username -p passwd IP target source*/
  14340. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14341. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14342. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14343. systemresult = system(ftpbuf);
  14344. DEBUG_INFO("systemresult=%d\n",systemresult);
  14345. if(systemresult != 0)
  14346. {
  14347. DEBUG_INFO("ftpput error!\n");
  14348. return FALSE;
  14349. }
  14350. return TRUE;
  14351. }
  14352. int GetOcppServerURL()
  14353. {
  14354. int result = FALSE;
  14355. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14356. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14357. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14358. struct yuarel url;
  14359. char urlStr[512];
  14360. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14361. {
  14362. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14363. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14364. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14365. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14366. if(yuarel_parse(&url, urlStr) != -1)
  14367. {
  14368. sprintf(OcppProtocol, "%s", url.scheme);
  14369. sprintf(OcppHost, "%s", url.host);
  14370. if(url.path == NULL)
  14371. OcppTempPath[0] = '\0';
  14372. else
  14373. {
  14374. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14375. {
  14376. sprintf(OcppTempPath, "%s/", url.path);
  14377. }
  14378. else
  14379. {
  14380. sprintf(OcppTempPath, "%s", url.path);
  14381. }
  14382. }
  14383. if(url.port == 0)
  14384. {
  14385. if(strcmp(OcppProtocol, "wss") == 0)
  14386. OcppPort = 443;
  14387. else
  14388. OcppPort = 80;
  14389. }
  14390. else
  14391. OcppPort = url.port;
  14392. result = TRUE;
  14393. }
  14394. }
  14395. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14396. {
  14397. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14398. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14399. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14400. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14401. if(yuarel_parse(&url, urlStr) != -1)
  14402. {
  14403. sprintf(OcppProtocol, "%s", url.scheme);
  14404. sprintf(OcppHost, "%s", url.host);
  14405. if(url.path == NULL)
  14406. OcppTempPath[0] = '\0';
  14407. else
  14408. sprintf(OcppTempPath, "%s", url.path);
  14409. if(url.port == 0)
  14410. {
  14411. if(strcmp(OcppProtocol, "wss") == 0)
  14412. OcppPort = 443;
  14413. else
  14414. OcppPort = 80;
  14415. }
  14416. else
  14417. OcppPort = url.port;
  14418. result = TRUE;
  14419. }
  14420. }
  14421. else
  14422. {
  14423. strcpy(OcppHost,"");
  14424. }
  14425. return result;
  14426. }
  14427. int GetOcppPath()
  14428. {
  14429. int result = FALSE;
  14430. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14431. {
  14432. if(OcppTempPath == NULL)
  14433. {
  14434. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14435. }
  14436. else
  14437. {
  14438. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14439. }
  14440. result = TRUE;
  14441. goto End;
  14442. }
  14443. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14444. {
  14445. if(OcppTempPath == NULL)
  14446. {
  14447. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14448. }
  14449. else
  14450. {
  14451. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14452. }
  14453. result = TRUE;
  14454. goto End;
  14455. }
  14456. else
  14457. {
  14458. strcpy(OcppPath,"");
  14459. }
  14460. End:
  14461. return result;
  14462. }
  14463. int GetOcppPort()
  14464. {
  14465. return OcppPort;
  14466. }
  14467. int GetOcppConnStatus(void)
  14468. {
  14469. return ShmOCPP16Data->OcppConnStatus;
  14470. }
  14471. void SetOcppConnStatus(uint8_t status)
  14472. {
  14473. ShmOCPP16Data->OcppConnStatus = status;
  14474. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14475. }
  14476. int GetHeartBeatWithNOResponse(void)
  14477. {
  14478. return HeartBeatWithNOResponse;
  14479. }
  14480. void SetHeartBeatWithNOResponse(void)
  14481. {
  14482. HeartBeatWithNOResponse = 0;
  14483. }
  14484. void GetStartTransactionIdTag(int gun_index)
  14485. {
  14486. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14487. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14488. }
  14489. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14490. {
  14491. char ch;
  14492. FILE *fptr1;
  14493. int temptransactionId;
  14494. char str[100]={0};
  14495. temptransactionId = 0;
  14496. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14497. {
  14498. DEBUG_INFO("IdTag is empty.\n");
  14499. return temptransactionId;
  14500. }
  14501. /*------ Read the file ----------------*/
  14502. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14503. if (!fptr1)
  14504. {
  14505. DEBUG_INFO("QueueTransactionId file open error.\n");
  14506. //printf(" File not found or unable to open the input file!!\n");
  14507. return temptransactionId;
  14508. }
  14509. ch=fgetc(fptr1);
  14510. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14511. rewind(fptr1);
  14512. if(ch!=EOF)
  14513. {
  14514. // printf("%c",ch);
  14515. while (fgets(str, 100, fptr1) != NULL)
  14516. {
  14517. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14518. if(str[0]=='\0')
  14519. {
  14520. break;
  14521. }
  14522. char *revbuf[8] = {0}; // Variable store string split
  14523. int num = 0;// Quantity after string split
  14524. DEBUG_INFO("Transaction queue data= %s\n", str);
  14525. splitstring(str,",",revbuf,&num); // String split
  14526. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14527. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14528. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14529. DEBUG_INFO("------------------------------\n");
  14530. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14531. {
  14532. if(isStopTransaction)
  14533. {
  14534. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14535. {
  14536. temptransactionId = atoi(revbuf[2]);
  14537. //break;
  14538. }
  14539. }
  14540. else
  14541. {
  14542. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14543. {
  14544. temptransactionId = atoi(revbuf[2]);
  14545. //break;
  14546. }
  14547. }
  14548. }
  14549. }
  14550. }
  14551. else
  14552. DEBUG_INFO("EOF\n");
  14553. fclose(fptr1);
  14554. /*------- End of reading ---------------*/
  14555. return temptransactionId;
  14556. }
  14557. void SetTransactionIdZero(int transactionId)
  14558. {
  14559. char ch;
  14560. FILE *fptr1, *fptr2;
  14561. int temptransactionId = 0;
  14562. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14563. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14564. if (!fptr1)
  14565. {
  14566. //printf(" File not found or unable to open the input file!!\n");
  14567. return ;
  14568. }
  14569. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14570. if (!fptr2)
  14571. {
  14572. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14573. fclose(fptr1);
  14574. return ;
  14575. }
  14576. ch=fgetc(fptr1);
  14577. rewind(fptr1);
  14578. if(ch!=EOF)
  14579. {
  14580. // copy all contents to the temporary file except the specific line
  14581. while (fgets(str, 100, fptr1) != NULL)
  14582. {
  14583. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14584. if(str[0]=='\0')
  14585. {
  14586. break;
  14587. }
  14588. char *revbuf[8] = {0};
  14589. int num = 0;
  14590. strcpy(strtemp, str);
  14591. splitstring(str,",",revbuf,&num);
  14592. if(revbuf[2][0] != '\0')
  14593. {
  14594. temptransactionId = atoi(revbuf[2]);
  14595. if(transactionId != temptransactionId)
  14596. {
  14597. fprintf(fptr2, "%s\n", strtemp);
  14598. }
  14599. }
  14600. }
  14601. }
  14602. fclose(fptr1);
  14603. fclose(fptr2);
  14604. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14605. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14606. /*------ Read the file ----------------*/
  14607. }
  14608. int InternetDisconnect(void)
  14609. {
  14610. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14611. }
  14612. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14613. void storeTempStopTransaction(int gun_index)
  14614. {
  14615. char guid[37]={0};
  14616. int tempIndex = 0;
  14617. char TempStopTransaction[256];
  14618. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14619. DEBUG_INFO("storeTempStopTransaction...\n");
  14620. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14621. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14622. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14623. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14624. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14625. {
  14626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14627. {
  14628. tempIndex = ((gun_index==2) ? 1: 0);
  14629. }
  14630. else
  14631. {
  14632. tempIndex = gun_index;
  14633. }
  14634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14635. {
  14636. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14637. {
  14638. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14639. }
  14640. }// END OF CHAdeMO_QUANTITY
  14641. }
  14642. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14643. {
  14644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14645. {
  14646. tempIndex = ((gun_index==2) ? 1: 0);
  14647. }
  14648. else
  14649. {
  14650. tempIndex = gun_index;
  14651. }
  14652. for (int index = 0; index < CCS_QUANTITY; index++)
  14653. {
  14654. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14655. {
  14656. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14657. }
  14658. }// END OF CCS_QUANTITY
  14659. }
  14660. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14661. {
  14662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14663. {
  14664. tempIndex = ((gun_index==2) ? 1: 0);
  14665. }
  14666. else
  14667. {
  14668. tempIndex = gun_index;
  14669. }
  14670. for (int index = 0; index < GB_QUANTITY; index++)
  14671. {
  14672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14673. {
  14674. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14675. }
  14676. }// END OF GB_QUANTITY
  14677. }
  14678. else if(gunType[gun_index] == GUN_TYPE_DO)
  14679. {
  14680. tempIndex = gun_index;
  14681. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14682. {
  14683. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14684. {
  14685. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14686. }
  14687. }
  14688. }
  14689. else
  14690. {
  14691. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14692. {
  14693. tempIndex = 2;
  14694. }
  14695. else
  14696. {
  14697. tempIndex = gun_index;
  14698. }
  14699. for (int index = 0; index < AC_QUANTITY; index++)
  14700. {
  14701. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14702. {
  14703. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14704. }
  14705. }// END OF AC_QUANTITY
  14706. }
  14707. //Stop Transaction Time
  14708. struct timeval tmnow;
  14709. struct tm *tm;
  14710. char buf[28];//, usec_buf[6];
  14711. gettimeofday(&tmnow, NULL);
  14712. time_t t;
  14713. t = time(NULL);
  14714. /*UTC time and date*/
  14715. tm = gmtime(&t);
  14716. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14718. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14720. random_uuid(guid);
  14721. /***********************************transactionData******************************************************/
  14722. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14724. //=================================
  14725. //1. Transaction_Begin
  14726. //=================================
  14727. //============================== Energy.Active.Import.Interval ===========================================
  14728. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14729. {
  14730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14733. 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*/]);
  14734. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14735. 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))
  14736. {
  14737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14738. }
  14739. else
  14740. {
  14741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14742. }
  14743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14745. }
  14746. //=================================
  14747. //2. Transaction_End
  14748. //=================================
  14749. //2.1====================================== Current.Import L1 ==============================================
  14750. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14751. {
  14752. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14753. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14754. {
  14755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14756. {
  14757. tempIndex = ((gun_index==2) ? 1: 0);
  14758. }
  14759. else
  14760. {
  14761. tempIndex = gun_index;
  14762. }
  14763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14764. {
  14765. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14766. {
  14767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14768. }
  14769. }// End of for CHAdeMO_QUANTITY
  14770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14771. }
  14772. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14773. {
  14774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14775. {
  14776. tempIndex = ((gun_index==2) ? 1: 0);
  14777. }
  14778. else
  14779. {
  14780. tempIndex = gun_index;
  14781. }
  14782. for (int index = 0; index < CCS_QUANTITY; index++)
  14783. {
  14784. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14785. {
  14786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14787. }
  14788. }// End of for CCS_QUANTITY
  14789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14790. }
  14791. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14792. {
  14793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14794. {
  14795. tempIndex = ((gun_index==2) ? 1: 0);
  14796. }
  14797. else
  14798. {
  14799. tempIndex = gun_index;
  14800. }
  14801. for (int index = 0; index < GB_QUANTITY; index++)
  14802. {
  14803. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14804. {
  14805. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14806. }
  14807. }// End of for GB_QUANTITY
  14808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14809. }
  14810. else if(gunType[gun_index] == GUN_TYPE_DO)
  14811. {
  14812. tempIndex = gun_index;
  14813. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14814. {
  14815. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14816. {
  14817. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14818. }
  14819. }
  14820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14821. }
  14822. else
  14823. {
  14824. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14825. {
  14826. tempIndex = 2;
  14827. }
  14828. else
  14829. {
  14830. tempIndex = gun_index;
  14831. }
  14832. for (int index = 0; index < AC_QUANTITY; index++)
  14833. {
  14834. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14835. {
  14836. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14837. }
  14838. }// End of for AC_QUANTITY
  14839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14840. }
  14841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14842. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14844. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14847. }
  14848. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14849. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14850. {
  14851. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14852. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14853. {
  14854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14855. {
  14856. tempIndex = ((gun_index==2) ? 1: 0);
  14857. }
  14858. else
  14859. {
  14860. tempIndex = gun_index;
  14861. }
  14862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14863. {
  14864. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14865. {
  14866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14867. }
  14868. }// END OF CHAdeMO_QUANTITY
  14869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14870. }
  14871. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14872. {
  14873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14874. {
  14875. tempIndex = ((gun_index==2) ? 1: 0);
  14876. }
  14877. else
  14878. {
  14879. tempIndex = gun_index;
  14880. }
  14881. for (int index = 0; index < CCS_QUANTITY; index++)
  14882. {
  14883. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14884. {
  14885. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14886. }
  14887. }// END OF CCS_QUANTITY
  14888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14889. }
  14890. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14891. {
  14892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14893. {
  14894. tempIndex = ((gun_index==2) ? 1: 0);
  14895. }
  14896. else
  14897. {
  14898. tempIndex = gun_index;
  14899. }
  14900. for (int index = 0; index < GB_QUANTITY; index++)
  14901. {
  14902. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14903. {
  14904. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14905. }
  14906. }// END OF GB_QUANTITY
  14907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14908. }
  14909. else if(gunType[gun_index] == GUN_TYPE_DO)
  14910. {
  14911. tempIndex = gun_index;
  14912. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14913. {
  14914. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14915. {
  14916. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14917. }
  14918. }
  14919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14920. }
  14921. else
  14922. {
  14923. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14924. {
  14925. tempIndex = 2;
  14926. }
  14927. else
  14928. {
  14929. tempIndex = gun_index;
  14930. }
  14931. for (int index = 0; index < AC_QUANTITY; index++)
  14932. {
  14933. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14934. {
  14935. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14936. }
  14937. }// END OF AC_QUANTITY
  14938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14939. }
  14940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14943. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14946. }
  14947. //2.3====================================== Power.Active.Import =========================================
  14948. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14949. {
  14950. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14951. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14952. {
  14953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14954. {
  14955. tempIndex = ((gun_index==2) ? 1: 0);
  14956. }
  14957. else
  14958. {
  14959. tempIndex = gun_index;
  14960. }
  14961. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14962. {
  14963. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14964. {
  14965. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14966. }
  14967. } // End for CHAdeMO_QUANTITY
  14968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14969. }
  14970. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14971. {
  14972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14973. {
  14974. tempIndex = ((gun_index==2) ? 1: 0);
  14975. }
  14976. else
  14977. {
  14978. tempIndex = gun_index;
  14979. }
  14980. for (int index = 0; index < CCS_QUANTITY; index++)
  14981. {
  14982. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14983. {
  14984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14985. }
  14986. } // END for CCS_QUANTITY
  14987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14988. }
  14989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14990. {
  14991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14992. {
  14993. tempIndex = ((gun_index==2) ? 1: 0);
  14994. }
  14995. else
  14996. {
  14997. tempIndex = gun_index;
  14998. }
  14999. for (int index = 0; index < GB_QUANTITY; index++)
  15000. {
  15001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15002. {
  15003. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15004. }
  15005. }// END for GB_QUANTITY
  15006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15007. }
  15008. else if(gunType[gun_index] == GUN_TYPE_DO)
  15009. {
  15010. tempIndex = gun_index;
  15011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15012. {
  15013. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15014. {
  15015. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15016. }
  15017. }
  15018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15019. }
  15020. else
  15021. {
  15022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15023. {
  15024. tempIndex = 2;
  15025. }
  15026. else
  15027. {
  15028. tempIndex = gun_index;
  15029. }
  15030. for (int index = 0; index < AC_QUANTITY; index++)
  15031. {
  15032. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15033. {
  15034. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15035. }
  15036. } // END for AC_QUANTITY
  15037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15038. }
  15039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15042. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15045. }
  15046. //2.4====================================== Voltage L1 ====================================================
  15047. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15048. {
  15049. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15050. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15051. {
  15052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15053. {
  15054. tempIndex = ((gun_index==2) ? 1: 0);
  15055. }
  15056. else
  15057. {
  15058. tempIndex = gun_index;
  15059. }
  15060. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15061. {
  15062. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15063. {
  15064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15065. }
  15066. } // END OF FOR CHAdeMO_QUANTITY
  15067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15068. }
  15069. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15070. {
  15071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15072. {
  15073. tempIndex = ((gun_index==2) ? 1: 0);
  15074. }
  15075. else
  15076. {
  15077. tempIndex = gun_index;
  15078. }
  15079. for (int index = 0; index < CCS_QUANTITY; index++)
  15080. {
  15081. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15082. {
  15083. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15084. }
  15085. } // END OF FOR CCS_QUANTITY
  15086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15087. }
  15088. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15089. {
  15090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15091. {
  15092. tempIndex = ((gun_index==2) ? 1: 0);
  15093. }
  15094. else
  15095. {
  15096. tempIndex = gun_index;
  15097. }
  15098. for (int index = 0; index < GB_QUANTITY; index++)
  15099. {
  15100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15101. {
  15102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15103. }
  15104. } // END OF FOR GB_QUANTITY
  15105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15106. }
  15107. else if(gunType[gun_index] == GUN_TYPE_DO)
  15108. {
  15109. tempIndex = gun_index;
  15110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15111. {
  15112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15113. {
  15114. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15115. }
  15116. }
  15117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15118. }
  15119. else
  15120. {
  15121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15122. {
  15123. tempIndex = 2;
  15124. }
  15125. else
  15126. {
  15127. tempIndex = gun_index;
  15128. }
  15129. for (int index = 0; index < AC_QUANTITY; index++)
  15130. {
  15131. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15132. {
  15133. 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
  15134. }
  15135. } // END OF FOR AC_QUANTITY
  15136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15137. }
  15138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15141. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15144. }
  15145. //2.5============================================== End SoC =========================================================
  15146. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15147. {
  15148. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15149. 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))
  15150. {
  15151. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15152. {
  15153. tempIndex = ((gun_index==2) ? 1: 0);
  15154. }
  15155. else
  15156. {
  15157. tempIndex = gun_index;
  15158. }
  15159. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15160. {
  15161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15162. {
  15163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15164. {
  15165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15166. }
  15167. }
  15168. }
  15169. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15170. {
  15171. for (int index = 0; index < CCS_QUANTITY; index++)
  15172. {
  15173. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15174. {
  15175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15176. }
  15177. }
  15178. }
  15179. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15180. {
  15181. for (int index = 0; index < GB_QUANTITY; index++)
  15182. {
  15183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15184. {
  15185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15186. }
  15187. }
  15188. }
  15189. else if(gunType[gun_index] == GUN_TYPE_DO)
  15190. {
  15191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15192. {
  15193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15194. {
  15195. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15196. }
  15197. }
  15198. }
  15199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15205. } // END FOR DC CASE
  15206. }
  15207. //2.6====================================== Current.Import L2 ==============================================
  15208. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15209. {
  15210. // AC 3 phase L2 current
  15211. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15212. {
  15213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15214. {
  15215. tempIndex = 2;
  15216. }
  15217. else
  15218. {
  15219. tempIndex = gun_index;
  15220. }
  15221. for (int index = 0; index < AC_QUANTITY; index++)
  15222. {
  15223. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15224. {
  15225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15226. }
  15227. }// End of for AC_QUANTITY
  15228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15229. }
  15230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15235. }
  15236. //2.7====================================== Current.Import L3 ==============================================
  15237. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15238. {
  15239. // AC 3 phase L3 current
  15240. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15241. {
  15242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15243. {
  15244. tempIndex = 2;
  15245. }
  15246. else
  15247. {
  15248. tempIndex = gun_index;
  15249. }
  15250. for (int index = 0; index < AC_QUANTITY; index++)
  15251. {
  15252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15253. {
  15254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15255. }
  15256. }// End of for AC_QUANTITY
  15257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15258. }
  15259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15264. }
  15265. //2.9====================================== Voltage L2 ====================================================
  15266. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15267. {
  15268. // AC 3 phase L2 volatge
  15269. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15270. {
  15271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15272. {
  15273. tempIndex = 2;
  15274. }
  15275. else
  15276. {
  15277. tempIndex = gun_index;
  15278. }
  15279. for (int index = 0; index < AC_QUANTITY; index++)
  15280. {
  15281. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15282. {
  15283. 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
  15284. }
  15285. } // END OF FOR AC_QUANTITY
  15286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15287. }
  15288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15293. }
  15294. //2.10====================================== Voltage L3 ====================================================
  15295. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15296. {
  15297. // AC 3 phase L3 volatge
  15298. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15299. {
  15300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15301. {
  15302. tempIndex = 2;
  15303. }
  15304. else
  15305. {
  15306. tempIndex = gun_index;
  15307. }
  15308. for (int index = 0; index < AC_QUANTITY; index++)
  15309. {
  15310. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15311. {
  15312. 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
  15313. }
  15314. } // END OF FOR AC_QUANTITY
  15315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15316. }
  15317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15322. }
  15323. //====================== Start SoC ================================
  15324. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15325. {
  15326. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15327. 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))
  15328. {
  15329. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15330. {
  15331. tempIndex = ((gun_index==2) ? 1: 0);
  15332. }
  15333. else
  15334. {
  15335. tempIndex = gun_index;
  15336. }
  15337. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15338. {
  15339. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15340. {
  15341. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15342. {
  15343. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15344. }
  15345. }
  15346. }
  15347. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15348. {
  15349. for (int index = 0; index < CCS_QUANTITY; index++)
  15350. {
  15351. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15352. {
  15353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15354. }
  15355. }
  15356. }
  15357. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15358. {
  15359. for (int index = 0; index < GB_QUANTITY; index++)
  15360. {
  15361. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15362. {
  15363. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15364. }
  15365. }
  15366. }
  15367. else if(gunType[gun_index] == GUN_TYPE_DO)
  15368. {
  15369. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15370. {
  15371. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15372. {
  15373. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15374. }
  15375. }
  15376. }
  15377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15383. } // END FOR DC CASE
  15384. }
  15385. //======================================== Message create ==============================================
  15386. json_object *StopTransaction = json_object_new_object();
  15387. json_object *transactionDatas = json_object_new_array();
  15388. json_object *sampledValues = json_object_new_array();
  15389. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15390. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15391. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15392. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15393. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15394. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15395. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15396. {
  15397. json_object *transactionData = json_object_new_object();
  15398. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15399. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15400. {
  15401. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15402. {
  15403. json_object *sampledValue = json_object_new_object();
  15404. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15405. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15406. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15407. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15408. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15409. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15410. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15411. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15412. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15413. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15414. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15415. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15416. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15417. json_object_array_add(sampledValues, sampledValue);
  15418. }
  15419. }
  15420. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15421. json_object_array_add(transactionDatas, transactionData);
  15422. }
  15423. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15424. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15425. ,MESSAGE_TYPE_CALL
  15426. ,guid
  15427. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15428. json_object_put(StopTransaction);
  15429. // Check File "TempStopTransaction" Exist
  15430. if((access(TempStopTransaction,F_OK))!=-1)
  15431. {
  15432. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15433. fclose(fopen(TempStopTransaction, "w"));
  15434. }
  15435. else
  15436. {
  15437. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15438. FILE *log = fopen(TempStopTransaction, "w+");
  15439. if(log == NULL)
  15440. {
  15441. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15442. return ;
  15443. }
  15444. else
  15445. {
  15446. fclose(log);
  15447. }
  15448. }
  15449. //Add TempStopTransaction | Update TempStopTransaction
  15450. // open file for writing
  15451. FILE *outfile;
  15452. outfile = fopen (TempStopTransaction, "a");
  15453. //DEBUG_INFO("data = %s\n", queuedata);
  15454. fputs(queuedata, outfile);
  15455. fputs("\n", outfile);
  15456. fclose (outfile);
  15457. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15458. }
  15459. void checkTempStopTransaction(int gun_index)
  15460. {
  15461. FILE *fptr1;
  15462. char ch;
  15463. char str[QUEUE_MESSAGE_LENGTH]={0};
  15464. char guid[37]={0};
  15465. char tempdata[65]={0};
  15466. char connectorStr[2]={0};
  15467. char TempStopTransaction[256];
  15468. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15469. fptr1 = fopen(TempStopTransaction, "r");
  15470. //TempStopTransaction格式: 槍號,StopTransaction封包
  15471. if (!fptr1)
  15472. {
  15473. //printf(" File not found or unable to open the input file!!\n");
  15474. return ;
  15475. }
  15476. ch=fgetc(fptr1);
  15477. //printf(" Now the content of the file %s is : \n",fname);
  15478. rewind(fptr1);
  15479. if(ch!=EOF)
  15480. {
  15481. // copy all contents to the temporary file except the specific line
  15482. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15483. {
  15484. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15485. if(str[0]=='\0')
  15486. {
  15487. break;
  15488. }
  15489. //TempStopTransaction格式: 槍號,StopTransaction封包
  15490. strncpy(connectorStr, str, 1);
  15491. if(atoi(connectorStr) != (gun_index+1))
  15492. {
  15493. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15494. fclose(fptr1);
  15495. return ;
  15496. }
  15497. //random_uuid(guid);
  15498. strncpy(guid, str+6, 36); //copy guid
  15499. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15500. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15501. {
  15502. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15503. }
  15504. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15505. OCPP_insert_transaction_msg(NO, str);
  15506. memset(str,0,ARRAY_SIZE(str));
  15507. }
  15508. }
  15509. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15510. fclose(fptr1);
  15511. remove(TempStopTransaction); // remove the original file
  15512. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15513. }
  15514. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15515. {
  15516. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15517. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15518. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15519. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15520. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15521. }
  15522. int GetWebSocketPingInterval(void)
  15523. {
  15524. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15525. }
  15526. int GetServerSign(void)
  15527. {
  15528. return server_sign;
  15529. }
  15530. uint8_t GetOcppSecurityProfile()
  15531. {
  15532. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15533. }
  15534. void GetOcppChargerBoxId(uint8_t *data)
  15535. {
  15536. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15537. }
  15538. void GetOcppSecurityPassword(uint8_t *data)
  15539. {
  15540. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15541. }
  15542. void SetOcppVersion(uint8_t *version)
  15543. {
  15544. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15545. DEBUG_INFO("ocpp version: %s\n", version);
  15546. if(strstr((char*)version, "ocpp1.6") != NULL)
  15547. {
  15548. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15549. }
  15550. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15551. {
  15552. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15553. system("pkill OcppBackend");
  15554. }
  15555. }
  15556. void SetServerSign(int value)
  15557. {
  15558. server_sign = value;
  15559. }
  15560. int GetBootNotificationInterval(void)
  15561. {
  15562. return BootNotificationInterval;
  15563. }
  15564. int GetInternetConn(void)
  15565. {
  15566. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15567. }
  15568. int GetBackendConnectionTimeout(void)
  15569. {
  15570. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15571. }
  15572. int isConnectorInitMode(int gun_index)
  15573. {
  15574. int tempIndex = 0;
  15575. int result = TRUE;
  15576. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15577. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15578. {
  15579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15580. {
  15581. tempIndex = ((gun_index==2) ? 1: 0);
  15582. }
  15583. else
  15584. {
  15585. tempIndex = gun_index;
  15586. }
  15587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15588. {
  15589. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15590. {
  15591. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15592. } //end of the same index
  15593. }//end of for CHAdeMO_QUANTITY
  15594. }
  15595. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15596. {
  15597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15598. {
  15599. tempIndex = ((gun_index==2) ? 1: 0);
  15600. }
  15601. else
  15602. {
  15603. tempIndex = gun_index;
  15604. }
  15605. for (int index = 0; index < CCS_QUANTITY; index++)
  15606. {
  15607. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15608. {
  15609. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15610. } //end of the same index
  15611. } // end of for CCS_QUANTITY
  15612. }
  15613. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15614. {
  15615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15616. {
  15617. tempIndex = ((gun_index==2) ? 1: 0);
  15618. }
  15619. else
  15620. {
  15621. tempIndex = gun_index;
  15622. }
  15623. for (int index = 0; index < GB_QUANTITY; index++)
  15624. {
  15625. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15626. {
  15627. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15628. } //end of the same index
  15629. } // end of for GB_QUANTITY
  15630. }
  15631. else if(gunType[gun_index] == GUN_TYPE_DO)
  15632. {
  15633. tempIndex = gun_index;
  15634. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15635. {
  15636. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15637. {
  15638. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15639. } //end of the same index
  15640. }
  15641. }
  15642. else
  15643. {
  15644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15645. {
  15646. tempIndex = 2;
  15647. }
  15648. else
  15649. {
  15650. tempIndex = gun_index;
  15651. }
  15652. for (int index = 0; index < AC_QUANTITY; index++)
  15653. {
  15654. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15655. {
  15656. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15657. }//end of the same index
  15658. }//end of for AC_QUANTITY
  15659. }
  15660. return result;
  15661. }
  15662. void refreshProcDogTimer()
  15663. {
  15664. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15665. }
  15666. void InitialSystemValue(void)
  15667. {
  15668. int connectorIndex = 0;
  15669. //int valueASCII = 0;
  15670. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15671. gunTotalNumber=0;
  15672. SystemInitial = 0;
  15673. localversion=0;
  15674. BootNotificationInterval = 0;
  15675. authorizeRetryTimes = 0;
  15676. GunStatusInterval = 10;
  15677. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15678. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15679. //Hear Beat
  15680. HeartBeatWithNOResponse = 0;
  15681. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15682. FirstHeartBeat = 0;
  15683. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15684. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15685. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15686. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15687. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15688. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15689. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15690. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15691. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15692. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15693. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15694. memset(gunType, 0, ARRAY_SIZE(gunType));
  15695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15696. {
  15697. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15698. {
  15699. // DO series
  15700. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15701. {
  15702. SystemInitial = SystemInitial + 1;
  15703. gunTotalNumber = gunTotalNumber + 1;
  15704. gunType[connectorIndex] = GUN_TYPE_DO;
  15705. connectorIndex = connectorIndex + 1;
  15706. }
  15707. }
  15708. else
  15709. {
  15710. // DM, DW, DS series
  15711. //check connector / socket type (index: 8, 9, 10)
  15712. for(int index=7; index <10 ; index++)
  15713. {
  15714. if(index != 8)
  15715. {
  15716. // DC Connector
  15717. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15718. {
  15719. SystemInitial = SystemInitial + 1;
  15720. gunTotalNumber = gunTotalNumber + 1;
  15721. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15722. connectorIndex = connectorIndex + 1;
  15723. }
  15724. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15725. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15726. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15727. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15728. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15729. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15730. {
  15731. SystemInitial = SystemInitial + 1;
  15732. gunTotalNumber = gunTotalNumber + 1;
  15733. gunType[connectorIndex] = GUN_TYPE_CCS;
  15734. connectorIndex = connectorIndex + 1;
  15735. }
  15736. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15737. {
  15738. SystemInitial = SystemInitial + 1;
  15739. gunTotalNumber = gunTotalNumber + 1;
  15740. gunType[connectorIndex] = GUN_TYPE_GBT;
  15741. connectorIndex = connectorIndex + 1;
  15742. }
  15743. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15744. {
  15745. SystemInitial = SystemInitial + 1;
  15746. gunTotalNumber = gunTotalNumber + 1;
  15747. gunType[connectorIndex] = GUN_TYPE_DO;
  15748. connectorIndex = connectorIndex + 1;
  15749. }
  15750. }
  15751. else
  15752. {
  15753. // AC Connector
  15754. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15755. {
  15756. SystemInitial = SystemInitial + 1;
  15757. gunTotalNumber = gunTotalNumber + 1;
  15758. gunType[connectorIndex] = GUN_TYPE_AC;
  15759. connectorIndex = connectorIndex + 1;
  15760. }
  15761. }
  15762. }
  15763. }
  15764. //DEBUG_INFO("DC ...\n");
  15765. }
  15766. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15767. {
  15768. //check connector / socket type (index: 8, 9, 10)
  15769. for(int index=7; index <10 ; index++)
  15770. {
  15771. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15772. {
  15773. SystemInitial = SystemInitial + 1;
  15774. gunTotalNumber = gunTotalNumber + 1;
  15775. gunType[connectorIndex] = GUN_TYPE_AC;
  15776. connectorIndex = connectorIndex + 1;
  15777. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15778. }
  15779. }
  15780. }
  15781. //Status && ConnectorPlugIn Setting
  15782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15783. {
  15784. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15785. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15786. }
  15787. for (int index = 0; index < CCS_QUANTITY; index++)
  15788. {
  15789. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15790. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15791. }
  15792. for (int index = 0; index < GB_QUANTITY; index++)
  15793. {
  15794. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15795. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15796. }
  15797. for (int index = 0; index < AC_QUANTITY; index++)
  15798. {
  15799. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15800. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15801. }
  15802. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15803. {
  15804. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15805. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15806. }
  15807. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15808. {
  15809. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15810. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15811. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15812. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15813. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15814. }
  15815. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15816. clientTime.Heartbeat=time((time_t*)NULL);
  15817. sleep(1);
  15818. }
  15819. void LWS_Send(char *str)
  15820. {
  15821. //=====================================================
  15822. // Check InternetConn 0: disconnected, 1: connected
  15823. //====================================================
  15824. if(GetOcppConnStatus() == 0)
  15825. {
  15826. DEBUG_INFO("offline now !!!\n");
  15827. return;
  15828. }
  15829. // Only disable isWebsocketSendable operation initiated by charger
  15830. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15831. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15832. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15833. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15834. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15835. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15836. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15837. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15838. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15839. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15840. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15841. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15842. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15843. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15844. {
  15845. isWebsocketSendable = 0;
  15846. }
  15847. pthread_mutex_lock(&lock_send);
  15848. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15849. sprintf((char *)SendBuffer, "%s", str);
  15850. SendBufLen = strlen(str);
  15851. pthread_mutex_unlock(&lock_send);
  15852. lws_callback_on_writable(wsi_client);
  15853. //lws_service(context, 0);
  15854. //sleep(1);
  15855. }
  15856. void LWS_SendNow(char *str)
  15857. {
  15858. //=====================================================
  15859. // Check InternetConn 0: disconnected, 1: connected
  15860. //====================================================
  15861. if(GetOcppConnStatus() == 0)
  15862. {
  15863. DEBUG_INFO("offline now !!!\n");
  15864. return;
  15865. }
  15866. // Only disable isWebsocketSendable operation initiated by charger
  15867. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15868. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15869. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15870. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15871. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15872. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15873. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15874. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15875. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15876. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15877. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15878. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15879. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15880. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15881. {
  15882. isWebsocketSendable = 0;
  15883. }
  15884. pthread_mutex_lock(&lock_send);
  15885. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15886. sprintf((char *)SendBuffer, "%s", str);
  15887. SendBufLen = strlen(str);
  15888. pthread_mutex_unlock(&lock_send);
  15889. lws_callback_on_writable(wsi_client);
  15890. lws_service(context, 0);
  15891. //sleep(1);
  15892. }